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.
Test Failed
Push — master ( 916e9a...62ca6e )
by
unknown
04:55
created

Release   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 30
dl 0
loc 96
rs 10
c 0
b 0
f 0
wmc 11

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getCodeContent() 0 3 1
A getChangeLogFile() 0 3 1
A updateChangelogFile() 0 13 1
A changeVersionInCode() 0 9 1
A log() 0 11 3
A getCodeFile() 0 3 1
A release() 0 8 2
A getChangeLogContent() 0 3 1
1
<?php
2
3
namespace AlibabaCloud\Client;
4
5
use Composer\Script\Event;
6
7
/**
8
 * Class Release
9
 *
10
 * @package AlibabaCloud\Client
11
 */
12
class Release
13
{
14
    /**
15
     * @param Event $event
16
     */
17
    public static function release(Event $event)
18
    {
19
        $arguments = $event->getArguments();
20
        if (count($arguments) <= 1) {
21
            die('Missing ChangeLog');
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
22
        }
23
        self::updateChangelogFile($arguments[0], $arguments[1]);
24
        self::changeVersionInCode($arguments[0]);
25
    }
26
27
    /**
28
     * @return string
29
     */
30
    private static function getCodeFile()
31
    {
32
        return __DIR__ . '/AlibabaCloud.php';
33
    }
34
35
    /**
36
     * @return string
37
     */
38
    private static function getChangeLogFile()
39
    {
40
        return __DIR__ . '/../CHANGELOG.md';
41
    }
42
43
    /**
44
     * @return string
45
     */
46
    private static function getCodeContent()
47
    {
48
        return file_get_contents(self::getCodeFile());
49
    }
50
51
    /**
52
     * @return string
53
     */
54
    private static function getChangeLogContent()
55
    {
56
        return file_get_contents(self::getChangeLogFile());
57
    }
58
59
    /**
60
     * @param $version
61
     */
62
    private static function changeVersionInCode($version)
63
    {
64
        $content = preg_replace(
65
            "/const VERSION = \'(.*)\';/",
66
            "const VERSION = '" . $version . "';",
67
            self::getCodeContent()
68
        );
69
70
        file_put_contents(self::getCodeFile(), $content);
71
    }
72
73
    /**
74
     * @param $version
75
     * @param $changeLog
76
     */
77
    private static function updateChangelogFile($version, $changeLog)
78
    {
79
        $content = preg_replace(
80
            '/# CHANGELOG/',
81
            '# CHANGELOG'
82
            . "\n"
83
            . "\n"
84
            . "## $version - " . date('Y-m-d')
85
            . self::log($changeLog),
86
            self::getChangeLogContent()
87
        );
88
89
        file_put_contents(self::getChangeLogFile(), $content);
90
    }
91
92
    /**
93
     * @param $changeLog
94
     *
95
     * @return string
96
     */
97
    private static function log($changeLog)
98
    {
99
        $logs   = explode('|', $changeLog);
100
        $string = "\n";
101
        foreach ($logs as $log) {
102
            if ($log) {
103
                $string .= "- $log." . "\n";
104
            }
105
        }
106
107
        return $string;
108
    }
109
}
110