Code Duplication    Length = 29-29 lines in 2 locations

src/Factory/FilterFactory.php 1 location

@@ 14-42 (lines=29) @@
11
12
use Jenner\LogMonitor\Filter\FilterInterface;
13
14
class FilterFactory
15
{
16
    /**
17
     * @param null $class_name
18
     * @return FilterInterface
19
     */
20
    public static function create($class_name)
21
    {
22
        if (is_object($class_name)) {
23
            return $class_name;
24
        }
25
26
        if (empty($class_name)) {
27
            throw new \InvalidArgumentException("empty class name");
28
        }
29
30
        if (!class_exists($class_name)) {
31
            throw new \RuntimeException($class_name . ' class is not exists');
32
        }
33
34
        $reflect = new \ReflectionClass($class_name);
35
        $parent_class = "\\AdTeam\\LogMonitor\\Filter\\FilterInterface";
36
        if (!$reflect->isSubclassOf($parent_class)) {
37
            throw new \RuntimeException($class_name . ' must be a sub class of ' . $parent_class);
38
        }
39
40
        return new $class_name();
41
    }
42
}

src/Factory/NotificationFactory.php 1 location

@@ 14-42 (lines=29) @@
11
12
use Jenner\LogMonitor\Notification\EchoNotification;
13
14
class NotificationFactory
15
{
16
    /**
17
     * @param $classname
18
     * @return EchoNotification
19
     */
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
}