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

ConfigurationResolver::addOptionResolver()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
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 Symplify\MultiCodingStandard\Contract\PhpCsFixer\Configuration\OptionResolver\OptionResolverInterface;
11
use Symplify\PHP7_CodeSniffer\Exception\Configuration\MissingOptionResolverException;
12
13
final class ConfigurationResolver
14
{
15
    /**
16
     * @var OptionResolverInterface[]
17
     */
18
    private $optionResolvers;
19
20
    public function addOptionResolver(OptionResolverInterface $optionResolver)
21
    {
22
        $this->optionResolvers[$optionResolver->getName()] = $optionResolver;
23
    }
24
25
    public function resolve(string $name, array $source) : array
26
    {
27
        $this->ensureResolverExists($name);
28
        return $this->optionResolvers[$name]->resolve($source);
29
    }
30
31
    private function ensureResolverExists(string $name)
32
    {
33
        if (!isset($this->optionResolvers[$name])) {
34
            throw new MissingOptionResolverException(sprintf(
35
                'Resolver for "%s" value is not registered. '.
36
                'Add it via $configurationResolver->addOptionResolver(...).',
37
                $name
38
            ));
39
        }
40
    }
41
42
//    /**
43
//     * @var FixerFileSystem
44
//     */
45
//    private $fixerFileSystem;
46
47
//    /**
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% 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...
48
//     * @var FixerFactory
49
//     */
50
//    private $fixerFactory;
51
//
52
//    public function __construct(FixerFileSystem $fixerFileSystem, FixerFactory $fixerFactory)
53
//    {
54
//        $this->fixerFileSystem = $fixerFileSystem;
55
//        $this->fixerFactory = $fixerFactory;
56
//    }
57
//
58
//    public function create() : ConfigurationResolver
59
//    {
60
//        $allFixerFiles = $this->fixerFileSystem->findAllFixers();
61
//        $allFixerObjects = $this->fixerFactory->createFixersFromFiles($allFixerFiles);
62
//
63
//        $configurationResolver = new ConfigurationResolver();
64
//        $configurationResolver->setAllFixers($allFixerObjects);
65
//
66
//        return $configurationResolver;
67
//    }
68
}
69