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

SimpleFileToClass::getClassNameFromFile()   C

Complexity

Conditions 15
Paths 4

Size

Total Lines 52
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 52
rs 5.9385
cc 15
eloc 28
nc 4
nop 1

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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