Completed
Branch master (aa8164)
by Tomáš
04:04
created

SourceOptionResolver::setSourceAllowedValues()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 1
nop 1
crap 3
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\PHP7_CodeSniffer\Configuration\OptionResolver;
9
10
use Symfony\Component\OptionsResolver\OptionsResolver;
11
use Symplify\PHP7_CodeSniffer\Contract\Configuration\OptionResolver\OptionResolverInterface;
12
use Symplify\PHP7_CodeSniffer\Exception\Configuration\SourceNotFoundException;
13
14
final class SourceOptionResolver implements OptionResolverInterface
15
{
16
    /**
17
     * @var string
18
     */
19
    const NAME = 'source';
20
21 2
    public function getName() : string
22
    {
23 2
        return self::NAME;
24
    }
25
26 1 View Code Duplication
    public function resolve(array $value) : array
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...
27
    {
28 1
        $optionsResolver = new OptionsResolver();
29 1
        $optionsResolver->setDefined(self::NAME);
30 1
        $this->setSourceAllowedValues($optionsResolver);
31
32 1
        $values = $optionsResolver->resolve([
33 1
            self::NAME => $value
34
        ]);
35
36 1
        return $values[self::NAME];
37
    }
38
39
    private function setSourceAllowedValues(OptionsResolver $optionsResolver)
40
    {
41 1
        $optionsResolver->setAllowedValues(self::NAME, function (array $source) {
42 1
            foreach ($source as $singleSource) {
43 1
                if (!file_exists($singleSource)) {
44
                    throw new SourceNotFoundException(sprintf(
45 1
                        'Source "%s" does not exist.',
46
                        $singleSource
47
                    ));
48
                }
49
            }
50
51 1
            return true;
52 1
        });
53 1
    }
54
}
55