Completed
Push — master ( 5db41f...c1280c )
by Daniel
01:31
created

SimpleClassToFile   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A classToFileCandidates() 0 17 3
1
<?php
2
3
namespace Phpactor\ClassFileConverter\Adapter\Simple;
4
5
use Phpactor\ClassFileConverter\Domain\ClassToFile;
6
use Phpactor\ClassFileConverter\Domain\FilePathCandidates;
7
use Phpactor\ClassFileConverter\Domain\ClassName;
8
use Phpactor\ClassFileConverter\Domain\FilePath;
9
10
class SimpleClassToFile implements ClassToFile
11
{
12
    /**
13
     * @var string
14
     */
15
    private $cwd;
16
17
    /**
18
     * @var ClassScanner
19
     */
20
    private $classScanner;
21
22
    public function __construct(string $cwd)
23
    {
24
        $this->cwd = $cwd;
25
        $this->classScanner = new ClassScanner();
26
    }
27
28
    public function classToFileCandidates(ClassName $className): FilePathCandidates
29
    {
30
        $candidates = [];
31
        foreach (glob(sprintf(
32
            '%s/**/%s.php',
33
            $this->cwd,
34
            $className->name()
35
        )) as $phpFile) {
36
            if (ClassName::fromString(
37
                $this->classScanner->getClassNameFromFile($phpFile)
38
            ) == $className) {
39
                $candidates[] = FilePath::fromString($phpFile);
40
            }
41
        }
42
43
        return FilePathCandidates::fromFilePaths($candidates);
44
    }
45
}
46