ElementVirtualLinkedController   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 14
eloc 29
dl 0
loc 92
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A ElementHolder() 0 3 1
A redirect() 0 10 3
A __call() 0 9 2
A hasMethod() 0 8 2
A checkAccessAction() 0 9 2
A hasAction() 0 9 2
A Link() 0 9 2
1
<?php
2
3
namespace DNADesign\ElementalVirtual\Control;
4
5
use DNADesign\Elemental\Controllers\ElementController;
6
use Exception;
7
8
class ElementVirtualLinkedController extends ElementController
9
{
10
11
    /**
12
     * Returns the current element in scope rendered into its' holder
13
     *
14
     * @return HTML
0 ignored issues
show
Bug introduced by
The type DNADesign\ElementalVirtual\Control\HTML was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
     */
16
    public function ElementHolder()
17
    {
18
        return $this->renderWith('ElementHolder_VirtualLinked');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->renderWith...tHolder_VirtualLinked') returns the type SilverStripe\ORM\FieldType\DBHTMLText which is incompatible with the documented return type DNADesign\ElementalVirtual\Control\HTML.
Loading history...
19
    }
20
21
    /**
22
     * @param string $action
23
     *
24
     * @return string
25
     */
26
    public function Link($action = null)
27
    {
28
        if ($this->data()->virtualOwner) {
0 ignored issues
show
Bug introduced by
The method data() does not exist on DNADesign\ElementalVirtu...VirtualLinkedController. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

28
        if ($this->/** @scrutinizer ignore-call */ data()->virtualOwner) {
Loading history...
29
            $controller = ElementController::create($this->data()->virtualOwner);
30
31
            return $controller->Link($action);
32
        }
33
34
        return parent::Link($action);
35
    }
36
37
    /**
38
     * if this is a virtual request, change the hash if set.
39
     *
40
     * @param string $url
41
     * @param int $code
42
     *
43
     * @return HTTPResponse
0 ignored issues
show
Bug introduced by
The type DNADesign\ElementalVirtual\Control\HTTPResponse was not found. Did you mean HTTPResponse? If so, make sure to prefix the type with \.
Loading history...
44
     */
45
    public function redirect($url, $code = 302)
46
    {
47
        if ($this->data()->virtualOwner) {
48
            $parts = explode('#', $url);
49
            if (isset($parts[1])) {
50
                $url = $parts[0] . '#' . $this->data()->virtualOwner->ID;
51
            }
52
        }
53
54
        return parent::redirect($url, $code);
0 ignored issues
show
Bug Best Practice introduced by
The expression return parent::redirect($url, $code) returns the type SilverStripe\Control\HTTPResponse which is incompatible with the documented return type DNADesign\ElementalVirtual\Control\HTTPResponse.
Loading history...
55
    }
56
57
58
59
    public function __call($method, $arguments)
60
    {
61
        try {
62
            $retVal = parent::__call($method, $arguments);
63
        } catch (Exception $e) {
64
            $controller = $this->LinkedElement()->getController();
0 ignored issues
show
Bug introduced by
The method LinkedElement() does not exist on DNADesign\ElementalVirtu...VirtualLinkedController. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

64
            $controller = $this->/** @scrutinizer ignore-call */ LinkedElement()->getController();
Loading history...
65
            $retVal = call_user_func_array([$controller, $method], $arguments);
66
        }
67
        return $retVal;
68
    }
69
70
    public function hasMethod($action)
71
    {
72
        if (parent::hasMethod($action)) {
73
            return true;
74
        }
75
76
        $controller = $this->LinkedElement()->getController();
77
        return $controller->hasMethod($action);
78
    }
79
80
    public function hasAction($action)
81
    {
82
        if (parent::hasAction($action)) {
83
            return true;
84
        }
85
86
        $controller = $this->LinkedElement()->getController();
87
88
        return $controller->hasAction($action);
89
    }
90
91
    public function checkAccessAction($action)
92
    {
93
        if (parent::checkAccessAction($action)) {
94
            return true;
95
        }
96
97
        $controller = $this->LinkedElement()->getController();
98
99
        return $controller->checkAccessAction($action);
100
    }
101
}
102