From 254936f626384a9601607ec1470f6e3a2c279ff6 Mon Sep 17 00:00:00 2001 From: Alessandro Chitolina Date: Wed, 1 Nov 2017 22:37:38 +0100 Subject: [PATCH] add scalar type hints --- lib/ClassMetadata.php | 2 +- lib/ClassMetadataInterface.php | 2 +- lib/Factory/MetadataFactory.php | 4 ++-- lib/Loader/FileLoader.php | 4 ++-- lib/Loader/FileLoaderTrait.php | 2 +- lib/Loader/FilesLoader.php | 6 +++--- lib/Loader/Locator/FileLocatorInterface.php | 2 +- lib/Loader/Locator/FinderFileLocator.php | 2 +- lib/Loader/Locator/IteratorFileLocator.php | 2 +- lib/Loader/Processor/ProcessorFactory.php | 4 ++-- tests/Loader/FileLoaderTest.php | 2 +- tests/Loader/FilesLoaderTest.php | 4 ++-- 12 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/ClassMetadata.php b/lib/ClassMetadata.php index e138e3b..95016ea 100644 --- a/lib/ClassMetadata.php +++ b/lib/ClassMetadata.php @@ -78,7 +78,7 @@ public function merge(MetadataInterface $metadata): void /** * {@inheritdoc} */ - public function getAttributeMetadata($name): MetadataInterface + public function getAttributeMetadata(string $name): MetadataInterface { if (! isset($this->attributesMetadata[$name])) { return new NullMetadata($name); diff --git a/lib/ClassMetadataInterface.php b/lib/ClassMetadataInterface.php index 7606fde..d13dbb0 100644 --- a/lib/ClassMetadataInterface.php +++ b/lib/ClassMetadataInterface.php @@ -16,7 +16,7 @@ public function getReflectionClass(): \ReflectionClass; * * @return MetadataInterface */ - public function getAttributeMetadata($name): MetadataInterface; + public function getAttributeMetadata(string $name): MetadataInterface; /** * Returns all attributes' metadata. diff --git a/lib/Factory/MetadataFactory.php b/lib/Factory/MetadataFactory.php index 7020821..3a72c2f 100644 --- a/lib/Factory/MetadataFactory.php +++ b/lib/Factory/MetadataFactory.php @@ -20,9 +20,9 @@ class MetadataFactory extends AbstractMetadataFactory * * @param string $metadataClass */ - public function setMetadataClass($metadataClass): void + public function setMetadataClass(string $metadataClass): void { - if (! class_exists($metadataClass) || ! is_subclass_of($metadataClass, ClassMetadataInterface::class, true)) { + if (! class_exists($metadataClass) || ! (new \ReflectionClass($metadataClass))->implementsInterface(ClassMetadataInterface::class)) { throw InvalidArgumentException::create(InvalidArgumentException::INVALID_METADATA_CLASS, $metadataClass); } diff --git a/lib/Loader/FileLoader.php b/lib/Loader/FileLoader.php index 0344434..8f5743e 100644 --- a/lib/Loader/FileLoader.php +++ b/lib/Loader/FileLoader.php @@ -18,7 +18,7 @@ abstract class FileLoader implements LoaderInterface * * @param string $filePath */ - public function __construct($filePath) + public function __construct(string $filePath) { $this->filePath = $filePath; } @@ -41,5 +41,5 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata): bool * * @return bool */ - abstract protected function loadClassMetadataFromFile($file_content, ClassMetadataInterface $classMetadata): bool; + abstract protected function loadClassMetadataFromFile(string $file_content, ClassMetadataInterface $classMetadata): bool; } diff --git a/lib/Loader/FileLoaderTrait.php b/lib/Loader/FileLoaderTrait.php index 2988294..e896912 100644 --- a/lib/Loader/FileLoaderTrait.php +++ b/lib/Loader/FileLoaderTrait.php @@ -6,7 +6,7 @@ trait FileLoaderTrait { - private function loadFile($filePath): string + private function loadFile(string $filePath): string { $file_content = @file_get_contents($filePath); if (false === $file_content) { diff --git a/lib/Loader/FilesLoader.php b/lib/Loader/FilesLoader.php index f8cd2e9..bfece2c 100644 --- a/lib/Loader/FilesLoader.php +++ b/lib/Loader/FilesLoader.php @@ -14,7 +14,7 @@ class FilesLoader extends ChainLoader /** * {@inheritdoc} */ - public function __construct(array $paths, $loaderClass = null) + public function __construct(array $paths, string $loaderClass = null) { $this->loaderClass = $loaderClass; @@ -29,11 +29,11 @@ public function __construct(array $paths, $loaderClass = null) /** * Create an instance of LoaderInterface for the path. * - * @param $path + * @param string $path * * @return LoaderInterface */ - protected function getLoader($path): LoaderInterface + protected function getLoader(string $path): LoaderInterface { if (null === $this->loaderClass) { throw new RuntimeException('You must implement '.__METHOD__.' or pass the loader class to the constructor'); diff --git a/lib/Loader/Locator/FileLocatorInterface.php b/lib/Loader/Locator/FileLocatorInterface.php index cc167c8..c0c84ee 100644 --- a/lib/Loader/Locator/FileLocatorInterface.php +++ b/lib/Loader/Locator/FileLocatorInterface.php @@ -13,5 +13,5 @@ interface FileLocatorInterface * * @return string[] */ - public function locate($basePath, $extension): array; + public function locate(string $basePath, string $extension): array; } diff --git a/lib/Loader/Locator/FinderFileLocator.php b/lib/Loader/Locator/FinderFileLocator.php index c20e8ac..7b59c9b 100644 --- a/lib/Loader/Locator/FinderFileLocator.php +++ b/lib/Loader/Locator/FinderFileLocator.php @@ -10,7 +10,7 @@ class FinderFileLocator implements FileLocatorInterface /** * {@inheritdoc} */ - public function locate($basePath, $extension): array + public function locate(string $basePath, string $extension): array { if ('.' !== $extension[0]) { throw new \InvalidArgumentException('Extension argument must start with a dot'); diff --git a/lib/Loader/Locator/IteratorFileLocator.php b/lib/Loader/Locator/IteratorFileLocator.php index 17d211f..b62535f 100644 --- a/lib/Loader/Locator/IteratorFileLocator.php +++ b/lib/Loader/Locator/IteratorFileLocator.php @@ -7,7 +7,7 @@ class IteratorFileLocator implements FileLocatorInterface /** * {@inheritdoc} */ - public function locate($basePath, $extension): array + public function locate(string $basePath, string $extension): array { if ('.' !== $extension[0]) { throw new \InvalidArgumentException('Extension argument must start with a dot'); diff --git a/lib/Loader/Processor/ProcessorFactory.php b/lib/Loader/Processor/ProcessorFactory.php index 6eeca77..d60b0b6 100644 --- a/lib/Loader/Processor/ProcessorFactory.php +++ b/lib/Loader/Processor/ProcessorFactory.php @@ -22,9 +22,9 @@ class ProcessorFactory implements ProcessorFactoryInterface * @param string $class * @param string $processorClass */ - public function registerProcessor($class, $processorClass): void + public function registerProcessor(string $class, string $processorClass): void { - if (! is_subclass_of($processorClass, ProcessorInterface::class, true)) { + if (! (new \ReflectionClass($processorClass))->implementsInterface(ProcessorInterface::class)) { throw InvalidArgumentException::create(InvalidArgumentException::INVALID_PROCESSOR_INTERFACE_CLASS, $processorClass); } diff --git a/tests/Loader/FileLoaderTest.php b/tests/Loader/FileLoaderTest.php index cd4ed06..9b94019 100644 --- a/tests/Loader/FileLoaderTest.php +++ b/tests/Loader/FileLoaderTest.php @@ -11,7 +11,7 @@ class TestLoader extends FileLoader { - protected function loadClassMetadataFromFile($file_content, ClassMetadataInterface $classMetadata): bool + protected function loadClassMetadataFromFile(string $file_content, ClassMetadataInterface $classMetadata): bool { return true; } diff --git a/tests/Loader/FilesLoaderTest.php b/tests/Loader/FilesLoaderTest.php index 9fe57d8..8caedb6 100644 --- a/tests/Loader/FilesLoaderTest.php +++ b/tests/Loader/FilesLoaderTest.php @@ -20,7 +20,7 @@ public function __construct(array $paths, $loader) parent::__construct($paths); } - protected function getLoader($path): LoaderInterface + protected function getLoader(string $path): LoaderInterface { return $this->loader; } @@ -37,7 +37,7 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata): bool return true; } - protected function loadClassMetadataFromFile($file_content, ClassMetadataInterface $classMetadata): bool + protected function loadClassMetadataFromFile(string $file_content, ClassMetadataInterface $classMetadata): bool { return true; }