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.

Release::getCodeContent()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace AlibabaCloud\Client;
4
5
use Composer\Script\Event;
6
7
/**
8
 * Class Release
9
 *
10
 * @codeCoverageIgnore
11
 * @package AlibabaCloud\Client
12
 */
13
class Release
14
{
15
    /**
16
     * @param Event $event
17
     */
18
    public static function release(Event $event)
19
    {
20
        $arguments = $event->getArguments();
21
        if (count($arguments) <= 1) {
22
            echo 'Missing ChangeLog';
23
24
            return;
25
        }
26
        self::updateChangelogFile($arguments[0], $arguments[1]);
27
        self::changeVersionInCode($arguments[0]);
28
    }
29
30
    /**
31
     * @param $version
32
     * @param $changeLog
33
     */
34
    private static function updateChangelogFile($version, $changeLog)
35
    {
36
        $content = preg_replace(
37
            '/# CHANGELOG/',
38
            '# CHANGELOG'
39
            . "\n"
40
            . "\n"
41
            . "## $version - " . date('Y-m-d')
42
            . self::log($changeLog),
43
            self::getChangeLogContent()
44
        );
45
46
        file_put_contents(self::getChangeLogFile(), $content);
47
    }
48
49
    /**
50
     * @param $changeLog
51
     *
52
     * @return string
53
     */
54
    private static function log($changeLog)
55
    {
56
        $logs   = explode('|', $changeLog);
57
        $string = "\n";
58
        foreach ($logs as $log) {
59
            if ($log) {
60
                $string .= "- $log." . "\n";
61
            }
62
        }
63
64
        return $string;
65
    }
66
67
    /**
68
     * @return string
69
     */
70
    private static function getChangeLogContent()
71
    {
72
        return file_get_contents(self::getChangeLogFile());
73
    }
74
75
    /**
76
     * @return string
77
     */
78
    private static function getChangeLogFile()
79
    {
80
        return __DIR__ . '/../CHANGELOG.md';
81
    }
82
83
    /**
84
     * @param $version
85
     */
86
    private static function changeVersionInCode($version)
87
    {
88
        $content = preg_replace(
89
            "/const VERSION = \'(.*)\';/",
90
            "const VERSION = '" . $version . "';",
91
            self::getCodeContent()
92
        );
93
94
        file_put_contents(self::getCodeFile(), $content);
95
    }
96
97
    /**
98
     * @return string
99
     */
100
    private static function getCodeContent()
101
    {
102
        return file_get_contents(self::getCodeFile());
103
    }
104
105
    /**
106
     * @return string
107
     */
108
    private static function getCodeFile()
109
    {
110
        return __DIR__ . '/AlibabaCloud.php';
111
    }
112
}
113