FilePathCandidates   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 0
dl 0
loc 52
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A create() 0 4 1
A fromFilePaths() 0 4 1
A toArray() 0 4 1
A add() 0 4 1
A best() 0 10 2
A noneFound() 0 4 1
A getIterator() 0 4 1
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