ModelFetcher   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 0
cbo 0
dl 0
loc 20
ccs 0
cts 9
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __call() 0 17 3
1
<?php
2
3
namespace BZIon\Twig;
4
5
/**
6
 * A twig global that enables the creation of Models from their IDs
7
 *
8
 * Example usage: `model.newsCategory(15).id`
9
 */
10
class ModelFetcher
11
{
12
    public function __call($type, $arguments)
13
    {
14
        $id = $arguments[0];
15
16
        if ($id instanceof \Model) {
17
            return $id;
18
        }
19
20
        $class = new \ReflectionClass("\\" . ucfirst($type));
21
22
        if (!$class->isSubclassOf("\\Model")) {
23
            throw new \Exception("$type is not a model");
24
        }
25
26
        return $class->getMethod('get')
27
                      ->invoke(null, $id);
28
    }
29
}
30