Ajde_View::fromRoute()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 4
nop 1
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
class Ajde_View extends Ajde_Template
4
{
5
    /**
6
     * @param Ajde_Controller $controller
7
     *
8
     * @return Ajde_View
9
     */
10
    public static function fromController(Ajde_Controller $controller)
11
    {
12
        $base = MODULE_DIR.$controller->getModule().'/';
13
        $action = $controller->getRoute()->getController() ?
14
            $controller->getRoute()->getController().'/'.$controller->getAction() :
15
            $controller->getAction();
16
        $format = $controller->hasFormat() ? $controller->getFormat() : 'html';
0 ignored issues
show
Documentation Bug introduced by
The method hasFormat does not exist on object<Ajde_Controller>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
17
18
        return new self($base, $action, $format);
19
    }
20
21
    /**
22
     * @param Ajde_Core_Route $route
23
     *
24
     * @return Ajde_View
25
     */
26
    public static function fromRoute($route)
27
    {
28
        if (!$route instanceof Ajde_Core_Route) {
29
            $route = new Ajde_Core_Route($route);
30
        }
31
        $base = MODULE_DIR.$route->getModule().'/';
32
        $action = $route->getController() ?
33
            $route->getController().'/'.$route->getAction() :
34
            $route->getAction();
35
        $format = $route->getFormat();
36
37
        return new self($base, $action, $format);
38
    }
39
}
40