ReaderFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B create() 0 25 5
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
class ReaderFactory
13
{
14
    /**
15
     * @param $file
16
     * @param $classname
17
     * @return mixed
18
     */
19
    public static function create($file, $classname)
20
    {
21
        if (is_object($classname)) {
22
            return $classname;
23
        }
24
25
        if (empty($classname)) {
26
            throw new \InvalidArgumentException("empty class name");
27
        }
28
29
        if (!class_exists($classname)) {
30
            throw new \RuntimeException($classname . ' class is not exists');
31
        }
32
33
        $reflect = new \ReflectionClass($classname);
34
        $parent_class = "\\AdTeam\\LogMonitor\\Reader\\ReaderInterface";
35
        if (!$reflect->isSubclassOf($parent_class)) {
36
            throw new \RuntimeException($classname . ' must be a sub class of ' . $parent_class);
37
        }
38
39
        $obj = new $classname();
40
        $obj->configure($file);
41
42
        return $obj;
43
    }
44
}