Skip to content

Commit

Permalink
improve
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik committed Mar 3, 2024
1 parent fedff5e commit 4afec90
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ public function get(string $id)
*/
private function addDefinition(string $id, mixed $definition): void
{
/** @var mixed $definition */
[$definition, $meta] = DefinitionParser::parse($definition);

Check failure on line 205 in src/Container.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.0-ubuntu-latest

MixedAssignment

src/Container.php:205:10: MixedAssignment: Unable to determine the type that $definition is being assigned to (see https://psalm.dev/032)

Check failure on line 205 in src/Container.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.0-ubuntu-latest

MixedAssignment

src/Container.php:205:10: MixedAssignment: Unable to determine the type that $definition is being assigned to (see https://psalm.dev/032)

Check failure on line 205 in src/Container.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.1-ubuntu-latest

MixedAssignment

src/Container.php:205:10: MixedAssignment: Unable to determine the type that $definition is being assigned to (see https://psalm.dev/032)
if ($this->validate) {
$this->validateDefinition($definition, $id);
Expand Down Expand Up @@ -630,11 +629,22 @@ private function buildProvider(mixed $provider): ServiceProviderInterface

private function decorateLazy(string $id, mixed $definition): DefinitionInterface
{
if (class_exists($id) || interface_exists($id)) {
$class = $id;
} elseif (is_array($definition) && array_key_exists(ArrayDefinition::CLASS_NAME, $definition)) {
$class = (string) $definition[ArrayDefinition::CLASS_NAME];
$class = class_exists($id) || interface_exists($id) ? $id : null;

if (is_array($definition) && isset($definition[DefinitionParser::IS_PREPARED_ARRAY_DEFINITION_DATA])) {
if (empty($class)) {
$class = $definition[ArrayDefinition::CLASS_NAME];

Check failure on line 636 in src/Container.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.0-ubuntu-latest

MixedAssignment

src/Container.php:636:17: MixedAssignment: Unable to determine the type that $class is being assigned to (see https://psalm.dev/032)

Check failure on line 636 in src/Container.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.0-ubuntu-latest

MixedAssignment

src/Container.php:636:17: MixedAssignment: Unable to determine the type that $class is being assigned to (see https://psalm.dev/032)

Check failure on line 636 in src/Container.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.1-ubuntu-latest

MixedAssignment

src/Container.php:636:17: MixedAssignment: Unable to determine the type that $class is being assigned to (see https://psalm.dev/032)
}
$preparedDefinition = ArrayDefinition::fromPreparedData(
$definition[ArrayDefinition::CLASS_NAME] ?? $class,

Check failure on line 639 in src/Container.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.0-ubuntu-latest

MixedArgument

src/Container.php:639:17: MixedArgument: Argument 1 of Yiisoft\Definitions\ArrayDefinition::fromPreparedData cannot be class-string|mixed, expecting class-string (see https://psalm.dev/030)

Check failure on line 639 in src/Container.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.0-ubuntu-latest

MixedArgument

src/Container.php:639:17: MixedArgument: Argument 1 of Yiisoft\Definitions\ArrayDefinition::fromPreparedData cannot be class-string|mixed, expecting class-string (see https://psalm.dev/030)

Check failure on line 639 in src/Container.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.1-ubuntu-latest

MixedArgument

src/Container.php:639:17: MixedArgument: Argument 1 of Yiisoft\Definitions\ArrayDefinition::fromPreparedData cannot be class-string|mixed, expecting class-string (see https://psalm.dev/030)
$definition[ArrayDefinition::CONSTRUCTOR],

Check failure on line 640 in src/Container.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.0-ubuntu-latest

MixedArgument

src/Container.php:640:17: MixedArgument: Argument 2 of Yiisoft\Definitions\ArrayDefinition::fromPreparedData cannot be mixed, expecting array<array-key, mixed> (see https://psalm.dev/030)

Check failure on line 640 in src/Container.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.0-ubuntu-latest

MixedArgument

src/Container.php:640:17: MixedArgument: Argument 2 of Yiisoft\Definitions\ArrayDefinition::fromPreparedData cannot be mixed, expecting array<array-key, mixed> (see https://psalm.dev/030)

Check failure on line 640 in src/Container.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.1-ubuntu-latest

MixedArgument

src/Container.php:640:17: MixedArgument: Argument 2 of Yiisoft\Definitions\ArrayDefinition::fromPreparedData cannot be mixed, expecting array<array-key, mixed> (see https://psalm.dev/030)
$definition['methodsAndProperties'],

Check failure on line 641 in src/Container.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.0-ubuntu-latest

MixedArgument

src/Container.php:641:17: MixedArgument: Argument 3 of Yiisoft\Definitions\ArrayDefinition::fromPreparedData cannot be mixed, expecting array<string, array{0: string, 1: string, 2: mixed}> (see https://psalm.dev/030)

Check failure on line 641 in src/Container.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.0-ubuntu-latest

MixedArgument

src/Container.php:641:17: MixedArgument: Argument 3 of Yiisoft\Definitions\ArrayDefinition::fromPreparedData cannot be mixed, expecting array<string, array{0: string, 1: string, 2: mixed}> (see https://psalm.dev/030)

Check failure on line 641 in src/Container.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.1-ubuntu-latest

MixedArgument

src/Container.php:641:17: MixedArgument: Argument 3 of Yiisoft\Definitions\ArrayDefinition::fromPreparedData cannot be mixed, expecting array<string, array{0: string, 1: string, 2: mixed}> (see https://psalm.dev/030)
);
} else {
$preparedDefinition = $definition;

Check failure on line 644 in src/Container.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.0-ubuntu-latest

MixedAssignment

src/Container.php:644:13: MixedAssignment: Unable to determine the type that $preparedDefinition is being assigned to (see https://psalm.dev/032)

Check failure on line 644 in src/Container.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.0-ubuntu-latest

MixedAssignment

src/Container.php:644:13: MixedAssignment: Unable to determine the type that $preparedDefinition is being assigned to (see https://psalm.dev/032)

Check failure on line 644 in src/Container.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.1-ubuntu-latest

MixedAssignment

src/Container.php:644:13: MixedAssignment: Unable to determine the type that $preparedDefinition is being assigned to (see https://psalm.dev/032)
}

if (empty($class)) {

Check failure on line 647 in src/Container.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.1-ubuntu-latest

RiskyTruthyFalsyComparison

src/Container.php:647:13: RiskyTruthyFalsyComparison: Operand of type class-string|mixed|null contains type mixed, which can be falsy and truthy. This can cause possibly unexpected behavior. Use strict comparison instead. (see https://psalm.dev/356)
throw new InvalidConfigException(
sprintf(
'Invalid definition: lazy services are only available with array definitions or references. Got type "%s" for definition ID: "%s"',
Expand All @@ -644,10 +654,6 @@ private function decorateLazy(string $id, mixed $definition): DefinitionInterfac
);
}

/**
* @var class-string $class
*/

return new LazyDefinition($definition, $class);
return new LazyDefinition($preparedDefinition, $class);

Check failure on line 657 in src/Container.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.0-ubuntu-latest

MixedArgument

src/Container.php:657:56: MixedArgument: Argument 2 of Yiisoft\Definitions\LazyDefinition::__construct cannot be class-string|non-empty-mixed, expecting class-string (see https://psalm.dev/030)

Check failure on line 657 in src/Container.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.0-ubuntu-latest

MixedArgument

src/Container.php:657:56: MixedArgument: Argument 2 of Yiisoft\Definitions\LazyDefinition::__construct cannot be class-string|non-empty-mixed, expecting class-string (see https://psalm.dev/030)

Check failure on line 657 in src/Container.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.1-ubuntu-latest

MixedArgument

src/Container.php:657:56: MixedArgument: Argument 2 of Yiisoft\Definitions\LazyDefinition::__construct cannot be class-string|non-empty-mixed, expecting class-string (see https://psalm.dev/030)
}
}

0 comments on commit 4afec90

Please sign in to comment.