NotificationFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 29
loc 29
wmc 5
lcom 0
cbo 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B create() 22 22 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
}