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

EnabledFixerResolver::getEnabledFixersAsString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 6
cp 0
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 0
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\Configuration;
9
10
use Symfony\CS\FixerInterface;
11
12
final class EnabledFixerResolver
13
{
14
    /**
15
     * @var ConfigurationResolverFactory
16
     */
17
    private $configurationResolverFactory;
18
19
    /**
20
     * @var FixerInterface[]
21
     */
22
    private $enabledFixers = [];
23
24
//    public function __construct() {
0 ignored issues
show
Unused Code Comprehensibility introduced by
44% 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...
25
//        $this->configurationResolverFactory = $configurationResolverFactory;
26
//    }
27
//
28
    /**
29
     * @return FixerInterface[]
30
     */
31
    public function getEnabledFixers() : array
32
    {
33
        if ($this->enabledFixers !== []) {
34
            return $this->enabledFixers;
35
        }
36
37
        $configurationResolver = $this->configurationResolverFactory->create();
38
39
        $this->addFixersByLevel($configurationResolver);
40
        $this->addCustomFixers($configurationResolver);
41
42
        return $this->enabledFixers;
43
    }
44
45 View Code Duplication
    private function addFixersByLevel(ConfigurationResolver $configurationResolver)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
46
    {
47
        $excludedFixers = $this->getExcludedFixersAsString();
48
        foreach ($this->configuration->getActiveFixerLevels() as $level) {
0 ignored issues
show
Bug introduced by
The property configuration does not seem to exist. Did you mean configurationResolverFactory?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
49
            $currentConfigurationResolver = clone $configurationResolver;
50
            if ($excludedFixers) {
51
                $currentConfigurationResolver->setOption('fixers', $excludedFixers);
0 ignored issues
show
Bug introduced by
The method setOption() does not seem to exist on object<Symplify\MultiCod...\ConfigurationResolver>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
52
            }
53
            $currentConfigurationResolver->setOption('level', $level);
0 ignored issues
show
Bug introduced by
The method setOption() does not seem to exist on object<Symplify\MultiCod...\ConfigurationResolver>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
54
            $currentConfigurationResolver->resolve();
0 ignored issues
show
Bug introduced by
The call to resolve() misses some required arguments starting with $name.
Loading history...
55
56
            $this->enabledFixers = array_merge($this->enabledFixers, $currentConfigurationResolver->getFixers());
0 ignored issues
show
Bug introduced by
The method getFixers() does not seem to exist on object<Symplify\MultiCod...\ConfigurationResolver>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
57
        }
58
    }
59
60
    /**
61
     * @return string
62
     */
63
    private function getExcludedFixersAsString()
64
    {
65
        $excludedFixers = '';
66
        if (count($this->configuration->getExcludedFixers())) {
0 ignored issues
show
Bug introduced by
The property configuration does not seem to exist. Did you mean configurationResolverFactory?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
67
            $excludedFixers .= '-' . implode(',-', $this->configuration->getExcludedFixers());
0 ignored issues
show
Bug introduced by
The property configuration does not seem to exist. Did you mean configurationResolverFactory?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
68
            return $excludedFixers;
69
        }
70
        return $excludedFixers;
71
    }
72
73
    /**
74
     * @return array
75
     */
76 View Code Duplication
    private function addCustomFixers(ConfigurationResolver $configurationResolver)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
77
    {
78
        $fixers = $this->getEnabledFixersAsString();
79
80
        if ($fixers) {
81
            $currentConfigurationResolver = clone $configurationResolver;
82
            $currentConfigurationResolver->setOption('level', 'none');
0 ignored issues
show
Bug introduced by
The method setOption() does not seem to exist on object<Symplify\MultiCod...\ConfigurationResolver>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
83
            $currentConfigurationResolver->setOption('fixers', $fixers);
0 ignored issues
show
Bug introduced by
The method setOption() does not seem to exist on object<Symplify\MultiCod...\ConfigurationResolver>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
84
            $currentConfigurationResolver->resolve();
0 ignored issues
show
Bug introduced by
The call to resolve() misses some required arguments starting with $name.
Loading history...
85
86
            $this->enabledFixers = array_merge($this->enabledFixers, $currentConfigurationResolver->getFixers());
0 ignored issues
show
Bug introduced by
The method getFixers() does not seem to exist on object<Symplify\MultiCod...\ConfigurationResolver>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
87
        }
88
    }
89
90
    private function getEnabledFixersAsString() : string
91
    {
92
        $fixers = '';
93
        if (count($this->configuration->getActiveFixers())) {
0 ignored issues
show
Bug introduced by
The property configuration does not seem to exist. Did you mean configurationResolverFactory?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
94
            $fixers .= implode(',', $this->configuration->getActiveFixers());
0 ignored issues
show
Bug introduced by
The property configuration does not seem to exist. Did you mean configurationResolverFactory?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
95
            return $fixers;
96
        }
97
        return $fixers;
98
    }
99
}
100