Skip to content

Commit

Permalink
add scalar type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
alekitto committed Nov 1, 2017
1 parent 43a00a4 commit 254936f
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion lib/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/ClassMetadataInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions lib/Factory/MetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Loader/FileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ abstract class FileLoader implements LoaderInterface
*
* @param string $filePath
*/
public function __construct($filePath)
public function __construct(string $filePath)
{
$this->filePath = $filePath;
}
Expand All @@ -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;
}
2 changes: 1 addition & 1 deletion lib/Loader/FileLoaderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions lib/Loader/FilesLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion lib/Loader/Locator/FileLocatorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ interface FileLocatorInterface
*
* @return string[]
*/
public function locate($basePath, $extension): array;
public function locate(string $basePath, string $extension): array;
}
2 changes: 1 addition & 1 deletion lib/Loader/Locator/FinderFileLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion lib/Loader/Locator/IteratorFileLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions lib/Loader/Processor/ProcessorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Loader/FileLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Loader/FilesLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 254936f

Please sign in to comment.