diff --git a/.travis.yml b/.travis.yml index 454dd54..a1bb847 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,6 @@ language: php php: - - 5.5 - - 5.6 - 7.0 sudo: true diff --git a/composer.json b/composer.json index f392f0e..e7edc48 100644 --- a/composer.json +++ b/composer.json @@ -1,16 +1,17 @@ { "name": "samburns/config-file-parser", - "version": "1.0.0", + "version": "2.0.0", "license": "MIT", "require": { + "php": "^7.0.0", "symfony/yaml": ">=2.8.0 <4.0.0" }, "require-dev": { - "phpunit/phpunit": ">=4.8.0 <5.1.0", + "phpunit/phpunit": "~5.1.0", "satooshi/php-coveralls": "~0.1.0" }, diff --git a/src/SamBurns/ConfigFileParser/ConfigFileParser.php b/src/SamBurns/ConfigFileParser/ConfigFileParser.php index 6d9b418..eb40335 100644 --- a/src/SamBurns/ConfigFileParser/ConfigFileParser.php +++ b/src/SamBurns/ConfigFileParser/ConfigFileParser.php @@ -16,11 +16,8 @@ class ConfigFileParser /** * @throws FileFormatNotParsable * @throws FileNotReadable - * - * @param $pathToFile - * @return array */ - public function parseConfigFile($pathToFile) + public function parseConfigFile(string $pathToFile): array { $file = $this->getParsableFileFromPath($pathToFile); return $file->toArray(); @@ -28,11 +25,8 @@ public function parseConfigFile($pathToFile) /** * @throws FileFormatNotParsable - * - * @param string $pathToFile - * @return ParsableFile */ - private function getParsableFileFromPath($pathToFile) + private function getParsableFileFromPath(string $pathToFile): ParsableFile { $fileExtension = pathinfo($pathToFile)['extension']; diff --git a/src/SamBurns/ConfigFileParser/Exception/FileFormatNotParsable.php b/src/SamBurns/ConfigFileParser/Exception/FileFormatNotParsable.php index ddd6a76..f45fbbb 100644 --- a/src/SamBurns/ConfigFileParser/Exception/FileFormatNotParsable.php +++ b/src/SamBurns/ConfigFileParser/Exception/FileFormatNotParsable.php @@ -3,11 +3,7 @@ class FileFormatNotParsable extends \RuntimeException { - /** - * @param string $path - * @return FileFormatNotParsable - */ - public static function constructWithFilePath($path) + public static function constructWithFilePath(string $path): FileFormatNotParsable { $message = 'Config file "' . $path . '" is not of a format that can be parsed. Try .ini, .php, .json, or .yml.'; return new static($message); diff --git a/src/SamBurns/ConfigFileParser/Exception/FileNotReadable.php b/src/SamBurns/ConfigFileParser/Exception/FileNotReadable.php index eb58036..c5f8e60 100644 --- a/src/SamBurns/ConfigFileParser/Exception/FileNotReadable.php +++ b/src/SamBurns/ConfigFileParser/Exception/FileNotReadable.php @@ -3,11 +3,7 @@ class FileNotReadable extends \RuntimeException { - /** - * @param string $path - * @return FileNotReadable - */ - public static function constructWithPath($path) + public static function constructWithPath(string $path): FileNotReadable { $message = 'Config file "' . $path . '" could not be read'; return new static($message); diff --git a/src/SamBurns/ConfigFileParser/File/ParsableFile.php b/src/SamBurns/ConfigFileParser/File/ParsableFile.php index 4d07535..61fae7a 100644 --- a/src/SamBurns/ConfigFileParser/File/ParsableFile.php +++ b/src/SamBurns/ConfigFileParser/File/ParsableFile.php @@ -3,8 +3,5 @@ interface ParsableFile { - /** - * @return array - */ - public function toArray(); + public function toArray(): array; } diff --git a/src/SamBurns/ConfigFileParser/File/ParsableFile/IniFile.php b/src/SamBurns/ConfigFileParser/File/ParsableFile/IniFile.php index 1902f2f..6247478 100644 --- a/src/SamBurns/ConfigFileParser/File/ParsableFile/IniFile.php +++ b/src/SamBurns/ConfigFileParser/File/ParsableFile/IniFile.php @@ -12,20 +12,13 @@ class IniFile implements ParsableFile /** @var FileContentsRetriever */ private $fileContentsRetriever; - /** - * @param string $path - * @param FileContentsRetriever $fileContentsRetriever - */ - public function __construct($path, FileContentsRetriever $fileContentsRetriever) + public function __construct(string $path, FileContentsRetriever $fileContentsRetriever) { $this->path = $path; $this->fileContentsRetriever = $fileContentsRetriever; } - /** - * @return array - */ - public function toArray() + public function toArray(): array { $fileContents = $this->fileContentsRetriever->fileGetContents($this->path); return parse_ini_string($fileContents); diff --git a/src/SamBurns/ConfigFileParser/File/ParsableFile/JsonFile.php b/src/SamBurns/ConfigFileParser/File/ParsableFile/JsonFile.php index 0328435..8e4c108 100644 --- a/src/SamBurns/ConfigFileParser/File/ParsableFile/JsonFile.php +++ b/src/SamBurns/ConfigFileParser/File/ParsableFile/JsonFile.php @@ -12,20 +12,13 @@ class JsonFile implements ParsableFile /** @var FileContentsRetriever */ private $fileContentsRetriever; - /** - * @param string $path - * @param FileContentsRetriever $fileContentsRetriever - */ - public function __construct($path, FileContentsRetriever $fileContentsRetriever) + public function __construct(string $path, FileContentsRetriever $fileContentsRetriever) { $this->path = $path; $this->fileContentsRetriever = $fileContentsRetriever; } - /** - * @return array - */ - public function toArray() + public function toArray(): array { $fileContents = $this->fileContentsRetriever->fileGetContents($this->path); return json_decode($fileContents, true); diff --git a/src/SamBurns/ConfigFileParser/File/ParsableFile/PhpArrayFile.php b/src/SamBurns/ConfigFileParser/File/ParsableFile/PhpArrayFile.php index 0c0a5a7..b2cc4fb 100644 --- a/src/SamBurns/ConfigFileParser/File/ParsableFile/PhpArrayFile.php +++ b/src/SamBurns/ConfigFileParser/File/ParsableFile/PhpArrayFile.php @@ -8,18 +8,12 @@ class PhpArrayFile implements ParsableFile /** @var string */ private $path; - /** - * @param string $path - */ - public function __construct($path) + public function __construct(string $path) { $this->path = $path; } - /** - * @return array - */ - public function toArray() + public function toArray(): array { return require $this->path; } diff --git a/src/SamBurns/ConfigFileParser/File/ParsableFile/YamlFile.php b/src/SamBurns/ConfigFileParser/File/ParsableFile/YamlFile.php index 6ea6906..7cecef0 100644 --- a/src/SamBurns/ConfigFileParser/File/ParsableFile/YamlFile.php +++ b/src/SamBurns/ConfigFileParser/File/ParsableFile/YamlFile.php @@ -16,22 +16,14 @@ class YamlFile implements ParsableFile /** @var YamlParser */ private $yamlParser; - /** - * @param string $path - * @param FileContentsRetriever $fileContentsRetriever - * @param YamlParser $yamlParser - */ - public function __construct($path, FileContentsRetriever $fileContentsRetriever, YamlParser $yamlParser) + public function __construct(string $path, FileContentsRetriever $fileContentsRetriever, YamlParser $yamlParser) { $this->path = $path; $this->fileContentsRetriever = $fileContentsRetriever; $this->yamlParser = $yamlParser; } - /** - * @return array - */ - public function toArray() + public function toArray(): array { $fileContents = $this->fileContentsRetriever->fileGetContents($this->path); return $this->yamlParser->parse($fileContents); diff --git a/src/SamBurns/ConfigFileParser/FileReading/FileContentsRetriever.php b/src/SamBurns/ConfigFileParser/FileReading/FileContentsRetriever.php index 0047f9b..06e2b46 100644 --- a/src/SamBurns/ConfigFileParser/FileReading/FileContentsRetriever.php +++ b/src/SamBurns/ConfigFileParser/FileReading/FileContentsRetriever.php @@ -7,11 +7,8 @@ class FileContentsRetriever { /** * @throws FileNotReadable - * - * @param string $path - * @return string */ - public function fileGetContents($path) + public function fileGetContents(string $path): string { if (!is_readable($path)) { throw FileNotReadable::constructWithPath($path); diff --git a/tests/phpunit/SamBurns/ConfigFileParser/Test/ReadingVariousFileFormatTest.php b/tests/phpunit/SamBurns/ConfigFileParser/Test/ReadingVariousFileFormatTest.php index d5e3c16..9074971 100644 --- a/tests/phpunit/SamBurns/ConfigFileParser/Test/ReadingVariousFileFormatTest.php +++ b/tests/phpunit/SamBurns/ConfigFileParser/Test/ReadingVariousFileFormatTest.php @@ -25,7 +25,7 @@ public function testReadingFileContents($filename, $errorMessage) $this->assertEquals($expectedArray, $arrayReadFromFile, $errorMessage); } - public function provideFilenames() + public function provideFilenames(): array { return [ ['config.ini', 'Error parsing .ini config file'],