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

SimpleFileToClass   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 25
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A fileToClassCandidates() 0 12 2
1
<?php
2
3
namespace Phpactor\ClassFileConverter\Adapter\Simple;
4
5
use Phpactor\ClassFileConverter\Domain\FileToClass;
6
use Phpactor\ClassFileConverter\Domain\ClassNameCandidates;
7
use Phpactor\ClassFileConverter\Domain\FilePath;
8
use Phpactor\ClassFileConverter\Domain\ClassName;
9
use Phpactor\ClassFileConverter\Adapter\Simple\ClassScanner;
10
11
class SimpleFileToClass implements FileToClass
12
{
13
    /**
14
     * @var ClassScanner
15
     */
16
    private $classScanner;
17
18
    public function __construct()
19
    {
20
        $this->classScanner = new ClassScanner();
21
    }
22
23
    public function fileToClassCandidates(FilePath $filePath): ClassNameCandidates
24
    {
25
        $classNames = [];
26
27
        $className = $this->classScanner->getClassNameFromFile($filePath->__toString());
28
29
        if ($className) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $className of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
30
            $classNames[] = ClassName::fromString($className);
31
        }
32
33
        return ClassNameCandidates::fromClassNames($classNames);
34
    }
35
}
36