From 71baeef5355dae761ef4e7cd036fc230ede88223 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sun, 18 Feb 2024 23:12:32 +0100 Subject: [PATCH] add contract interface (#5) * add contract interface * misc --- .../AbstractClassPropertyExtension.php | 25 ++----------------- .../ClassModelsPropertyExtension.php | 6 ++--- .../ShellClassPropertyExtension.php | 6 ++--- .../PropertyNameExtensionInterface.php | 25 +++++++++++++++++++ tests/config/phpstan.neon | 1 - 5 files changed, 33 insertions(+), 30 deletions(-) create mode 100644 src/Contract/PropertyNameExtensionInterface.php diff --git a/src/ClassPropertyExtension/AbstractClassPropertyExtension.php b/src/ClassPropertyExtension/AbstractClassPropertyExtension.php index 1d0accc..d949a74 100644 --- a/src/ClassPropertyExtension/AbstractClassPropertyExtension.php +++ b/src/ClassPropertyExtension/AbstractClassPropertyExtension.php @@ -8,9 +8,10 @@ use PHPStan\Reflection\PropertiesClassReflectionExtension; use PHPStan\Reflection\PropertyReflection; use PHPStan\Reflection\ReflectionProvider; +use PHPStanCakePHP2\Contract\PropertyNameExtensionInterface; use PHPStanCakePHP2\Reflection\PublicReadOnlyPropertyReflection; -abstract class AbstractClassPropertyExtension implements PropertiesClassReflectionExtension +abstract class AbstractClassPropertyExtension implements PropertiesClassReflectionExtension, PropertyNameExtensionInterface { private ReflectionProvider $reflectionProvider; @@ -42,26 +43,4 @@ public function getProperty( return new PublicReadOnlyPropertyReflection($correctedPropertyName, $classReflection); } - - /** - * @todo use constract instead to separate - * Get the class name of the type of property. - */ - abstract protected function getPropertyParentClassName(): string; - - /** - * @todo use constract instead to separate - * Get the class names which can contain the property. - * - * @return array - */ - abstract protected function getContainingClassNames(): array; - - /** - * @todo use constract instead to separate - * Return the class name from the property name. - */ - abstract protected function getClassNameFromPropertyName( - string $propertyName - ): string; } diff --git a/src/ClassPropertyExtension/ClassModelsPropertyExtension.php b/src/ClassPropertyExtension/ClassModelsPropertyExtension.php index 5423f8e..e1990fa 100644 --- a/src/ClassPropertyExtension/ClassModelsPropertyExtension.php +++ b/src/ClassPropertyExtension/ClassModelsPropertyExtension.php @@ -9,7 +9,7 @@ */ final class ClassModelsPropertyExtension extends AbstractClassPropertyExtension { - protected function getPropertyParentClassName(): string + public function getPropertyParentClassName(): string { return 'Model'; } @@ -17,7 +17,7 @@ protected function getPropertyParentClassName(): string /** * @return array */ - protected function getContainingClassNames(): array + public function getContainingClassNames(): array { return [ 'Controller', @@ -26,7 +26,7 @@ protected function getContainingClassNames(): array ]; } - protected function getClassNameFromPropertyName( + public function getClassNameFromPropertyName( string $propertyName ): string { return $propertyName; diff --git a/src/ClassPropertyExtension/ShellClassPropertyExtension.php b/src/ClassPropertyExtension/ShellClassPropertyExtension.php index d567292..3ff7134 100644 --- a/src/ClassPropertyExtension/ShellClassPropertyExtension.php +++ b/src/ClassPropertyExtension/ShellClassPropertyExtension.php @@ -11,7 +11,7 @@ */ final class ShellClassPropertyExtension extends AbstractClassPropertyExtension { - protected function getPropertyParentClassName(): string + public function getPropertyParentClassName(): string { return 'Shell'; } @@ -19,12 +19,12 @@ protected function getPropertyParentClassName(): string /** * @return array */ - protected function getContainingClassNames(): array + public function getContainingClassNames(): array { return ['Shell']; } - protected function getClassNameFromPropertyName( + public function getClassNameFromPropertyName( string $propertyName ): string { return $propertyName . 'Task'; diff --git a/src/Contract/PropertyNameExtensionInterface.php b/src/Contract/PropertyNameExtensionInterface.php new file mode 100644 index 0000000..2f61eaa --- /dev/null +++ b/src/Contract/PropertyNameExtensionInterface.php @@ -0,0 +1,25 @@ +