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

SimpleFileToClass::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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