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

JBZoo / Composer-Diff / 8868989088

08 Feb 2024 09:20PM UTC coverage: 94.345%. Remained the same
8868989088

push

github

web-flow
Bump composer/composer from 2.6.6 to 2.7.0 (#34)

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

317 of 336 relevant lines covered (94.35%)

74.11 hits per line

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

89.47
/src/Package.php
1
<?php
2

3
/**
4
 * JBZoo Toolbox - Composer-Diff.
5
 *
6
 * This file is part of the JBZoo Toolbox project.
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license    MIT
11
 * @copyright  Copyright (C) JBZoo.com, All rights reserved.
12
 * @see        https://github.com/JBZoo/Composer-Diff
13
 */
14

15
declare(strict_types=1);
16

17
namespace JBZoo\ComposerDiff;
18

19
use JBZoo\Data\Data;
20

21
use function JBZoo\Data\data;
22

23
final class Package
24
{
25
    public const HASH_LENGTH = 7;
26

27
    private Data $data;
28

29
    public function __construct(array $packageDate)
30
    {
31
        $this->data = data($packageDate);
162✔
32

33
        if ($this->data->count() === 0) {
162✔
34
            throw new Exception("Can't parse package data");
×
35
        }
36
    }
37

38
    public function getName(): string
39
    {
40
        return $this->data->getString('name');
162✔
41
    }
42

43
    public function getVersion(bool $prettyPrint = false): string
44
    {
45
        $version = $this->data->getString('version');
162✔
46
        if ($prettyPrint) {
162✔
47
            $version = (string)\preg_replace('#^v\.#i', '', $version);
138✔
48
            $version = (string)\preg_replace('#^v#i', '', $version);
138✔
49
        }
50

51
        $reference = $this->data->findString('source.reference');
162✔
52

53
        if (\strlen($reference) >= self::HASH_LENGTH && \str_starts_with($version, 'dev-')) {
162✔
54
            $version = \substr($reference, 0, self::HASH_LENGTH);
84✔
55
            if ($prettyPrint) {
84✔
56
                $version = "{$this->data->getString('version')}@{$version}";
72✔
57
            }
58
        }
59

60
        return $version;
162✔
61
    }
62

63
    public function getSourceUrl(): string
64
    {
65
        return $this->data->findString('source.url');
162✔
66
    }
67

68
    public function getPackageUrl(): ?string
69
    {
70
        $url = $this->getSourceUrl();
138✔
71
        if ($url !== '') {
138✔
72
            return Url::getPackageUrl($url);
138✔
73
        }
74

75
        return null;
×
76
    }
77
}
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