Completed
Pull Request — master (#6)
by Jefersson
01:52
created

IOResourcePathResolution::getDirectory()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 2
eloc 2
nc 2
nop 1
crap 2
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license.
17
 */
18
namespace DocHeader\Helper;
19
20
use Symfony\Component\Finder\Finder;
21
22
/**
23
 * @author Jefersson Nathan  <[email protected]>
24
 * @license MIT
25
 */
26
final class IOResourcePathResolution
27
{
28
    /**
29
     * @var string
30
     */
31
    private $directoryOrFile;
32
33
    /**
34
     * @param array $directoryOrFile
35
     */
36 2
    public function __construct(array $directoryOrFile)
37
    {
38 2
        $this->directoryOrFile = $directoryOrFile;
0 ignored issues
show
Documentation Bug introduced by
It seems like $directoryOrFile of type array is incompatible with the declared type string of property $directoryOrFile.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
39 2
    }
40
41 2
    private function getDirectory($directoryOrFile)
42
    {
43 2
        return is_dir($directoryOrFile) ? $directoryOrFile : dirname($directoryOrFile);
44
    }
45
46 2
    private function getFeatureMatch($directoryOrFile)
47
    {
48 2
        return is_dir($directoryOrFile) ? '*.php' : basename($directoryOrFile);
49
    }
50
51
    /**
52
     * @throws \InvalidArgumentException
53
     *
54
     * @return Finder[]
55
     */
56 2
    public function __invoke()
57
    {
58 2
        return array_map(
59 2
            function ($directoryOrFile) {
60 2
                return Finder::create()
61 2
                    ->files()
62 2
                    ->in($this->getDirectory($directoryOrFile))
63 2
                    ->name($this->getFeatureMatch($directoryOrFile));
64 2
            },
65 2
            $this->directoryOrFile
66 2
        );
67
    }
68
}
69