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 ( c6d004...e8d1b2 )
by Beñat
02:14
created

PhpCsFixer::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 3
1
<?php
2
3
/*
4
 * This file is part of the CS library.
5
 *
6
 * Copyright (c) 2015-present LIN3S <[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
declare(strict_types=1);
13
14
namespace LIN3S\CS\Checker;
15
16
/**
17
 * @author Beñat Espiña <[email protected]>
18
 * @author Jon Torrado <[email protected]>
19
 */
20
final class PhpCsFixer implements Checker
21
{
22
    use FileFinder;
23
24
    public static function check(array $files = [], array $parameters = null)
25
    {
26
        foreach ($files as $file) {
27
            if (false === self::exist($file, $parameters['phpcsfixer_path'], 'php')
28
                && false === self::exist($file, $parameters['phpcsfixer_test_path'], 'php')
29
            ) {
30
                continue;
31
            }
32
33
            if (mb_strpos($file, 'Spec') !== false) {
34
                self::execute($file, $parameters, '.phpspec_cs');
35
                continue;
36
            }
37
38
            self::execute($file, $parameters);
39
        }
40
    }
41
42
    public static function file(array $parameters)
43
    {
44
        self::phpCsConfigFile($parameters);
45
        self::phpspecCsConfigFile($parameters);
46
    }
47
48
    private static function execute($file, array $parameters, $checkFile = '.php_cs')
49
    {
50
        // Exec PHP function is used because php-cs-fixer uses Symfony Process component inside
51
        // ProcessBuilder fails when is launched from another ProcessBuilder
52
        $commandLine = [
53
            'php',
54
            'vendor/friendsofphp/php-cs-fixer/php-cs-fixer',
55
            'fix',
56
            $file,
57
            '--config=' . self::location($parameters) . '/' . $checkFile,
58
        ];
59
        exec(implode(' ', $commandLine));
60
    }
61
62
    private static function phpCsConfigFile(array $parameters)
63
    {
64
        self::configFile('.php_cs', $parameters);
65
    }
66
67
    private static function phpspecCsConfigFile(array $parameters)
68
    {
69
        self::configFile('.phpspec_cs', $parameters);
70
    }
71
72
    private static function configFile($fileName, array $parameters)
73
    {
74
        $file = file_get_contents(__DIR__ . '/../' . $fileName . '.dist');
75
76
        $file = str_replace(
77
            '$$CHANGE-FOR-YOUR-AWESOME-NAME CHANGE-FOR-TYPE$$',
78
            $parameters['name'],
79
            $file
80
        );
81
        $file = str_replace(
82
            '$$CHANGE-FOR-YEAR$$',
83
            $parameters['year'],
84
            $file
85
        );
86
        $file = str_replace(
87
            '$$CHANGE-FOR-TYPE$$',
88
            $parameters['type'],
89
            $file
90
        );
91
        $file = str_replace(
92
            '$$CHANGE-FOR-PHPCSFIXER-PATH$$',
93
            '/' . $parameters['phpcsfixer_path'],
94
            $file
95
        );
96
        $file = str_replace(
97
            '$$CHANGE-FOR-PHPCSFIXER-TEST-PATH$$',
98
            '/' . $parameters['phpcsfixer_test_path'],
99
            $file
100
        );
101
102
        try {
103
            file_put_contents(self::location($parameters) . '/' . $fileName, $file);
104
        } catch (\Exception $exception) {
105
            echo sprintf("Something wrong happens during the creating process: \n%s\n", $exception->getMessage());
106
        }
107
    }
108
109
    private static function location(array $parameters)
110
    {
111
        return $parameters['root_directory'] . '/' . $parameters['phpcsfixer_file_location'];
112
    }
113
}
114