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.

PhpCsFixer   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 1
dl 0
loc 95
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A check() 0 17 5
A file() 0 5 1
A execute() 0 14 1
A phpCsConfigFile() 0 4 1
A phpspecCsConfigFile() 0 4 1
A configFile() 0 36 2
A location() 0 4 1
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 (false !== mb_strpos($file, 'Spec')) {
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
        // Process fails when is launched from another Process
52
        $commandLine = [
53
            'php',
54
            'vendor/friendsofphp/php-cs-fixer/php-cs-fixer',
55
            'fix',
56
            $file,
57
            '--config=' . self::location($parameters) . '/' . $checkFile,
58
            '2> /dev/null',
59
        ];
60
        exec(implode(' ', $commandLine));
61
    }
62
63
    private static function phpCsConfigFile(array $parameters)
64
    {
65
        self::configFile('.php_cs', $parameters);
66
    }
67
68
    private static function phpspecCsConfigFile(array $parameters)
69
    {
70
        self::configFile('.phpspec_cs', $parameters);
71
    }
72
73
    private static function configFile($fileName, array $parameters)
74
    {
75
        $file = file_get_contents(__DIR__ . '/../' . $fileName . '.dist');
76
77
        $file = str_replace(
78
            '$$CHANGE-FOR-YOUR-AWESOME-NAME CHANGE-FOR-TYPE$$',
79
            $parameters['name'],
80
            $file
81
        );
82
        $file = str_replace(
83
            '$$CHANGE-FOR-YEAR$$',
84
            $parameters['year'],
85
            $file
86
        );
87
        $file = str_replace(
88
            '$$CHANGE-FOR-TYPE$$',
89
            $parameters['type'],
90
            $file
91
        );
92
        $file = str_replace(
93
            '$$CHANGE-FOR-PHPCSFIXER-PATH$$',
94
            $parameters['root_directory'] . '/' . $parameters['phpcsfixer_path'],
95
            $file
96
        );
97
        $file = str_replace(
98
            '$$CHANGE-FOR-PHPCSFIXER-TEST-PATH$$',
99
            $parameters['root_directory'] . '/' . $parameters['phpcsfixer_test_path'],
100
            $file
101
        );
102
103
        try {
104
            file_put_contents(self::location($parameters) . '/' . $fileName, $file);
105
        } catch (\Exception $exception) {
106
            echo sprintf("Something wrong happens during the creating process: \n%s\n", $exception->getMessage());
107
        }
108
    }
109
110
    private static function location(array $parameters)
111
    {
112
        return $parameters['root_directory'] . '/' . $parameters['phpcsfixer_file_location'];
113
    }
114
}
115