Completed
Pull Request — master (#35)
by Saif Eddin
02:32
created

ClassCollectorFactory::__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;
4
5
class ClassCollectorFactory
6
{
7
    /**
8
    * @var ClassCollector $collector;
9
    */
10
    private static $collector;
11
    
12
    private function __construct() {}
13
    
14
    /**
15
     * @return \PhpToZephir\ClassCollector
16
     */
17 1
    public static function getInstance()
18
    {
19 1
        if(static::$collector !== null) {
0 ignored issues
show
Bug introduced by
Since $collector is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $collector 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...
20
            return static::$collector;   
0 ignored issues
show
Bug introduced by
Since $collector is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $collector 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...
21
        }
22 1
        return static::$collector = new ClassCollector(
0 ignored issues
show
Bug introduced by
Since $collector is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $collector 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
            new NodeFetcher(),
24 1
            new ReservedWordReplacer()
25 1
        );
26
    }
27
}
28