Utils   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 80.95%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 38
ccs 17
cts 21
cp 0.8095
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B checkOverwriteRunMethod() 0 30 6
1
<?php
2
/**
3
 * @author Jenner <[email protected]>
4
 * @license https://opensource.org/licenses/MIT MIT
5
 * @datetime: 2015/11/11 17:50
6
 */
7
8
namespace Jenner\SimpleFork;
9
10
11
class Utils
12
{
13
    /**
14
     * check if the sub class of Process has overwrite the run method
15
     *
16
     * @param $child_class
17
     */
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
}