Skip to content

Commit

Permalink
refactor: Method signature string
Browse files Browse the repository at this point in the history
  • Loading branch information
apple-x-co committed May 19, 2024
1 parent ede1515 commit cb68023
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/MethodSignatureString.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,7 @@ public function get(ReflectionMethod $method): string
$formattedArgs = [];

foreach ($argsList as $name => $value) {
if ($value instanceof UnitEnum) {
$formattedValue = '\\' . var_export($value, true);
$argRepresentation = is_numeric($name) ? $formattedValue : "{$name}: {$formattedValue}";
$formattedArgs[] = $argRepresentation;

continue;
}

$formattedValue = preg_replace('/\s+/', ' ', var_export($value, true));
$argRepresentation = is_numeric($name) ? $formattedValue : "{$name}: {$formattedValue}";
$formattedArgs[] = $argRepresentation;
$formattedArgs[] = $this->representArg($name, $value);
}

$signatureParts[] = sprintf(' #[\\%s(%s)]', $attribute->getName(), implode(', ', $formattedArgs)) . PHP_EOL;
Expand Down Expand Up @@ -98,6 +88,23 @@ public function get(ReflectionMethod $method): string
return implode(' ', $signatureParts);
}

/**
* @param string|int $name
* @param mixed $value
*/
private function representArg($name, $value): string
{
if ($value instanceof UnitEnum) {
$formattedValue = '\\' . var_export($value, true);

return is_numeric($name) ? $formattedValue : "{$name}: {$formattedValue}";
}

$formattedValue = preg_replace('/\s+/', ' ', var_export($value, true));

return is_numeric($name) ? $formattedValue : "{$name}: {$formattedValue}";

Check failure on line 105 in src/MethodSignatureString.php

View workflow job for this annotation

GitHub Actions / sa / PHPStan

Method Ray\Aop\MethodSignatureString::representArg() should return string but returns string|null.
}

public function generateParameterCode(ReflectionParameter $param): string
{
$typeStr = ($this->typeString)($param->getType());
Expand Down

0 comments on commit cb68023

Please sign in to comment.