Completed
Push — master ( bdcf7d...eb1b80 )
by Tomáš
05:51
created

SourceFinder::processFile()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 2
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\PHP7_CodeSniffer\File\Finder;
9
10
use SplFileInfo;
11
use Symfony\Component\Finder\Finder;
12
13
final class SourceFinder
14
{
15
    /**
16
     * @param string[]
17
     * @return SplFileInfo[]
18
     */
19 5
    public function find(array $source) : array
20
    {
21 5
        $files = [];
22
23 5
        foreach ($source as $singleSource) {
24 5
            if (is_file($singleSource)) {
25 2
                $files = $this->processFile($files, $singleSource);
26
            } else {
27 5
                $files = $this->processDirectory($files, $singleSource);
28
            }
29
        }
30
31 5
        return $files;
32
    }
33
34 2
    private function processFile(array $files, string $file) : array
35
    {
36 2
        $fileInfo = new SplFileInfo($file);
37 2
        if ($fileInfo->getExtension() !== 'php') {
38 1
            return $files;
39
        }
40
41 1
        $files[$file] = $fileInfo;
42
43 1
        return $files;
44
    }
45
46 3
    private function processDirectory(array $files, string $directory) : array
47
    {
48 3
        $finder = (new Finder())->files()
49 3
            ->name('*.php')
50 3
            ->in($directory);
51
52 3
        return array_merge(
53
            $files,
54 3
            iterator_to_array($finder->getIterator())
55
        );
56
    }
57
}
58