Skip to content

Commit

Permalink
[TASK] Streamline Reflection usage
Browse files Browse the repository at this point in the history
  • Loading branch information
brotkrueml committed Oct 19, 2021
1 parent 47569d6 commit 02ec440
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
25 changes: 17 additions & 8 deletions Classes/Entity/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,28 @@ private static function processOptions(self $configuration, string $commaDelimit
* @param bool|int|string $value
*/
private static function setConfiguration(self $configuration, string $property, $value): void
{
$type = self::getTypeForProperty($property);
if ($type === 'string') {
$configuration->{$property} = (string)$value;
} elseif ($type === 'int') {
$configuration->{$property} = (int)$value;
} elseif ($type === 'bool') {
$configuration->{$property} = (bool)$value;
}
}

private static function getTypeForProperty(string $property): string
{
try {
// @phpstan-ignore-next-line
$type = (new \ReflectionProperty(self::class, $property))->getType()->getName();
if ($type === 'string') {
$configuration->{$property} = (string)$value;
} elseif ($type === 'int') {
$configuration->{$property} = (int)$value;
} elseif ($type === 'bool') {
$configuration->{$property} = (bool)$value;
$type = (new \ReflectionProperty(self::class, $property))->getType();
if ($type instanceof \ReflectionNamedType && $type->isBuiltin()) {
return $type->getName();
}
} catch (\ReflectionException $e) {
}

return '';
}

private static function normaliseUrl(string $url): string
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ services:
class: Symplify\PHPStanRules\CognitiveComplexity\Rules\ClassLikeCognitiveComplexityRule
tags: [phpstan.rules.rule]
arguments:
maxClassCognitiveComplexity: 11
maxClassCognitiveComplexity: 13
-
class: Symplify\PHPStanRules\Rules\ForbiddenFuncCallRule
tags: [phpstan.rules.rule]
Expand Down

0 comments on commit 02ec440

Please sign in to comment.