| Conditions | 3 | 
| Paths | 3 | 
| Total Lines | 26 | 
| Code Lines | 17 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Tests | 17 | 
| CRAP Score | 3.0015 | 
| Changes | 1 | ||
| Bugs | 0 | Features | 0 | 
| 1 | <?php | ||
| 14 | 1 | public static function getInstance() | |
| 15 |     { | ||
| 16 | 1 |         if(static::$dispatcher !== null) { | |
|  | |||
| 17 | return static::$dispatcher; | ||
| 18 | } | ||
| 19 | 1 | $dirName = __DIR__.'/Printer/'; | |
| 20 | 1 | $directory = new \RecursiveDirectoryIterator($dirName); | |
| 21 | 1 | $iterator = new \RecursiveIteratorIterator($directory); | |
| 22 | 1 | $regex = new \RegexIterator($iterator, '/^.+\.php$/i', \RecursiveRegexIterator::GET_MATCH); | |
| 23 | 1 | $classes = new PrinterCollection(array()); | |
| 24 | 1 | include 'SimplePrinter.php'; | |
| 25 | |||
| 26 | 1 |         foreach ($regex as $fileInfo) { | |
| 27 | 1 | $declaredClasses = get_declared_classes(); | |
| 28 | 1 | include $fileInfo[0]; | |
| 29 | |||
| 30 | 1 | $className = current(array_diff(get_declared_classes(), $declaredClasses)); | |
| 31 | |||
| 32 | 1 | $classes->offsetSet($className::getType(), $className); | |
| 33 | 1 | } | |
| 34 | |||
| 35 | 1 | return static::$dispatcher = new Dispatcher( | |
| 36 | 1 | $classes, | |
| 37 | include __DIR__.'/PrecedenceMap.php' | ||
| 38 | 1 | ); | |
| 39 | } | ||
| 40 | } | ||
| 41 | 
Let’s assume you have a class which uses late-static binding:
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:In the case above, it makes sense to update
SomeClassto useselfinstead: