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

eliashaeussler / composer-update-check / 15182034191

22 May 2025 03:06AM UTC coverage: 20.538%. First build
15182034191

Pull #130

github

web-flow
[TASK] Update all dependencies
Pull Request #130: [!!!][FEATURE] Modernize plugin

356 of 1832 new or added lines in 57 files covered. (19.43%)

382 of 1860 relevant lines covered (20.54%)

1.11 hits per line

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

45.24
/src/Entity/Package/OutdatedPackage.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the Composer package "eliashaeussler/composer-update-check".
7
 *
8
 * Copyright (C) 2020-2025 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\ComposerUpdateCheck\Entity\Package;
25

26
use EliasHaeussler\ComposerUpdateCheck\Entity;
27
use GuzzleHttp\Psr7;
28
use Psr\Http\Message;
29

30
use function array_map;
31

32
/**
33
 * OutdatedPackage.
34
 *
35
 * @author Elias Häußler <elias@haeussler.dev>
36
 * @license GPL-3.0-or-later
37
 */
38
final class OutdatedPackage implements Package
39
{
40
    private const PROVIDER_LINK_PATTERN = 'https://packagist.org/packages/%s#%s';
41

42
    private Message\UriInterface $providerLink;
43

44
    /**
45
     * @param non-empty-string                       $name
46
     * @param list<Entity\Security\SecurityAdvisory> $securityAdvisories
47
     */
48
    public function __construct(
3✔
49
        private readonly string $name,
50
        private readonly Entity\Version $outdatedVersion,
51
        private readonly Entity\Version $newVersion,
52
        private array $securityAdvisories = [],
53
    ) {
54
        $this->providerLink = $this->generateProviderLink();
3✔
55
    }
56

NEW
57
    public function getName(): string
×
58
    {
NEW
59
        return $this->name;
×
60
    }
61

NEW
62
    public function getOutdatedVersion(): Entity\Version
×
63
    {
NEW
64
        return $this->outdatedVersion;
×
65
    }
66

NEW
67
    public function getNewVersion(): Entity\Version
×
68
    {
NEW
69
        return $this->newVersion;
×
70
    }
71

72
    /**
73
     * @return list<Entity\Security\SecurityAdvisory>
74
     */
NEW
75
    public function getSecurityAdvisories(): array
×
76
    {
NEW
77
        return $this->securityAdvisories;
×
78
    }
79

80
    public function getHighestSeverityLevel(): ?Entity\Security\SeverityLevel
2✔
81
    {
82
        if (!$this->isInsecure()) {
2✔
83
            return null;
1✔
84
        }
85

86
        $severityLevels = array_map(
1✔
87
            static fn (Entity\Security\SecurityAdvisory $securityAdvisory) => $securityAdvisory->getSeverity(),
1✔
88
            $this->securityAdvisories,
1✔
89
        );
1✔
90

91
        return Entity\Security\SeverityLevel::getHighestSeverityLevel(...$severityLevels);
1✔
92
    }
93

94
    /**
95
     * @param list<Entity\Security\SecurityAdvisory> $securityAdvisories
96
     */
97
    public function setSecurityAdvisories(array $securityAdvisories): self
2✔
98
    {
99
        $this->securityAdvisories = $securityAdvisories;
2✔
100

101
        return $this;
2✔
102
    }
103

104
    /**
105
     * @phpstan-assert-if-true !null $this->getHighestSeverityLevel()
106
     */
107
    public function isInsecure(): bool
3✔
108
    {
109
        return [] !== $this->securityAdvisories;
3✔
110
    }
111

NEW
112
    public function getProviderLink(): Message\UriInterface
×
113
    {
NEW
114
        return $this->providerLink;
×
115
    }
116

NEW
117
    public function setProviderLink(Message\UriInterface $providerLink): self
×
118
    {
NEW
119
        $this->providerLink = $providerLink;
×
120

NEW
121
        return $this;
×
122
    }
123

124
    /**
125
     * @return array{
126
     *     name: non-empty-string,
127
     *     outdatedVersion: string,
128
     *     newVersion: string,
129
     *     securityAdvisories: list<Entity\Security\SecurityAdvisory>,
130
     *     providerLink: string,
131
     * }
132
     */
NEW
133
    public function jsonSerialize(): array
×
134
    {
NEW
135
        return [
×
NEW
136
            'name' => $this->name,
×
NEW
137
            'outdatedVersion' => (string) $this->outdatedVersion,
×
NEW
138
            'newVersion' => (string) $this->newVersion,
×
NEW
139
            'securityAdvisories' => $this->securityAdvisories,
×
NEW
140
            'providerLink' => (string) $this->providerLink,
×
NEW
141
        ];
×
142
    }
143

NEW
144
    public function __toString(): string
×
145
    {
NEW
146
        return $this->name;
×
147
    }
148

149
    private function generateProviderLink(): Message\UriInterface
3✔
150
    {
151
        $versionHash = explode(' ', $this->newVersion->toString(), 2)[0];
3✔
152
        $uri = sprintf(self::PROVIDER_LINK_PATTERN, $this->name, $versionHash);
3✔
153

154
        return new Psr7\Uri($uri);
3✔
155
    }
156
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc