Skip to content

Commit

Permalink
Resolver: processing of functions like not() moved to PhpGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Oct 5, 2024
1 parent 965c203 commit 5152375
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
9 changes: 9 additions & 0 deletions src/DI/PhpGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,15 @@ public function formatStatement(Statement $statement): string
case is_string($entity) && str_contains($entity, '?'): // PHP literal
return $this->formatPhp($entity, $arguments);

case $entity === 'not':
return $this->formatPhp('!(?)', $arguments);

case $entity === 'bool':
case $entity === 'int':
case $entity === 'float':
case $entity === 'string':
return $this->formatPhp('?::?(?, ?)', [Helpers::class, 'convertType', $arguments[0], $entity]);

case is_string($entity): // create class
return $arguments
? $this->formatPhp("new $entity(...?:)", [$arguments])
Expand Down
10 changes: 0 additions & 10 deletions src/DI/Resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,23 +192,13 @@ public function completeStatement(Statement $statement, bool $currentServiceAllo
break;

case $entity === 'not':
if (count($arguments) !== 1) {
throw new ServiceCreationException(sprintf('Function %s() expects 1 parameter, %s given.', $entity, count($arguments)));
}

$entity = ['', '!'];
break;

case $entity === 'bool':
case $entity === 'int':
case $entity === 'float':
case $entity === 'string':
if (count($arguments) !== 1) {
throw new ServiceCreationException(sprintf('Function %s() expects 1 parameter, %s given.', $entity, count($arguments)));
}

$arguments = [$arguments[0], $entity];
$entity = [Helpers::class, 'convertType'];
break;

case is_string($entity): // create class
Expand Down

0 comments on commit 5152375

Please sign in to comment.