ActiveRecordFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 18
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A make() 0 8 2
1
<?php
2
3
namespace leinonen\Yii2Algolia\ActiveRecord;
4
5
use yii\db\ActiveRecordInterface;
6
7
class ActiveRecordFactory
8
{
9
    /**
10
     * Returns an new ActiveRecordInterface instance.
11
     *
12
     * @param string $className
13
     *
14
     * @return ActiveRecordInterface
15
     */
16 5
    public function make($className)
17
    {
18 5
        if (! (new \ReflectionClass($className))->implementsInterface(ActiveRecordInterface::class)) {
19 1
            throw new \InvalidArgumentException("Cannot initiate a class ({$className}) which doesn't implement \\yii\\db\\ActiveRecordInterface");
20
        }
21
22 4
        return new $className();
23
    }
24
}
25