| Conditions | 6 |
| Paths | 6 |
| Total Lines | 30 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 17 |
| CRAP Score | 6.2488 |
| Changes | 0 | ||
| 1 | <?php |
||
| 18 | 12 | public static function checkOverwriteRunMethod($child_class) |
|
| 19 | { |
||
| 20 | 12 | $parent_class = '\\Jenner\\SimpleFork\\Process'; |
|
| 21 | 12 | if ($child_class == $parent_class) { |
|
| 22 | $message = "you should extend the `{$parent_class}`" . |
||
| 23 | ' and overwrite the run method'; |
||
| 24 | throw new \RuntimeException($message); |
||
| 25 | } |
||
| 26 | |||
| 27 | 12 | $child = new \ReflectionClass($child_class); |
|
| 28 | 12 | if ($child->getParentClass() === false) { |
|
| 29 | 3 | $message = "you should extend the `{$parent_class}`" . |
|
| 30 | 3 | ' and overwrite the run method'; |
|
| 31 | 3 | throw new \RuntimeException($message); |
|
| 32 | } |
||
| 33 | |||
| 34 | 9 | $parent_methods = $child->getParentClass()->getMethods(\ReflectionMethod::IS_PUBLIC); |
|
| 35 | |||
| 36 | 9 | foreach ($parent_methods as $parent_method) { |
|
| 37 | 9 | if ($parent_method->getName() !== 'run') continue; |
|
| 38 | |||
| 39 | 9 | $declaring_class = $child->getMethod($parent_method->getName()) |
|
| 40 | 9 | ->getDeclaringClass() |
|
| 41 | 9 | ->getName(); |
|
| 42 | |||
| 43 | 9 | if ($declaring_class === $parent_class) { |
|
| 44 | throw new \RuntimeException('you must overwrite the run method'); |
||
| 45 | } |
||
| 46 | 9 | } |
|
| 47 | } |
||
| 48 | } |