Skip to content

Commit

Permalink
Resolved merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike van Diepen committed Dec 9, 2019
2 parents d28ffc4 + 31d7719 commit 2e98d57
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 33 deletions.
2 changes: 1 addition & 1 deletion examples/ConfigurationExample.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
->directory('./config')
->config('config_file')
->get(Configuration::RETURN_TYPE_ARRAY);
/**
/*
* Possible return types:
* array: (Configuration::RETURN_TYPE_ARRAY)
* Json: (Configuration::RETURN_TYPE_JSON)
Expand Down
27 changes: 16 additions & 11 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace Mediadevs\Configuration;

use Mediadevs\Configuration\Exceptions\InvalidReturnTypeException;
use Mediadevs\Configuration\Traits\ReturnTypeTrait;
use Mediadevs\Configuration\Traits\FileCheckerTrait;
use Mediadevs\Configuration\Traits\DirectoryCheckerTrait;
use Mediadevs\Configuration\Exceptions\InvalidReturnTypeException;

class Configuration
{
Expand All @@ -14,25 +14,28 @@ class Configuration
use DirectoryCheckerTrait;

/**
* Return types for collecting the configuration data
* Return types for collecting the configuration data.
*/
public const RETURN_TYPE_JSON = 'json';
public const RETURN_TYPE_JSON = 'json';
public const RETURN_TYPE_ARRAY = 'array';

/**
* Path to the configuration directory
* Path to the configuration directory.
*
* @var string
*/
private $path;

/**
* The file name of the desired configuration file
* The file name of the desired configuration file.
*
* @var string
*/
private $file;

/**
* The path to the config directory
* The path to the config directory.
*
* @param string $path
*
* @return Configuration
Expand All @@ -45,7 +48,8 @@ public function directory(string $path): self
}

/**
* The name of the configuration file
* The name of the configuration file.
*
* @param string $file
*
* @return Configuration
Expand All @@ -58,22 +62,23 @@ public function config(string $file): self
}

/**
* Returning the contents of the configuration file
* Returning the contents of the configuration file.
*
* @param string $returnType
*
* @return array|string|void
* @throws InvalidReturnTypeException
* @throws Exceptions\ConfigurationFileException
* @throws Exceptions\ConfigurationDirectoryException
*
* @return array|string|void
*/
public function get(string $returnType = self::RETURN_TYPE_JSON): array
{
$configuration = $this->path . DIRECTORY_SEPARATOR . $this->file . '.php';
$configuration = $this->path.DIRECTORY_SEPARATOR.$this->file.'.php';

// Validating whether the configuration file and directory exists
if ($this->configurationDirectoryExists($this->path) && $this->configurationFileExists($configuration)) {
$collection = include($configuration);
$collection = include $configuration;

// Returning the configuration in the desired format
switch ($returnType) {
Expand Down
4 changes: 2 additions & 2 deletions src/Exceptions/ConfigurationDirectoryException.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ConfigurationDirectoryException extends Exception
*/
public function errorMessage(): string
{
return 'Invalid directory path! error thrown the file: ' . $this->getMessage() . ' does not exist.' . PHP_EOL
. 'Error thrown at line: ' . $this->getLine() . ' in file: ' . $this->getFile() . PHP_EOL;
return 'Invalid directory path! error thrown the file: '.$this->getMessage().' does not exist.'.PHP_EOL
.'Error thrown at line: '.$this->getLine().' in file: '.$this->getFile().PHP_EOL;
}
}
4 changes: 2 additions & 2 deletions src/Exceptions/ConfigurationFileException.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ConfigurationFileException extends Exception
*/
public function errorMessage(): string
{
return 'Invalid config file! Error thrown the file: ' . $this->getMessage() . ' does not exist.' . PHP_EOL
. 'Error thrown at line: ' . $this->getLine() . ' in file: ' . $this->getFile() . PHP_EOL;
return 'Invalid config file! Error thrown the file: '.$this->getMessage().' does not exist.'.PHP_EOL
.'Error thrown at line: '.$this->getLine().' in file: '.$this->getFile().PHP_EOL;
}
}
4 changes: 2 additions & 2 deletions src/Exceptions/InvalidReturnTypeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class InvalidReturnTypeException extends Exception
*/
public function errorMessage(): string
{
return 'Invalid return type! Error thrown the file: ' . $this->getMessage() . ' does not exist.' . PHP_EOL
. 'Error thrown at line: ' . $this->getLine() . ' in file: ' . $this->getFile() . PHP_EOL;
return 'Invalid return type! Error thrown the file: '.$this->getMessage().' does not exist.'.PHP_EOL
.'Error thrown at line: '.$this->getLine().' in file: '.$this->getFile().PHP_EOL;
}
}
6 changes: 4 additions & 2 deletions src/Traits/DirectoryCheckerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
trait DirectoryCheckerTrait
{
/**
* Whether the configuration directory exists
* Whether the configuration directory exists.
*
* @param string $path
*
* @return bool
* @throws ConfigurationDirectoryException
*
* @return bool
*/
public function configurationDirectoryExists(string $path): bool
{
Expand Down
6 changes: 4 additions & 2 deletions src/Traits/FileCheckerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
trait FileCheckerTrait
{
/**
* Whether the configuration file exists
* Whether the configuration file exists.
*
* @param string $file
*
* @return bool
* @throws ConfigurationFileException
*
* @return bool
*/
public function configurationFileExists(string $file): bool
{
Expand Down
6 changes: 4 additions & 2 deletions src/Traits/ReturnTypeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
trait ReturnTypeTrait
{
/**
* Return the data as JSON
* Return the data as JSON.
*
* @param array $data
*
* @return string
Expand All @@ -16,7 +17,8 @@ protected function returnJson(array $data): string
}

/**
* Return the data as an array
* Return the data as an array.
*
* @param array $data
*
* @return array
Expand Down
12 changes: 6 additions & 6 deletions tests/Unit/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace Mediadevs\Configuration\Tests;

use PHPUnit\Framework\TestCase;
use Mediadevs\Configuration\Configuration;
use Mediadevs\Configuration\Exceptions\ConfigurationDirectoryException;
use Mediadevs\Configuration\Exceptions\ConfigurationFileException;
use Mediadevs\Configuration\Exceptions\InvalidReturnTypeException;
use PHPUnit\Framework\TestCase;
use Mediadevs\Configuration\Exceptions\ConfigurationDirectoryException;

class ConfigurationTest extends TestCase
{
Expand Down Expand Up @@ -52,7 +52,7 @@ protected function setUp(): void
'September',
'October',
'November',
'December'
'December',
],
'Days' => [
'Monday',
Expand All @@ -61,14 +61,14 @@ protected function setUp(): void
'Thursday',
'Friday',
'Saturday',
'Sunday'
]
'Sunday',
],
];

// Loading the expectations.
$this->expectations = array(
'array' => $toArray,
'json' => json_encode($toArray)
'json' => json_encode($toArray),
);
}

Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/Fixtures/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
'September',
'October',
'November',
'December'
'December',
],
'Days' => [
'Monday',
Expand All @@ -22,6 +22,6 @@
'Thursday',
'Friday',
'Saturday',
'Sunday'
]
'Sunday',
],
];

0 comments on commit 2e98d57

Please sign in to comment.