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 ( c3138a...4d5951 )
by Beñat
03:40
created

PhpCsFixer::configFile()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 26
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 18
nc 2
nop 2
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
                continue;
29
            }
30
31
            // Exec PHP function is used because php-cs-fixer uses Symfony Process component inside
32
            // ProcessBuilder fails when is launched from another ProcessBuilder
33
            $commandLine = [
34
                'php',
35
                'vendor/friendsofphp/php-cs-fixer/php-cs-fixer',
36
                'fix',
37
                $file,
38
                '--config=.php_cs',
39
            ];
40
            exec(implode(' ', $commandLine));
41
        }
42
    }
43
44
    public static function file(array $parameters)
45
    {
46
        self::phpCsConfigFile($parameters);
47
        self::phpspecCsConfigFile($parameters);
48
    }
49
50
    private static function phpCsConfigFile(array $parameters)
51
    {
52
        self::configFile('.php_cs', $parameters);
53
    }
54
55
    private static function phpspecCsConfigFile(array $parameters)
56
    {
57
        self::configFile('.phpspec_cs', $parameters);
58
    }
59
60
    private static function configFile($fileName, array $parameters)
61
    {
62
        $file = file_get_contents(__DIR__ . '/../' . $fileName . '.dist');
63
64
        $file = str_replace(
65
            '$$CHANGE-FOR-YOUR-AWESOME-NAME CHANGE-FOR-TYPE$$',
66
            $parameters['name'],
67
            $file
68
        );
69
        $file = str_replace(
70
            '$$CHANGE-FOR-YEAR$$',
71
            $parameters['year'],
72
            $file
73
        );
74
        $file = str_replace(
75
            '$$CHANGE-FOR-TYPE$$',
76
            $parameters['type'],
77
            $file
78
        );
79
80
        try {
81
            file_put_contents(self::location($parameters) . '/' . $fileName, $file);
82
        } catch (\Exception $exception) {
83
            echo sprintf("Something wrong happens during the creating process: \n%s\n", $exception->getMessage());
84
        }
85
    }
86
87
    private static function location(array $parameters)
88
    {
89
        return $parameters['root_directory'] . '/' . $parameters['phpcsfixer_file_location'];
90
    }
91
}
92