slince /
di
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | /* |
||
| 6 | * This file is part of the slince/di package. |
||
| 7 | * |
||
| 8 | * (c) Slince <[email protected]> |
||
| 9 | * |
||
| 10 | * For the full copyright and license information, please view the LICENSE |
||
| 11 | * file that was distributed with this source code. |
||
| 12 | */ |
||
| 13 | |||
| 14 | namespace Slince\Di; |
||
| 15 | |||
| 16 | class Definition |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * @var mixed |
||
| 20 | */ |
||
| 21 | protected $concrete; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @var string |
||
| 25 | */ |
||
| 26 | protected $class; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Array of arguments. |
||
| 30 | * |
||
| 31 | * @var array |
||
| 32 | */ |
||
| 33 | protected $arguments = []; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Array of setters. |
||
| 37 | * |
||
| 38 | * @var array |
||
| 39 | */ |
||
| 40 | protected $calls = []; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Array of properties. |
||
| 44 | * |
||
| 45 | * @var array |
||
| 46 | */ |
||
| 47 | protected $properties = []; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * ['@Foo\Bar', 'createBaz'] |
||
| 51 | * or |
||
| 52 | * ['Foo\Bar', 'createBaz']. |
||
| 53 | * |
||
| 54 | * @var \callable |
||
|
0 ignored issues
–
show
|
|||
| 55 | */ |
||
| 56 | protected $factory; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @var array |
||
| 60 | */ |
||
| 61 | protected $tags; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @var boolean |
||
| 65 | */ |
||
| 66 | protected $autowired = true; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @var boolean |
||
| 70 | */ |
||
| 71 | protected $shared = true; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @var object |
||
| 75 | */ |
||
| 76 | protected $resolved; |
||
| 77 | |||
| 78 | public function __construct($concrete) |
||
| 79 | { |
||
| 80 | $this->concrete = $concrete; |
||
| 81 | } |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Set the concrete of the definition. |
||
| 85 | * |
||
| 86 | * @param mixed $concrete |
||
| 87 | */ |
||
| 88 | public function setConcrete($concrete) |
||
| 89 | { |
||
| 90 | $this->concrete = $concrete; |
||
| 91 | } |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Get the concrete of the definition. |
||
| 95 | * |
||
| 96 | * @return mixed |
||
| 97 | */ |
||
| 98 | public function getConcrete() |
||
| 99 | { |
||
| 100 | return $this->concrete; |
||
| 101 | } |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Set class for the definition. |
||
| 105 | * |
||
| 106 | * @param string $class |
||
| 107 | * |
||
| 108 | * @return $this |
||
| 109 | */ |
||
| 110 | public function setClass(string $class) |
||
| 111 | { |
||
| 112 | $this->class = $class; |
||
| 113 | |||
| 114 | return $this; |
||
| 115 | } |
||
| 116 | |||
| 117 | /** |
||
| 118 | * Gets the class. |
||
| 119 | * |
||
| 120 | * @return string |
||
| 121 | */ |
||
| 122 | public function getClass() |
||
| 123 | { |
||
| 124 | return $this->class; |
||
| 125 | } |
||
| 126 | |||
| 127 | /** |
||
| 128 | * @param callable $factory |
||
| 129 | * |
||
| 130 | * @return $this |
||
| 131 | */ |
||
| 132 | public function setFactory($factory) |
||
| 133 | { |
||
| 134 | $this->factory = $factory; |
||
|
0 ignored issues
–
show
It seems like
$factory of type callable is incompatible with the declared type callable of property $factory.
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property. Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.. Loading history...
|
|||
| 135 | |||
| 136 | return $this; |
||
| 137 | } |
||
| 138 | |||
| 139 | /** |
||
| 140 | * @return callable |
||
| 141 | */ |
||
| 142 | public function getFactory() |
||
| 143 | { |
||
| 144 | return $this->factory; |
||
| 145 | } |
||
| 146 | |||
| 147 | /** |
||
| 148 | * @param array $properties |
||
| 149 | */ |
||
| 150 | public function setProperties($properties) |
||
| 151 | { |
||
| 152 | $this->properties = $properties; |
||
| 153 | } |
||
| 154 | |||
| 155 | /** |
||
| 156 | * Gets all properties. |
||
| 157 | * |
||
| 158 | * @return array |
||
| 159 | */ |
||
| 160 | public function getProperties() |
||
| 161 | { |
||
| 162 | return $this->properties; |
||
| 163 | } |
||
| 164 | |||
| 165 | /** |
||
| 166 | * Adds a property. |
||
| 167 | * |
||
| 168 | * @param int|string $name |
||
| 169 | * @param mixed $value |
||
| 170 | * |
||
| 171 | * @return $this |
||
| 172 | */ |
||
| 173 | public function setProperty(string $name, $value) |
||
| 174 | { |
||
| 175 | $this->properties[$name] = $value; |
||
| 176 | |||
| 177 | return $this; |
||
| 178 | } |
||
| 179 | |||
| 180 | /** |
||
| 181 | * Gets the property by given name. |
||
| 182 | * |
||
| 183 | * @param string $name |
||
| 184 | * |
||
| 185 | * @return mixed |
||
| 186 | */ |
||
| 187 | public function getProperty(string $name) |
||
| 188 | { |
||
| 189 | return isset($this->properties[$name]) ? $this->properties[$name] : null; |
||
| 190 | } |
||
| 191 | |||
| 192 | /** |
||
| 193 | * add an argument. |
||
| 194 | * |
||
| 195 | * @param mixed $value |
||
| 196 | * |
||
| 197 | * @return $this |
||
| 198 | */ |
||
| 199 | public function addArgument($value) |
||
| 200 | { |
||
| 201 | $this->arguments[] = $value; |
||
| 202 | |||
| 203 | return $this; |
||
| 204 | } |
||
| 205 | |||
| 206 | /** |
||
| 207 | * Sets a specific argument. |
||
| 208 | * |
||
| 209 | * @param string $key |
||
| 210 | * @param mixed $value |
||
| 211 | * |
||
| 212 | * @return $this |
||
| 213 | */ |
||
| 214 | public function setArgument(string $key, $value) |
||
| 215 | { |
||
| 216 | $this->arguments[$key] = $value; |
||
| 217 | |||
| 218 | return $this; |
||
| 219 | } |
||
| 220 | |||
| 221 | /** |
||
| 222 | * Sets the arguments to pass to the service constructor/factory method. |
||
| 223 | * |
||
| 224 | * @param array $arguments |
||
| 225 | * |
||
| 226 | * @return $this |
||
| 227 | */ |
||
| 228 | public function setArguments(array $arguments) |
||
| 229 | { |
||
| 230 | $this->arguments = $arguments; |
||
| 231 | |||
| 232 | return $this; |
||
| 233 | } |
||
| 234 | |||
| 235 | /** |
||
| 236 | * Gets all arguments of constructor. |
||
| 237 | * |
||
| 238 | * @return array |
||
| 239 | */ |
||
| 240 | public function getArguments() |
||
| 241 | { |
||
| 242 | return $this->arguments; |
||
| 243 | } |
||
| 244 | |||
| 245 | /** |
||
| 246 | * Gets the argument at the specified position of constructor. |
||
| 247 | * |
||
| 248 | * @param int|string $index |
||
| 249 | * |
||
| 250 | * @return mixed |
||
| 251 | */ |
||
| 252 | public function getArgument($index) |
||
| 253 | { |
||
| 254 | return isset($this->arguments[$index]) ? $this->arguments[$index] : null; |
||
| 255 | } |
||
| 256 | |||
| 257 | /** |
||
| 258 | * Adds a method. |
||
| 259 | * |
||
| 260 | * @param string $method |
||
| 261 | * @param string|array $arguments |
||
| 262 | * |
||
| 263 | * @return $this |
||
| 264 | */ |
||
| 265 | public function addMethodCall(string $method, $arguments) |
||
| 266 | { |
||
| 267 | $this->calls[] = [ |
||
| 268 | $method, |
||
| 269 | (array) $arguments, |
||
| 270 | ]; |
||
| 271 | |||
| 272 | return $this; |
||
| 273 | } |
||
| 274 | |||
| 275 | /** |
||
| 276 | * Sets the methods to call after service initialization. |
||
| 277 | * |
||
| 278 | * @param array methods |
||
|
0 ignored issues
–
show
The type
Slince\Di\methods 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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 279 | * |
||
| 280 | * @return $this |
||
| 281 | */ |
||
| 282 | public function setMethodCalls(array $methods) |
||
| 283 | { |
||
| 284 | $this->calls = array(); |
||
| 285 | foreach ($methods as $call) { |
||
| 286 | $this->addMethodCall($call[0], $call[1]); |
||
| 287 | } |
||
| 288 | |||
| 289 | return $this; |
||
| 290 | } |
||
| 291 | |||
| 292 | /** |
||
| 293 | * Gets all methods. |
||
| 294 | * |
||
| 295 | * @return array |
||
| 296 | */ |
||
| 297 | public function getMethodCalls() |
||
| 298 | { |
||
| 299 | return $this->calls; |
||
| 300 | } |
||
| 301 | |||
| 302 | /** |
||
| 303 | * Check if the current definition has a given method to call after service initialization. |
||
| 304 | * |
||
| 305 | * @param string $method The method name to search for |
||
| 306 | * |
||
| 307 | * @return bool |
||
| 308 | */ |
||
| 309 | public function hasMethodCall(string $method) |
||
| 310 | { |
||
| 311 | foreach ($this->calls as $call) { |
||
| 312 | if ($call[0] === $method) { |
||
| 313 | return true; |
||
| 314 | } |
||
| 315 | } |
||
| 316 | |||
| 317 | return false; |
||
| 318 | } |
||
| 319 | |||
| 320 | /** |
||
| 321 | * Sets tags for this definition. |
||
| 322 | * |
||
| 323 | * @param array $tags |
||
| 324 | * |
||
| 325 | * @return $this |
||
| 326 | */ |
||
| 327 | public function setTags(array $tags) |
||
| 328 | { |
||
| 329 | $this->tags = $tags; |
||
| 330 | |||
| 331 | return $this; |
||
| 332 | } |
||
| 333 | |||
| 334 | /** |
||
| 335 | * Returns all tags. |
||
| 336 | * |
||
| 337 | * @return array An array of tags |
||
| 338 | */ |
||
| 339 | public function getTags() |
||
| 340 | { |
||
| 341 | return $this->tags; |
||
| 342 | } |
||
| 343 | |||
| 344 | /** |
||
| 345 | * Gets a tag by name. |
||
| 346 | * |
||
| 347 | * @param string $name The tag name |
||
| 348 | * |
||
| 349 | * @return array An array of attributes |
||
| 350 | */ |
||
| 351 | public function getTag(string $name) |
||
| 352 | { |
||
| 353 | return isset($this->tags[$name]) ? $this->tags[$name] : array(); |
||
| 354 | } |
||
| 355 | |||
| 356 | /** |
||
| 357 | * Adds a tag for this definition. |
||
| 358 | * |
||
| 359 | * @param string $name The tag name |
||
| 360 | * @param array $attributes An array of attributes |
||
| 361 | * |
||
| 362 | * @return $this |
||
| 363 | */ |
||
| 364 | public function addTag(string $name, array $attributes = array()) |
||
| 365 | { |
||
| 366 | $this->tags[$name][] = $attributes; |
||
| 367 | |||
| 368 | return $this; |
||
| 369 | } |
||
| 370 | |||
| 371 | /** |
||
| 372 | * Whether this definition has a tag with the given name. |
||
| 373 | * |
||
| 374 | * @param string $name |
||
| 375 | * |
||
| 376 | * @return bool |
||
| 377 | */ |
||
| 378 | public function hasTag(string $name) |
||
| 379 | { |
||
| 380 | return isset($this->tags[$name]); |
||
| 381 | } |
||
| 382 | |||
| 383 | /** |
||
| 384 | * Clears all tags for a given name. |
||
| 385 | * |
||
| 386 | * @param string $name The tag name |
||
| 387 | * |
||
| 388 | * @return $this |
||
| 389 | */ |
||
| 390 | public function clearTag(string $name) |
||
| 391 | { |
||
| 392 | unset($this->tags[$name]); |
||
| 393 | |||
| 394 | return $this; |
||
| 395 | } |
||
| 396 | |||
| 397 | /** |
||
| 398 | * Clears the tags for this definition. |
||
| 399 | * |
||
| 400 | * @return $this |
||
| 401 | */ |
||
| 402 | public function clearTags() |
||
| 403 | { |
||
| 404 | $this->tags = array(); |
||
| 405 | |||
| 406 | return $this; |
||
| 407 | } |
||
| 408 | |||
| 409 | /** |
||
| 410 | * Is the definition autowired? |
||
| 411 | * |
||
| 412 | * @return bool |
||
| 413 | */ |
||
| 414 | public function isAutowired(): bool |
||
| 415 | { |
||
| 416 | return $this->autowired; |
||
| 417 | } |
||
| 418 | |||
| 419 | /** |
||
| 420 | * Enables/disables autowiring. |
||
| 421 | * |
||
| 422 | * @param bool $autowired |
||
| 423 | * |
||
| 424 | * @return $this |
||
| 425 | */ |
||
| 426 | public function setAutowired($autowired) |
||
| 427 | { |
||
| 428 | $this->autowired = (bool) $autowired; |
||
| 429 | |||
| 430 | return $this; |
||
| 431 | } |
||
| 432 | |||
| 433 | /** |
||
| 434 | * Sets if the service must be shared or not. |
||
| 435 | * |
||
| 436 | * @param bool $shared Whether the service must be shared or not |
||
| 437 | * |
||
| 438 | * @return $this |
||
| 439 | */ |
||
| 440 | public function setShared($shared) |
||
| 441 | { |
||
| 442 | $this->shared = (bool) $shared; |
||
| 443 | |||
| 444 | return $this; |
||
| 445 | } |
||
| 446 | |||
| 447 | /** |
||
| 448 | * Whether this service is shared. |
||
| 449 | * |
||
| 450 | * @return bool |
||
| 451 | */ |
||
| 452 | public function isShared(): bool |
||
| 453 | { |
||
| 454 | return $this->shared; |
||
| 455 | } |
||
| 456 | |||
| 457 | /** |
||
| 458 | * Get resolved instance of the definition. |
||
| 459 | * |
||
| 460 | * @return object |
||
| 461 | */ |
||
| 462 | public function getResolved() |
||
| 463 | { |
||
| 464 | return $this->resolved; |
||
| 465 | } |
||
| 466 | |||
| 467 | /** |
||
| 468 | * Set the resolved instance for the definition. |
||
| 469 | * |
||
| 470 | * @param object $resolved |
||
| 471 | * |
||
| 472 | * @return $this |
||
| 473 | */ |
||
| 474 | public function setResolved($resolved) |
||
| 475 | { |
||
| 476 | $this->resolved = $resolved; |
||
| 477 | |||
| 478 | return $this; |
||
| 479 | } |
||
| 480 | } |
||
| 481 |
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths