Conditions | 5 |
Paths | 5 |
Total Lines | 22 |
Code Lines | 12 |
Lines | 22 |
Ratio | 100 % |
Changes | 2 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
20 | public static function create($classname) |
||
21 | { |
||
22 | if (is_object($classname)) { |
||
23 | return $classname; |
||
24 | } |
||
25 | |||
26 | if (empty($classname)) { |
||
27 | throw new \InvalidArgumentException("empty class name"); |
||
28 | } |
||
29 | |||
30 | if (!class_exists($classname)) { |
||
31 | throw new \RuntimeException($classname . ' class is not exists'); |
||
32 | } |
||
33 | |||
34 | $reflect = new \ReflectionClass($classname); |
||
35 | $parent_class = "\\AdTeam\\LogMonitor\\Notification\\NotificationInterface"; |
||
36 | if (!$reflect->isSubclassOf($parent_class)) { |
||
37 | throw new \RuntimeException($classname . ' must be a sub class of ' . $parent_class); |
||
38 | } |
||
39 | |||
40 | return new $classname(); |
||
41 | } |
||
42 | } |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.