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.

Application::doRun()   C
last analyzed

Complexity

Conditions 14
Paths 92

Size

Total Lines 65

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 65
rs 6.2666
c 0
b 0
f 0
cc 14
nc 92
nop 2

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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;
15
16
use LIN3S\CS\Checker\Composer;
17
use LIN3S\CS\Checker\EsLint;
18
use LIN3S\CS\Checker\PhpCsFixer;
19
use LIN3S\CS\Checker\Phpmd;
20
use LIN3S\CS\Checker\Stylelint;
21
use LIN3S\CS\Checker\TwigCs;
22
use LIN3S\CS\Exception\CheckFailException;
23
use LIN3S\CS\Git\Git;
24
use Symfony\Component\Console\Application as BaseApplication;
25
use Symfony\Component\Console\Input\InputInterface;
26
use Symfony\Component\Console\Output\OutputInterface;
27
use Symfony\Component\Yaml\Yaml;
28
29
/**
30
 * @author Beñat Espiña <[email protected]>
31
 */
32
final class Application extends BaseApplication
33
{
34
    private const APP_NAME = 'LIN3S CS';
35
    private const APP_VERSION = '0.7.x-dev';
36
37
    private $name;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
38
    private $parameters;
39
40
    public function __construct()
41
    {
42
        parent::__construct(self::APP_NAME, self::APP_VERSION);
43
44
        $rootDirectory = realpath(__DIR__ . '/../../../../../../');
45
        $this->parameters = Yaml::parse(file_get_contents($rootDirectory . '/.lin3s_cs.yml'))['parameters'];
46
        $this->parameters['root_directory'] = $rootDirectory;
47
    }
48
49
    public function doRun(InputInterface $input, OutputInterface $output)
50
    {
51
        $output->writeln(sprintf('<fg=white;options=bold;bg=red>%s</fg=white;options=bold;bg=red>', $this->name));
52
        $output->writeln('<info>Fetching files...</info>');
53
        $files = Git::committedFiles();
54
55
        $output->writeln('<info>Check composer</info>');
56
        Composer::check($files);
0 ignored issues
show
Bug introduced by
It seems like $files defined by \LIN3S\CS\Git\Git::committedFiles() on line 53 can also be of type null; however, LIN3S\CS\Checker\Composer::check() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
57
58
        if (in_array('phpcsfixer', $this->parameters['enabled'], true)) {
59
            $output->writeln('<info>Fixing PHP code style with PHP-CS-Fixer</info>');
60
            PhpCsFixer::check($files, $this->parameters);
0 ignored issues
show
Bug introduced by
It seems like $files defined by \LIN3S\CS\Git\Git::committedFiles() on line 53 can also be of type null; however, LIN3S\CS\Checker\PhpCsFixer::check() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
61
        }
62
63
        if (in_array('twigcs', $this->parameters['enabled'], true)) {
64
            $output->writeln('<info>Linting the Twig files with TwigCS</info>');
65
            $twigCsResult = TwigCs::check($files, $this->parameters);
0 ignored issues
show
Bug introduced by
It seems like $files defined by \LIN3S\CS\Git\Git::committedFiles() on line 53 can also be of type null; however, LIN3S\CS\Checker\TwigCs::check() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
66
            if (count($twigCsResult) > 0) {
67
                foreach ($twigCsResult as $error) {
68
                    $output->writeln($error->output());
69
                }
70
                throw new CheckFailException('TwigCS');
71
            }
72
        }
73
74
        if (in_array('phpmd', $this->parameters['enabled'], true)) {
75
            $output->writeln('<info>Checking code mess with PHPMD</info>');
76
            $phpmdResult = Phpmd::check($files, $this->parameters);
0 ignored issues
show
Bug introduced by
It seems like $files defined by \LIN3S\CS\Git\Git::committedFiles() on line 53 can also be of type null; however, LIN3S\CS\Checker\Phpmd::check() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
77
            if (count($phpmdResult) > 0) {
78
                foreach ($phpmdResult as $error) {
79
                    $output->writeln($error->output());
80
                }
81
                throw new CheckFailException('PHPMD');
82
            }
83
        }
84
85
        if (in_array('stylelint', $this->parameters['enabled'], true)) {
86
            $output->writeln('<info>Checking scss files with Stylelint</info>');
87
            $stylelintResult = Stylelint::check($files, $this->parameters);
0 ignored issues
show
Bug introduced by
It seems like $files defined by \LIN3S\CS\Git\Git::committedFiles() on line 53 can also be of type null; however, LIN3S\CS\Checker\Stylelint::check() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
88
            if (count($stylelintResult) > 0) {
89
                foreach ($stylelintResult as $error) {
90
                    $output->writeln($error->output());
91
                }
92
                throw new CheckFailException('Stylelint', 'Please, execute "npm update -g stylelint');
93
            }
94
        }
95
96
        if (in_array('eslint', $this->parameters['enabled'], true)) {
97
            $output->writeln('<info>Checking js files with ESLint</info>');
98
            $esLintResult = EsLint::check($files, $this->parameters);
0 ignored issues
show
Bug introduced by
It seems like $files defined by \LIN3S\CS\Git\Git::committedFiles() on line 53 can also be of type null; however, LIN3S\CS\Checker\EsLint::check() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
99
            if (count($esLintResult) > 0) {
100
                foreach ($esLintResult as $error) {
101
                    $output->writeln($error->output());
102
                }
103
                throw new CheckFailException(
104
                    'ESLint',
105
                    'Please, execute "npm update -g eslint eslint-plugin-class-property ' .
106
                    'eslint-plugin-react eslint-plugin-babel babel-eslint"'
107
                );
108
            }
109
        }
110
111
        Git::addFiles($files, $this->parameters['root_directory']);
0 ignored issues
show
Bug introduced by
It seems like $files defined by \LIN3S\CS\Git\Git::committedFiles() on line 53 can also be of type null; however, LIN3S\CS\Git\Git::addFiles() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
112
        $output->writeln('<info>Nice commit man!</info>');
113
    }
114
115
    public function parameters()
116
    {
117
        return $this->parameters;
118
    }
119
}
120