Completed
Push — master ( eb4a71...8120d9 )
by Hu
09:57 queued 07:59
created

Utils   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 77.27%

Importance

Changes 5
Bugs 1 Features 3
Metric Value
wmc 6
c 5
b 1
f 3
lcom 0
cbo 0
dl 0
loc 39
ccs 17
cts 22
cp 0.7727
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B checkOverwriteRunMethod() 0 31 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
                $message = "you must overwrite the run method";
45
                throw new \RuntimeException($message);
46
            }
47 9
        }
48
    }
49
}