Passed
Push — master ( 535460...57bd4b )
by Thierry
02:39
created

CallableClass::rq()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace Jaxon;
4
5
use Jaxon\Request\Support\CallableObject;
6
7
use Psr\Log\LoggerInterface;
8
9
class CallableClass
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class CallableClass
Loading history...
10
{
11
    /**
12
     * The Callable object associated to this class
13
     *
14
     * @var CallableObject
15
     */
16
    private $xCallableObject = null;
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before first member var; 0 found
Loading history...
17
18
    /**
19
     * The Jaxon response returned by all classes methods
20
     *
21
     * @var \Jaxon\Response\Response
22
     */
23
    protected $response = null;
24
25
    /**
26
     * Get the view renderer
27
     *
28
     * @return \Jaxon\Utils\View\Renderer
29
     */
30
    public function view()
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
31
    {
32
        return jaxon()->view();
33
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
34
35
    /**
36
     * Get the session manager
37
     *
38
     * @return \Jaxon\Contracts\Session
39
     */
40
    public function session()
41
    {
42
        return jaxon()->session();
43
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
44
45
    /**
46
     * Get the logger
47
     *
48
     * @return LoggerInterface
49
     */
50
    public function logger()
51
    {
52
        return jaxon()->logger();
53
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
54
55
    /**
56
     * Get the request factory.
57
     *
58
     * @return \Jaxon\Request\Factory\CallableClass\Request
59
     */
60
    public function rq()
61
    {
62
        return jaxon()->di()->getCallableClassRequestFactory(get_class($this));
63
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
64
65
    /**
66
     * Create a JQuery Element with a given selector, and link it to the response attribute.
67
     *
68
     * @param string        $sSelector            The jQuery selector
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 12 found
Loading history...
69
     * @param string        $sContext             A context associated to the selector
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter name; 13 found
Loading history...
70
     *
71
     * @return \Jaxon\Response\Plugin\JQuery\Dom\Element
72
     */
73
    public function jq($sSelector = '', $sContext = '')
74
    {
75
        return $this->response->plugin('jquery')->element($sSelector, $sContext);
76
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
77
78
    /**
79
     * Get an instance of a Jaxon class by name
80
     *
81
     * @param string $name the class name
82
     *
83
     * @return CallableClass|null the Jaxon class instance, or null
0 ignored issues
show
Documentation introduced by
Should the return type not be object|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
84
     */
85
    public function cl($name)
86
    {
87
        $cFirstChar = substr($name, 0, 1);
88
        // If the class name starts with a dot, then find the class in the same full namespace as the caller
89
        if($cFirstChar == ':')
90
        {
91
            $name = $this->xCallableObject->getRootNamespace() . '\\' . str_replace('.', '\\', substr($name, 1));
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $name. This often makes code more readable.
Loading history...
92
        }
93
        // If the class name starts with a dot, then find the class in the same base namespace as the caller
94
        elseif($cFirstChar == '.')
95
        {
96
            $name = $this->xCallableObject->getNamespace() . '\\' . str_replace('.', '\\', substr($name, 1));
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $name. This often makes code more readable.
Loading history...
97
        }
98
        // Find the class instance
99
        return jaxon()->instance($name);
100
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
101
102
    /**
103
     * Get the uploaded files
104
     *
105
     * @return array
106
     */
107
    public function files()
108
    {
109
        return jaxon()->upload()->files();
110
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
111
}
112