• 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

95.74
/src/Url.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
final class Url
20
{
21
    public const BITBUCKET = 'bitbucket';
22
    public const GITHUB    = 'github';
23
    public const GITLAB    = 'gitlab';
24
    public const UNKNOWN   = 'unknown';
25

26
    public static function getCompareUrl(?string $sourceUrl, ?string $fromVersion, ?string $toVersion): ?string
27
    {
28
        if (
29
            $sourceUrl === null
150✔
30
            || $sourceUrl === ''
150✔
31
            || $fromVersion === null
150✔
32
            || $fromVersion === ''
150✔
33
            || $toVersion === null
150✔
34
            || $toVersion === ''
150✔
35
        ) {
36
            return null;
×
37
        }
38

39
        $service = self::detectService($sourceUrl);
150✔
40
        $url     = self::getPackageUrl($sourceUrl);
150✔
41

42
        $fromVersion = \urlencode($fromVersion);
150✔
43
        $toVersion   = \urlencode($toVersion);
150✔
44

45
        if (\in_array($service, [self::GITHUB, self::GITLAB], true)) {
150✔
46
            return "{$url}/compare/{$fromVersion}...{$toVersion}";
150✔
47
        }
48

49
        if ($service === self::BITBUCKET) {
12✔
50
            return "{$url}/branches/compare/{$fromVersion}%0D{$toVersion}";
12✔
51
        }
52

53
        return null;
12✔
54
    }
55

56
    public static function getPackageUrl(string $sourceUrl): ?string
57
    {
58
        $service = self::detectService($sourceUrl);
186✔
59

60
        if ($service === self::GITHUB) {
186✔
61
            if (!\str_contains($sourceUrl, 'http')) {
36✔
62
                $sourceUrl = (string)\preg_replace('/^git@(github\.[^:]+):/', 'https://$1/', $sourceUrl);
24✔
63
            }
64

65
            return (string)\preg_replace('/\.git$/', '', $sourceUrl);
36✔
66
        }
67

68
        if ($service === self::GITLAB) {
174✔
69
            if (!\str_contains($sourceUrl, 'http')) {
174✔
70
                $sourceUrl = (string)\preg_replace('/^git@(gitlab\.[^:]+):/', 'https://$1/', $sourceUrl);
174✔
71
            }
72

73
            return (string)\preg_replace('/\.git$/', '', $sourceUrl);
174✔
74
        }
75

76
        if ($service === self::BITBUCKET) {
24✔
77
            if (!\str_contains($sourceUrl, 'http')) {
24✔
78
                $sourceUrl = (string)\preg_replace('/^git@(bitbucket\.[^:]+):/', 'https://$1/', $sourceUrl);
24✔
79
            }
80

81
            return (string)\preg_replace('/\.git$/', '', $sourceUrl);
24✔
82
        }
83

84
        return null;
24✔
85
    }
86

87
    public static function isUrl(string $string): bool
88
    {
89
        return (bool)\filter_var($string, \FILTER_VALIDATE_URL, \FILTER_FLAG_PATH_REQUIRED);
162✔
90
    }
91

92
    private static function detectService(string $url): string
93
    {
94
        if (\preg_match('/^git@github\..+:.+\.git$/', $url) > 0) {
186✔
95
            return self::GITHUB;
24✔
96
        }
97

98
        if (\preg_match('/^git@gitlab\..+:.+\.git$/', $url) > 0) {
186✔
99
            return self::GITLAB;
174✔
100
        }
101

102
        if (\preg_match('/^git@bitbucket\..+:.+\.git$/', $url) > 0) {
36✔
103
            return self::BITBUCKET;
24✔
104
        }
105

106
        if (\stripos($url, 'http') !== 0) {
36✔
107
            return self::UNKNOWN;
×
108
        }
109

110
        $host = \strtolower((string)\parse_url($url, \PHP_URL_HOST));
36✔
111

112
        if (\str_contains($host, 'github')) {
36✔
113
            return self::GITHUB;
36✔
114
        }
115

116
        if (\str_contains($host, 'bitbucket')) {
24✔
117
            return self::BITBUCKET;
24✔
118
        }
119

120
        if (\str_contains($host, 'gitlab')) {
24✔
121
            return self::GITLAB;
24✔
122
        }
123

124
        return self::UNKNOWN;
24✔
125
    }
126
}
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