Completed
Pull Request — master (#35)
by Saif Eddin
02:55 queued 38s
created

ConverterFactory::getInstance()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
ccs 4
cts 5
cp 0.8
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
crap 2.032
1
<?php
2
3
namespace PhpToZephir\Converter;
4
5
use PhpToZephir\NodeFetcher;
6
7
class ConverterFactory
8
{
9
    /**
10
    * @var Converter $converter
11
    */
12
    private static $converter;
13
    
14
    private function __construct() {}
15
    
16
    /**
17
     * @return \PhpToZephir\Converter\Converter
18
     */
19 1
    public static function getInstance()
20
    {
21 1
        if(static::$converter !== null) {
0 ignored issues
show
Bug introduced by
Since $converter is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $converter to at least protected.

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

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

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 { }

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

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

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
22
            return static::$converter;   
0 ignored issues
show
Bug introduced by
Since $converter is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $converter to at least protected.

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

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

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 { }

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

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

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
23 1
        }
24 1
        return static::$converter = new Converter(DispatcherFactory::getInstance(), new NodeFetcher());
0 ignored issues
show
Bug introduced by
Since $converter is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $converter to at least protected.

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

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

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 { }

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

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

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
25
    }
26
}
27