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.
Completed
Push — master ( be0fbc...5fc530 )
by Loick
8s
created

UpdateHandler   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 0 Features 2
Metric Value
wmc 11
c 5
b 0
f 2
lcom 0
cbo 5
dl 0
loc 96
ccs 58
cts 58
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A supports() 0 4 1
A extractSourceUrl() 0 8 2
C getOutput() 0 70 8
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\OperationHandler;
13
14
use Composer\DependencyResolver\Operation\OperationInterface;
15
use Composer\DependencyResolver\Operation\UpdateOperation;
16
use Composer\Package\Version\VersionParser;
17
use Composer\Semver\Comparator;
18
use Pyrech\ComposerChangelogs\UrlGenerator\UrlGenerator;
19
use Pyrech\ComposerChangelogs\Version;
20
21
class UpdateHandler implements OperationHandler
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26 13
    public function supports(OperationInterface $operation)
27
    {
28 13
        return $operation instanceof UpdateOperation;
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34 19
    public function extractSourceUrl(OperationInterface $operation)
35
    {
36 19
        if (!($operation instanceof UpdateOperation)) {
37 2
            throw new \LogicException('Operation should be an instance of UpdateOperation');
38
        }
39
40 17
        return $operation->getTargetPackage()->getSourceUrl();
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 21
    public function getOutput(OperationInterface $operation, UrlGenerator $urlGenerator = null)
47
    {
48 21
        if (!($operation instanceof UpdateOperation)) {
49 2
            throw new \LogicException('Operation should be an instance of UpdateOperation');
50
        }
51
52 19
        $output = [];
53
54 19
        $initialPackage = $operation->getInitialPackage();
55 19
        $targetPackage = $operation->getTargetPackage();
56
57 19
        $versionFrom = new Version(
58 19
            $initialPackage->getVersion(),
59 19
            $initialPackage->getPrettyVersion(),
60 19
            method_exists($initialPackage, 'getFullPrettyVersion') // This method was added after composer v1.0.0-alpha10
61 19
                ? $initialPackage->getFullPrettyVersion()
62 19
                : VersionParser::formatVersion($initialPackage)
63 19
        );
64 19
        $versionTo = new Version(
65 19
            $targetPackage->getVersion(),
66 19
            $targetPackage->getPrettyVersion(),
67 19
            method_exists($targetPackage, 'getFullPrettyVersion') // This method was added after composer v1.0.0-alpha10
68 19
                ? $targetPackage->getFullPrettyVersion()
69 19
                : VersionParser::formatVersion($targetPackage)
70 19
        );
71
72 19
        $action = 'updated';
73
74 19
        if (Comparator::greaterThan($versionFrom->getName(), $versionTo->getName())) {
75 2
            $action = 'downgraded';
76 2
        }
77
78 19
        $output[] = sprintf(
79 19
            ' - <fg=green>%s</fg=green> %s from <fg=yellow>%s</fg=yellow> to <fg=yellow>%s</fg=yellow>',
80 19
            $initialPackage->getName(),
81 19
            $action,
82 19
            $versionFrom->getPretty(),
83 19
            $versionTo->getPretty()
84 19
        );
85
86 19
        if ($urlGenerator) {
87 15
            $compareUrl = $urlGenerator->generateCompareUrl(
88 15
                $initialPackage->getSourceUrl(),
89 15
                $versionFrom,
90 15
                $targetPackage->getSourceUrl(),
91
                $versionTo
92 15
            );
93
94 15
            if (!empty($compareUrl)) {
95 13
                $output[] = sprintf(
96 13
                    '   See changes: %s',
97
                    $compareUrl
98 13
                );
99 13
            }
100
101 15
            $releaseUrl = $urlGenerator->generateReleaseUrl(
102 15
                $this->extractSourceUrl($operation),
103
                $versionTo
104 15
            );
105
106 15
            if (!empty($releaseUrl)) {
107 13
                $output[] = sprintf(
108 13
                    '   Release notes: %s',
109
                    $releaseUrl
110 13
                );
111 13
            }
112 15
        }
113
114 19
        return $output;
115
    }
116
}
117