-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #484 from phpDocumentor/feature/introduce-paramete…
…r-reducer Move parameter building to reducer
- Loading branch information
Showing
10 changed files
with
75 additions
and
261 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/phpDocumentor/Reflection/Php/Factory/Reducer/Parameter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace phpDocumentor\Reflection\Php\Factory\Reducer; | ||
|
||
use phpDocumentor\Reflection\Php\Argument as ArgumentDescriptor; | ||
use phpDocumentor\Reflection\Php\Factory\ContextStack; | ||
use phpDocumentor\Reflection\Php\Factory\Type; | ||
use phpDocumentor\Reflection\Php\Function_; | ||
use phpDocumentor\Reflection\Php\Method; | ||
use phpDocumentor\Reflection\Php\StrategyContainer; | ||
use PhpParser\Node\Expr\Variable; | ||
use PhpParser\Node\FunctionLike; | ||
use PhpParser\PrettyPrinter\Standard as PrettyPrinter; | ||
use Webmozart\Assert\Assert; | ||
|
||
use function is_string; | ||
|
||
class Parameter implements Reducer | ||
{ | ||
public function __construct(private readonly PrettyPrinter $valueConverter) | ||
{ | ||
} | ||
|
||
public function reduce( | ||
ContextStack $context, | ||
object $object, | ||
StrategyContainer $strategies, | ||
object|null $carry, | ||
): object|null { | ||
if ($object instanceof FunctionLike === false) { | ||
return $carry; | ||
} | ||
|
||
if ($carry instanceof Method === false && $carry instanceof Function_ === false) { | ||
return null; | ||
} | ||
|
||
foreach ($object->getParams() as $param) { | ||
Assert::isInstanceOf($param->var, Variable::class); | ||
|
||
$carry->addArgument( | ||
new ArgumentDescriptor( | ||
is_string($param->var->name) ? $param->var->name : $this->valueConverter->prettyPrintExpr($param->var->name), | ||
(new Type())->fromPhpParser($param->type), | ||
$param->default !== null ? $this->valueConverter->prettyPrintExpr($param->default) : null, | ||
$param->byRef, | ||
$param->variadic, | ||
), | ||
); | ||
} | ||
|
||
return $carry; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 0 additions & 77 deletions
77
tests/unit/phpDocumentor/Reflection/Php/Factory/ArgumentTest.php
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.