SimpleFileToClass::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
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
10
class SimpleFileToClass implements FileToClass
11
{
12
    /**
13
     * @var ClassScanner
14
     */
15
    private $classScanner;
16
17
    public function __construct()
18
    {
19
        $this->classScanner = new ClassScanner();
20
    }
21
22
    public function fileToClassCandidates(FilePath $filePath): ClassNameCandidates
23
    {
24
        $classNames = [];
25
26
        $className = $this->classScanner->getClassNameFromFile($filePath->__toString());
27
28
        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...
29
            $classNames[] = ClassName::fromString($className);
30
        }
31
32
        return ClassNameCandidates::fromClassNames($classNames);
33
    }
34
}
35