• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

eliashaeussler / version-bumper / 24532097497

16 Apr 2026 08:22PM UTC coverage: 88.226% (+0.1%) from 88.084%
24532097497

push

github

web-flow
Merge pull request #128 from eliashaeussler/task/deprecations

[TASK] Collect and display deprecated config options

60 of 66 new or added lines in 2 files covered. (90.91%)

1154 of 1308 relevant lines covered (88.23%)

5.04 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.21
/src/Error/DeprecationMessage.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the Composer package "eliashaeussler/version-bumper".
7
 *
8
 * Copyright (C) 2024-2026 Elias Häußler <elias@haeussler.dev>
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by
12
 * the Free Software Foundation, either version 3 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22
 */
23

24
namespace EliasHaeussler\VersionBumper\Error;
25

26
use function count;
27
use function debug_backtrace;
28
use function explode;
29
use function is_array;
30
use function is_object;
31
use function is_string;
32
use function str_contains;
33
use function str_starts_with;
34
use function substr;
35
use function trim;
36

37
/**
38
 * DeprecationMessage.
39
 *
40
 * @author Elias Häußler <elias@haeussler.dev>
41
 * @license GPL-3.0-or-later
42
 */
43
final readonly class DeprecationMessage
44
{
45
    public function __construct(
5 ✔
46
        private string $message,
47
        private ?string $since = null,
48
        private ?object $origin = null,
49
    ) {}
5 ✔
50

51
    /**
52
     * @param array{function?: string, args?: list<mixed>} $trace
53
     */
54
    public static function fromTrace(array $trace): ?self
9 ✔
55
    {
56
        if ('trigger_deprecation' !== ($trace['function'] ?? null)) {
9 ✔
57
            return null;
2 ✔
58
        }
59

60
        if (!is_array($trace['args'] ?? null) || count($trace['args']) < 3) {
7 ✔
61
            return null;
2 ✔
62
        }
63

64
        [$packageName, $since, $message] = $trace['args'];
5 ✔
65

66
        if ('eliashaeussler/version-bumper' !== $packageName || !is_string($since) || !is_string($message)) {
5 ✔
67
            return null;
3 ✔
68
        }
69

70
        return new self($message, $since);
2 ✔
71
    }
72

73
    public static function fromMessage(string $message): ?self
5 ✔
74
    {
75
        $initialPhrase = 'Since eliashaeussler/version-bumper';
5 ✔
76

77
        if (!str_starts_with($message, $initialPhrase)) {
5 ✔
78
            return null;
2 ✔
79
        }
80

81
        if (!str_contains($message, ':')) {
3 ✔
82
            return new self($message);
1 ✔
83
        }
84

85
        [$since, $message] = explode(':', substr($message, strlen($initialPhrase)), 2);
2 ✔
86

87
        return new self(trim($message), trim($since));
2 ✔
88
    }
89

90
    public static function fromTraceOrMessage(string $message): ?self
3 ✔
91
    {
92
        $trace = debug_backtrace();
3 ✔
93
        $deprecation = null;
3 ✔
94

95
        foreach ($trace as $entry) {
3 ✔
96
            if (null === $deprecation) {
3 ✔
97
                if ('trigger_deprecation' === $entry['function'] && !isset($entry['class']) && isset($entry['args'])) {
3 ✔
98
                    $deprecation = self::fromTrace($entry) ?? self::fromMessage($message);
1 ✔
99
                }
100
            } elseif (
101
                is_object($entry['object'] ?? null)
1 ✔
102
                && str_starts_with($entry['class'] ?? '', 'EliasHaeussler\\VersionBumper\\')
1 ✔
103
            ) {
104
                return $deprecation->withOrigin($entry['object']);
1 ✔
105
            }
106
        }
107

108
        return $deprecation ?? self::fromMessage($message);
2 ✔
109
    }
110

NEW
111
    public function message(): string
×
112
    {
NEW
113
        return $this->message;
×
114
    }
115

NEW
116
    public function since(): ?string
×
117
    {
NEW
118
        return $this->since;
×
119
    }
120

NEW
121
    public function origin(): ?object
×
122
    {
NEW
123
        return $this->origin;
×
124
    }
125

126
    /**
127
     * @impure
128
     */
129
    public function withOrigin(object $origin): self
1 ✔
130
    {
131
        return new self($this->message, $this->since, $origin);
1 ✔
132
    }
133
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc