Completed
Push — develop ( e55011...fb44ee )
by
unknown
13s
created

ScanStrategy   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 48
ccs 14
cts 16
cp 0.875
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setScanDir() 0 8 2
A supports() 0 4 1
A getFinder() 0 10 1
1
<?php
2
/**
3
 * load json from a dir if json files are in a subdir called resources/definition
4
 */
5
6
namespace Graviton\GeneratorBundle\Definition\Loader\Strategy;
7
8
use Symfony\Component\Finder\Finder;
9
10
/**
11
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
12
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
13
 * @link     http://swisscom.ch
14
 */
15
class ScanStrategy extends DirStrategy
16
{
17
    /**
18
     * @var string
19
     */
20
    protected $scanDir;
21
22
    /**
23
     * @param string $scanDir dir to scan
24
     *
25
     * @return void
26
     */
27 4
    public function setScanDir($scanDir)
28
    {
29
        // if we are vendorized we will search all vendor paths
30 4
        if (strpos($scanDir, 'vendor/graviton/graviton')) {
31
            $scanDir .= '/../../';
32
        }
33 4
        $this->scanDir = $scanDir;
34 4
    }
35
36
    /**
37
     * may the strategy handle this input
38
     *
39
     * @param string|null $input input from command
40
     *
41
     * @return boolean
42
     */
43 2
    public function supports($input)
44
    {
45 2
        return is_null($input);
46
    }
47
48
    /**
49
     * @param mixed $input Input from command
50
     * @return Finder
51
     */
52 2
    protected function getFinder($input)
53
    {
54 2
        return (new Finder())
55 2
            ->files()
56 2
            ->in($this->scanDir)
57 2
            ->name('*.json')
58 2
            ->notName('_*')
59 2
            ->path('/(^|\/)resources\/definition($|\/)/i')
60 2
            ->notPath('/(^|\/)Tests($|\/)/i');
61
    }
62
}
63