Passed
Push — master ( 548923...89935f )
by Thierry
08:39
created

CallableClass::bag()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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

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

81
        return $this->response->plugin('jquery')->/** @scrutinizer ignore-call */ element($sSelector, $sContext);
Loading history...
82
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
83
84
    /**
85
     * Get an instance of a Jaxon class by name
86
     *
87
     * @param string $name the class name
88
     *
89
     * @return CallableClass|null the Jaxon class instance, or null
90
     */
91
    public function cl($name)
92
    {
93
        $cFirstChar = substr($name, 0, 1);
94
        // If the class name starts with a dot, then find the class in the same full namespace as the caller
95
        if($cFirstChar == ':')
96
        {
97
            $name = $this->callable->getRootNamespace() . '\\' . str_replace('.', '\\', substr($name, 1));
98
        }
99
        // If the class name starts with a dot, then find the class in the same base namespace as the caller
100
        elseif($cFirstChar == '.')
101
        {
102
            $name = $this->callable->getNamespace() . '\\' . str_replace('.', '\\', substr($name, 1));
103
        }
104
        // Find the class instance
105
        return jaxon()->instance($name);
106
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
107
108
    /**
109
     * Get the uploaded files
110
     *
111
     * @return array
112
     */
113
    public function files()
114
    {
115
        return jaxon()->upload()->files();
116
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
117
118
    /**
119
     * Get a data bag.
120
     *
121
     * @param string        $sName
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
122
     *
123
     * @return Bag
124
     */
125
    public function bag($sName)
126
    {
127
        return $this->response->plugin('bags')->bag($sName);
0 ignored issues
show
Bug introduced by
The method bag() does not exist on Jaxon\Plugin\Response. It seems like you code against a sub-type of Jaxon\Plugin\Response such as Jaxon\Response\Plugin\DataBag. ( Ignorable by Annotation )

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

127
        return $this->response->plugin('bags')->/** @scrutinizer ignore-call */ bag($sName);
Loading history...
128
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
129
}
130