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

ConverterFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 1
ccs 0
cts 0
cp 0
rs 10
cc 1
eloc 1
nc 1
nop 0
crap 2
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