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

JBZoo / Composer-Diff / 5920911726

16 Aug 2023 06:22PM UTC coverage: 94.294%. Remained the same
5920911726

push

github

web-flow
Upgrade `jbzoo/cli:^7.1.1` (#26)

1 of 1 new or added line in 1 file covered. (100.0%)

314 of 333 relevant lines covered (94.29%)

49.24 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);
108✔
32

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

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

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

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

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

60
        return $version;
108✔
61
    }
62

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

68
    public function getPackageUrl(): ?string
69
    {
70
        $url = $this->getSourceUrl();
92✔
71
        if ($url !== '') {
92✔
72
            return Url::getPackageUrl($url);
92✔
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