Completed
Push — master ( 46a28a...d0144c )
by Greg
03:47
created

CommandDocBlockParserFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 20
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A parse() 0 4 1
A create() 0 7 2
A hasReflectionDocBlock3() 0 4 2
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
        if (static::hasReflectionDocBlock3()) {
0 ignored issues
show
Bug introduced by
Since hasReflectionDocBlock3() 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 hasReflectionDocBlock3() 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...
19
            return new CommandDocBlockParser3($commandInfo, $reflection);
20
        }
21
        return new CommandDocBlockParser2($commandInfo, $reflection);
22
    }
23
24
    private static function hasReflectionDocBlock3()
25
    {
26
        return class_exists('phpDocumentor\Reflection\DocBlockFactory') && class_exists('phpDocumentor\Reflection\Types\ContextFactory');
27
    }
28
}
29