1 | <?php |
||
53 | class Provider |
||
54 | { |
||
55 | protected $manager = null; |
||
56 | |||
57 | protected $service = null; |
||
58 | |||
59 | /** @var AbstractContract[] $providers */ |
||
60 | protected $providers = array(); |
||
61 | |||
62 | /** |
||
63 | * __construct |
||
64 | * |
||
65 | * @param Manager $manager Manager instance |
||
66 | * @param string $service service name (case sensitive) |
||
67 | */ |
||
68 | 8 | public function __construct(Manager $manager, $service) |
|
73 | |||
74 | /** |
||
75 | * getProviderMode |
||
76 | * |
||
77 | * @return Manager MODE constant |
||
78 | */ |
||
79 | 2 | public function getProviderMode() |
|
92 | |||
93 | /** |
||
94 | * registerProvider - register a provider of a named service |
||
95 | * |
||
96 | * @param string $object instantiated object that provides the service |
||
97 | * |
||
98 | * @return void |
||
99 | */ |
||
100 | 1 | public function register($object) |
|
111 | |||
112 | /** |
||
113 | * getRegistered - access list of registered providers |
||
114 | * |
||
115 | * @return array of registered providers managed by this instance |
||
116 | */ |
||
117 | 2 | public function &getRegistered() |
|
121 | |||
122 | /** |
||
123 | * sortProviders - sort providers into priority order |
||
124 | * |
||
125 | * @return void |
||
126 | */ |
||
127 | 2 | public function sortProviders() |
|
139 | |||
140 | /** |
||
141 | * isAvailable - indicate the availability of an actual provider |
||
142 | * |
||
143 | * In many cases a null provider can be called without changing the flow of the calling |
||
144 | * program. In some cases, the availability of a provider may need to be reflected in |
||
145 | * the caller, i.e. adding a UI button or menu item. |
||
146 | * |
||
147 | * @return boolean true if actual provider is available, otherwise false |
||
148 | */ |
||
149 | 1 | public function isAvailable() |
|
153 | |||
154 | /** |
||
155 | * All contract specified methods go here |
||
156 | * |
||
157 | * @param string $name method to call |
||
158 | * @param mixed $arguments any arguments |
||
159 | * |
||
160 | * @return Response Response |
||
161 | */ |
||
162 | 2 | public function __call($name, $arguments) |
|
163 | { |
||
164 | 2 | $mode = $this->getProviderMode(); |
|
|
|||
165 | |||
166 | // for right now only one provider will be called, and it should be at the top |
||
167 | 2 | $object = reset($this->providers); |
|
168 | 2 | $method = array($object, $name); |
|
169 | 2 | $response = new Response(); |
|
170 | 2 | if (is_callable($method)) { |
|
171 | try { |
||
172 | //$object->$name($response, $arguments); |
||
173 | 2 | array_unshift($arguments, $response); |
|
174 | 2 | call_user_func_array($method, $arguments); |
|
175 | } catch (\Exception $e) { |
||
176 | \Xoops::getInstance()->events()->triggerEvent('core.exception', $e); |
||
177 | $response->setSuccess(false)->addErrorMessage($e->getMessage()); |
||
178 | } |
||
179 | } else { |
||
180 | $response->setSuccess(false)->addErrorMessage(sprintf('No method %s', $name)); |
||
181 | } |
||
182 | 2 | return $response; |
|
183 | } |
||
184 | |||
185 | /** |
||
186 | * All static methods go here and will return null |
||
187 | * |
||
188 | * @param string $name not used |
||
189 | * @param mixed $arguments not used |
||
190 | * |
||
191 | * @return null |
||
192 | */ |
||
193 | 1 | public static function __callStatic($name, $arguments) |
|
197 | } |
||
198 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.