FilePathCandidates::best()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Phpactor\ClassFileConverter\Domain;
4
5
final class FilePathCandidates implements \IteratorAggregate
6
{
7
    private $filePaths = [];
8
9
    private function __construct(array $filePaths = [])
10
    {
11
        foreach ($filePaths as $filePath) {
12
            $this->add($filePath);
13
        }
14
    }
15
16
    public static function create()
17
    {
18
        return new self([]);
19
    }
20
21
    public static function fromFilePaths(array $filePaths)
22
    {
23
        return new self($filePaths);
24
    }
25
26
    public function toArray(): array
27
    {
28
        return $this->filePaths;
29
    }
30
31
    public function add(FilePath $filePath)
32
    {
33
        $this->filePaths[] = $filePath;
34
    }
35
36
    public function best(): FilePath
37
    {
38
        if (empty($this->filePaths)) {
39
            throw new \RuntimeException(
40
                'There are no file path candidates'
41
            );
42
        }
43
44
        return reset($this->filePaths);
45
    }
46
47
    public function noneFound(): bool
48
    {
49
        return empty($this->filePaths);
50
    }
51
52
    public function getIterator()
53
    {
54
        return new \ArrayIterator($this->filePaths);
55
    }
56
}
57