NotificationFactory::create()   B
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 22
Code Lines 12

Duplication

Lines 22
Ratio 100 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 22
loc 22
rs 8.6737
cc 5
eloc 12
nc 5
nop 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Jenner
5
 * Date: 2015/10/14
6
 * Time: 10:39
7
 */
8
9
namespace Jenner\LogMonitor\Factory;
10
11
12
use Jenner\LogMonitor\Notification\EchoNotification;
13
14 View Code Duplication
class NotificationFactory
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

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.

Loading history...
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
}