GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

GitlabUrlGenerator   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 64
Duplicated Lines 18.75 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 1
cbo 2
dl 12
loc 64
ccs 26
cts 26
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getDomain() 0 4 1
B generateCompareUrl() 0 23 4
A generateReleaseUrl() 12 12 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/*
4
 * This file is part of the composer-changelogs project.
5
 *
6
 * (c) Loïck Piera <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Pyrech\ComposerChangelogs\UrlGenerator;
13
14
use Pyrech\ComposerChangelogs\Version;
15
16
class GitlabUrlGenerator extends AbstractUrlGenerator
0 ignored issues
show
Deprecated Code introduced by
The class Pyrech\ComposerChangelog...or\AbstractUrlGenerator has been deprecated with message: since v1.4, will be removed in v2.0. Use GitBasedUrlGenerator class instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
17
{
18
    /** @var string */
19
    private $host;
20
21
    /**
22
     * @param string $host
23
     */
24 20
    public function __construct($host)
25
    {
26 20
        $this->host = $host;
27 20
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32 16
    protected function getDomain()
33
    {
34 16
        return $this->host;
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 10
    public function generateCompareUrl($sourceUrlFrom, Version $versionFrom, $sourceUrlTo, Version $versionTo)
41
    {
42
        // Check if both urls come from the supported domain
43
        // It avoids problems when one url is from another domain or is local
44 10
        if (!$this->supports($sourceUrlFrom) || !$this->supports($sourceUrlTo)) {
45 2
            return false;
46
        }
47
48 8
        $sourceUrlFrom = $this->generateBaseUrl($sourceUrlFrom);
49 8
        $sourceUrlTo = $this->generateBaseUrl($sourceUrlTo);
50
51 8
        if ($sourceUrlFrom !== $sourceUrlTo) {
52
            // Comparison across forks is not supported
53 2
            return false;
54
        }
55
56 6
        return sprintf(
57 6
            '%s/compare/%s...%s',
58 6
            $sourceUrlTo,
59 6
            $this->getCompareVersion($versionFrom),
60 6
            $this->getCompareVersion($versionTo)
61 6
        );
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67 6 View Code Duplication
    public function generateReleaseUrl($sourceUrl, Version $version)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
68
    {
69 6
        if ($version->isDev()) {
70 2
            return false;
71
        }
72
73 4
        return sprintf(
74 4
            '%s/tags/%s',
75 4
            $this->generateBaseUrl($sourceUrl),
76 4
            $version->getPretty()
77 4
        );
78
    }
79
}
80