Target   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 172
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 11
eloc 23
dl 0
loc 172
rs 10
c 1
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A getMethodName() 0 3 1
A makeClass() 0 3 1
A getFunctionName() 0 3 1
A __construct() 0 7 1
A isFunction() 0 3 1
A makeFunction() 0 3 1
A getClassName() 0 3 1
A isClass() 0 3 1
A setMethodArgs() 0 3 1
A method() 0 3 1
A args() 0 3 1
1
<?php
2
3
/**
4
 * Target.php - Jaxon Request Target
5
 *
6
 * This class contains the name of the function or class and method targetted by a Jaxon request.
7
 *
8
 * @package jaxon-core
9
 * @author Thierry Feuzeu <[email protected]>
10
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
11
 * @link https://github.com/jaxon-php/jaxon-core
12
 */
13
14
namespace Jaxon\Request;
15
16
class Target implements TargetInterface
17
{
18
    /**
19
     * The target type for function.
20
     *
21
     * @var string
22
     */
23
    const TYPE_FUNCTION = 'TargetFunction';
24
25
    /**
26
     * The target type for class.
27
     *
28
     * @var string
29
     */
30
    const TYPE_CLASS = 'TargetClass';
31
32
    /**
33
     * The target type.
34
     *
35
     * @var string
36
     */
37
    private $sType = '';
38
39
    /**
40
     * The target function name.
41
     *
42
     * @var string
43
     */
44
    private $sFunctionName = '';
45
46
    /**
47
     * The target class name.
48
     *
49
     * @var string
50
     */
51
    private $sClassName = '';
52
53
    /**
54
     * The target method name.
55
     *
56
     * @var string
57
     */
58
    private $sMethodName = '';
59
60
    /**
61
     * The target method args.
62
     *
63
     * @var array
64
     */
65
    private $aMethodArgs = [];
66
67
    /**
68
     * The constructor
69
     *
70
     * @param string $sType    The target type
71
     * @param string $sFunctionName    The function name
72
     * @param string $sClassName    The class name
73
     * @param string $sMethodName    The method name
74
     * @param array $aMethodArgs    The method args
75
     */
76
    private function __construct(string $sType, string $sFunctionName, string $sClassName, string $sMethodName, array $aMethodArgs = [])
77
    {
78
        $this->sType = $sType;
79
        $this->sFunctionName = $sFunctionName;
80
        $this->sClassName = $sClassName;
81
        $this->sMethodName = $sMethodName;
82
        $this->aMethodArgs = $aMethodArgs;
83
    }
84
85
    /**
86
     * Create a target of type Function
87
     *
88
     * @param string $sFunctionName    The function name
89
     *
90
     * @return Target
91
     */
92
    public static function makeFunction(string $sFunctionName): Target
93
    {
94
        return new Target(self::TYPE_FUNCTION, $sFunctionName, '', '');
95
    }
96
97
    /**
98
     * Create a target of type Class
99
     *
100
     * @param string $sClassName    The class name
101
     * @param string $sMethodName    The method name
102
     *
103
     * @return Target
104
     */
105
    public static function makeClass(string $sClassName, string $sMethodName): Target
106
    {
107
        return new Target(self::TYPE_CLASS, '', $sClassName, $sMethodName);
108
    }
109
110
    /**
111
     * Check if the target type is Function.
112
     *
113
     * @return bool
114
     */
115
    public function isFunction(): bool
116
    {
117
        return $this->sType === self::TYPE_FUNCTION;
118
    }
119
120
    /**
121
     * Check if the target type is Class.
122
     *
123
     * @return bool
124
     */
125
    public function isClass(): bool
126
    {
127
        return $this->sType === self::TYPE_CLASS;
128
    }
129
130
    /**
131
     * The target function name.
132
     *
133
     * @return string
134
     */
135
    public function getFunctionName(): string
136
    {
137
        return $this->sFunctionName;
138
    }
139
140
    /**
141
     * The target class name.
142
     *
143
     * @return string
144
     */
145
    public function getClassName(): string
146
    {
147
        return $this->sClassName;
148
    }
149
150
    /**
151
     * The target method name.
152
     *
153
     * @return string
154
     */
155
    public function getMethodName(): string
156
    {
157
        return $this->sMethodName;
158
    }
159
160
    /**
161
     * Set the target method name.
162
     *
163
     * @param array $aMethodArgs
164
     */
165
    public function setMethodArgs(array $aMethodArgs): void
166
    {
167
        $this->aMethodArgs = $aMethodArgs;
168
    }
169
170
    /**
171
     * The target method name.
172
     *
173
     * @return string
174
     */
175
    public function method(): string
176
    {
177
        return $this->sMethodName;
178
    }
179
180
    /**
181
     * The target method args.
182
     *
183
     * @return array
184
     */
185
    public function args(): array
186
    {
187
        return $this->aMethodArgs;
188
    }
189
}
190