Skip to content

Commit

Permalink
Adding PHP-7 only version
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam-Burns committed Dec 8, 2015
1 parent a22e037 commit 847bdae
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 67 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
language: php

php:
- 5.5
- 5.6
- 7.0

sudo: true
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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"
},

Expand Down
10 changes: 2 additions & 8 deletions src/SamBurns/ConfigFileParser/ConfigFileParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,17 @@ 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();
}

/**
* @throws FileFormatNotParsable
*
* @param string $pathToFile
* @return ParsableFile
*/
private function getParsableFileFromPath($pathToFile)
private function getParsableFileFromPath(string $pathToFile): ParsableFile
{
$fileExtension = pathinfo($pathToFile)['extension'];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 1 addition & 5 deletions src/SamBurns/ConfigFileParser/Exception/FileNotReadable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 1 addition & 4 deletions src/SamBurns/ConfigFileParser/File/ParsableFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@

interface ParsableFile
{
/**
* @return array
*/
public function toArray();
public function toArray(): array;
}
11 changes: 2 additions & 9 deletions src/SamBurns/ConfigFileParser/File/ParsableFile/IniFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 2 additions & 9 deletions src/SamBurns/ConfigFileParser/File/ParsableFile/JsonFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 2 additions & 8 deletions src/SamBurns/ConfigFileParser/File/ParsableFile/PhpArrayFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
12 changes: 2 additions & 10 deletions src/SamBurns/ConfigFileParser/File/ParsableFile/YamlFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down

0 comments on commit 847bdae

Please sign in to comment.