Conversation
4f185b0 to
9ac1dda
Compare
system/Config/BaseService.php
Outdated
| * | ||
| * @return mixed Entry. | ||
| */ | ||
| public static function get(string $key): mixed |
There was a problem hiding this comment.
Applicable review until override().
mixed should be limited to object, as the static array prop $instances accepts object as value. I don't think we need to accept anything to be set. Accepting mixed may lead to future misuses.
system/Config/BaseService.php
Outdated
| * Sets an entry. | ||
| * | ||
| * @param string $key Identifier of the entry. | ||
| * @param mixed $value Normally an object. |
system/Config/BaseService.php
Outdated
| public static function set(string $key, mixed $value): void | ||
| { | ||
| if (isset(static::$instances[$key])) { | ||
| throw new InvalidArgumentException('The Entry for "' . $key . '" is already set.'); |
There was a problem hiding this comment.
| throw new InvalidArgumentException('The Entry for "' . $key . '" is already set.'); | |
| throw new InvalidArgumentException('The entry for "' . $key . '" is already set.'); |
system/Config/BaseService.php
Outdated
| * Overrides an existing entry. | ||
| * | ||
| * @param string $key Identifier of the entry. | ||
| * @param mixed $value Normally an object. |
|
The more I think about this the more confused I am about the performance issue we're seeing. All methods are static and should be called before |
|
The current Services is not that simple. CodeIgniter4/app/Config/Services.php Line 20 in fd28a3f and BaseService has only $ grep function system/Config/BaseService.php
public static function get(string $key): ?object
public static function set(string $key, object $value): void
public static function override(string $key, object $value): void
protected static function getSharedInstance(string $key, ...$params)
public static function autoloader(bool $getShared = true)
public static function locator(bool $getShared = true)
public static function __callStatic(string $name, array $arguments)
public static function serviceExists(string $name): ?string
public static function reset(bool $initAutoloader = true)
public static function resetSingle(string $name)
public static function injectMock(string $name, $mock)
protected static function buildServicesCache(): void |
|
Yeah, I guess the only ones that would hit directly would be in |
|
How do I work with the magic of services? The analyzer swears at the returned type. It looks sad. // some code
$this->request = service('request');Errors: 3) tests/system/Honeypot/HoneypotTest.php:37
---------- begin diff ----------
@@ @@
/**
* @var CLIRequest|IncomingRequest
*/
- private $request;
+ private ?object $request = null;
private Response $response;
----------- end diff -----------
Applied rules:
* TypedPropertyFromAssignsRector |
Description
Services::get()method to get the shared instance fast.service()usesServices::get()Checklist: