Completed
Pull Request — master (#130)
by Greg
04:26
created

CommandDocBlockParserFactory::hasReflectionDocBlock3()   A

Complexity

Conditions 2
Paths 2

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 2
eloc 2
nc 2
nop 0
1
<?php
2
namespace Consolidation\AnnotatedCommand\Parser\Internal;
3
4
use Consolidation\AnnotatedCommand\Parser\CommandInfo;
5
6
/**
7
 * Create an appropriate CommandDocBlockParser.
8
 */
9
class CommandDocBlockParserFactory
10
{
11
    public static function parse(CommandInfo $commandInfo, \ReflectionMethod $reflection)
12
    {
13
        return static::create($commandInfo, $reflection)->parse();
0 ignored issues
show
Bug introduced by
Since create() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of create() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
14
    }
15
16
    private static function create(CommandInfo $commandInfo, \ReflectionMethod $reflection)
17
    {
18
        return new BespokeDocBlockParser($commandInfo, $reflection);
19
    }
20
}
21