Completed
Pull Request — master (#10)
by Tomáš
07:32
created

Application::runForSource()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 12
ccs 0
cts 7
cp 0
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 6
nc 2
nop 2
crap 6
1
<?php
2
3
/*
4
 * This file is part of Symplify
5
 * Copyright (c) 2016 Tomas Votruba (http://tomasvotruba.cz).
6
 */
7
8
namespace Symplify\MultiCodingStandard\PhpCsFixer\Application;
9
10
use Symfony\CS\Config;
11
use Symfony\CS\Fixer;
12
use Symplify\MultiCodingStandard\PhpCsFixer\Application\Command\RunApplicationCommand;
13
use Symplify\MultiCodingStandard\PhpCsFixer\Factory\FixerSetFactory;
14
use Symplify\PHP7_CodeSniffer\File\Finder\SourceFinder;
15
16
final class Application
17
{
18
    /**
19
     * @var Fixer
20
     */
21
    private $fixer;
22
23
    /**
24
     * @var FixerSetFactory
25
     */
26
    private $fixerSetFactory;
27
    /**
28
     * @var SourceFinder
29
     */
30
    private $sourceFinder;
31
32
    public function __construct(Fixer $fixer, FixerSetFactory $fixerSetFactory, SourceFinder $sourceFinder)
33
    {
34
        $this->fixer = $fixer;
35
        $this->fixerSetFactory = $fixerSetFactory;
36
        $this->sourceFinder = $sourceFinder;
37
    }
38
39
    public function runCommand(RunApplicationCommand $command)
40
    {
41
        $this->registerFixersToFixer($command->getFixerLevels(), $command->getFixers(), $command->getExcludeFixers());
42
43
        $this->runForSource($command->getSource(), $command->isFixer());
44
    }
45
46
    private function registerFixersToFixer(array $fixerLevels, array $fixers, array $excludedFixers)
47
    {
48
        $fixers = $this->fixerSetFactory->createFromLevelsFixersAndExcludedFixers($fixerLevels, $fixers, $excludedFixers);
49
        $this->fixer->registerCustomFixers($fixers);
50
    }
51
52
    private function runForSource(array $source, bool $isFixer)
53
    {
54
//        $files = $this->sourceFinder->find($source);
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
55
56
        $config = new Config();
57
        $config->finder(new \ArrayIterator($source));
58
        $configs = $this->fixer->addConfig($config);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $configs is correct as $this->fixer->addConfig($config) (which targets Symfony\CS\Fixer::addConfig()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Unused Code introduced by
$configs is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
59
60
        foreach ($files as $splFileInfo) {
0 ignored issues
show
Bug introduced by
The variable $files does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
61
            $this->fixer->fixFile($splFileInfo, $this->fixer->getFixers(), !$isFixer);
0 ignored issues
show
Bug introduced by
The call to fixFile() misses some required arguments starting with $diff.
Loading history...
62
        }
63
    }
64
}
65