Skip to content
This repository has been archived by the owner on Apr 28, 2024. It is now read-only.

Commit

Permalink
4.3.1 Release
Browse files Browse the repository at this point in the history
  • Loading branch information
lcharette authored Nov 5, 2019
2 parents 7cb73e0 + 3da5925 commit 1dba247
Show file tree
Hide file tree
Showing 18 changed files with 168 additions and 29 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [4.3.1]
- Improved code quality & type hinting
- Fixed issue where an empty Yaml file would produce a null. Now returns an empty array
- `UserFrosting\Support\DotenvEditor\DotenvEditor::load` will throw an error if a `null` path is passed.
- Replaced deprecated code in `UserFrosting\Support\Repository\Repository`

## [4.3.0]
- Dropping support for PHP 5.6 & 7.0
- Updated Illuminate/Config to 5.8
Expand Down Expand Up @@ -34,6 +40,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
## 4.0.0
- Initial Release

[4.3.1]: https://github.com/userfrosting/support/compare/4.3.0...4.3.1
[4.3.0]: https://github.com/userfrosting/support/compare/4.2.1...4.3.0
[4.2.1]: https://github.com/userfrosting/support/compare/4.2.0...4.2.1
[4.2.0]: https://github.com/userfrosting/support/compare/4.1.3...4.2.0
Expand Down
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,10 @@
"psr-4": {
"UserFrosting\\Support\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"UserFrosting\\Support\\Tests\\": "tests"
}
}
}
11 changes: 9 additions & 2 deletions src/DotenvEditor/DotenvEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,19 @@ public function __construct($backupPath = '', $autoBackup = true)
/**
* Load file for working.
*
* @param string|null $filePath The file path
* @param string $filePath The file path
* @param bool $restoreIfNotFound Restore this file from other file if it's not found
* @param string|null $restorePath The file path you want to restore from
*
* @return DotenvEditor
*/
public function load($filePath = null, $restoreIfNotFound = false, $restorePath = null)
{
//Fail if path is null to maintain compatibility with Jackiedo\DotenvEditor
if (is_null($filePath)) {
throw new \InvalidArgumentException('File path cannot be null');
}

$this->resetContent();
$this->filePath = $filePath;

Expand All @@ -68,7 +73,9 @@ public function load($filePath = null, $restoreIfNotFound = false, $restorePath

return $this;
} elseif ($restoreIfNotFound) {
return $this->restore($restorePath);
$this->restore($restorePath);

return $this;
} else {
return $this;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Repository/Loader/ArrayFileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
class ArrayFileLoader extends FileRepositoryLoader
{
/**
* @return array
* {@inheritdoc}
*/
protected function parseFile($path)
protected function parseFile(string $path): array
{
return require $path;
}
Expand Down
26 changes: 13 additions & 13 deletions src/Repository/Loader/FileRepositoryLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
abstract class FileRepositoryLoader
{
/**
* @var array An array of paths to ultimately load the data from.
* @var string[] An array of paths to ultimately load the data from.
*/
protected $paths = [];

Expand All @@ -39,18 +39,18 @@ public function __construct($paths)
*
* @param string $path
*
* @return array
* @return mixed[]
*/
abstract protected function parseFile($path);
abstract protected function parseFile(string $path): array;

/**
* Fetch and recursively merge in content from all file paths.
*
* @param bool $skipMissing
*
* @return array
* @return string[]
*/
public function load($skipMissing = true)
public function load(bool $skipMissing = true): array
{
$result = [];

Expand All @@ -70,9 +70,9 @@ public function load($skipMissing = true)
*
* @throws FileNotFoundException
*
* @return array
* @return mixed[]
*/
public function loadFile($path, $skipMissing = true)
public function loadFile(string $path, $skipMissing = true): array
{
if (!file_exists($path)) {
if ($skipMissing) {
Expand All @@ -97,7 +97,7 @@ public function loadFile($path, $skipMissing = true)
*
* @return bool
*/
protected function isReadable($path)
protected function isReadable(string $path): bool
{
return is_readable($path);
}
Expand All @@ -107,7 +107,7 @@ protected function isReadable($path)
*
* @param string $path
*/
public function addPath($path)
public function addPath(string $path): self
{
$this->paths[] = rtrim($path, '/\\');

Expand All @@ -119,7 +119,7 @@ public function addPath($path)
*
* @param string $path
*/
public function prependPath($path)
public function prependPath($path): self
{
array_unshift($this->paths, rtrim($path, '/\\'));

Expand All @@ -131,7 +131,7 @@ public function prependPath($path)
*
* @param string|string[] $paths
*/
public function setPaths($paths)
public function setPaths($paths): self
{
if (!is_array($paths)) {
$paths = [$paths];
Expand All @@ -149,9 +149,9 @@ public function setPaths($paths)
/**
* Return a list of all file paths.
*
* @return array
* @return string[]
*/
public function getPaths()
public function getPaths(): array
{
return $this->paths;
}
Expand Down
11 changes: 8 additions & 3 deletions src/Repository/Loader/YamlFileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class YamlFileLoader extends FileRepositoryLoader
/**
* {@inheritdoc}
*/
protected function parseFile($path)
protected function parseFile(string $path): array
{
$doc = $this->fileGetContents($path);
if ($doc === false) {
Expand All @@ -42,6 +42,11 @@ protected function parseFile($path)
}
}

// In case `Yaml::parse` returns empty data/file
if (is_null($result)) {
return [];
}

return $result;
}

Expand All @@ -50,9 +55,9 @@ protected function parseFile($path)
*
* @param string $path
*
* @return string|bool
* @return string|false
*/
protected function fileGetContents($path)
protected function fileGetContents(string $path)
{
return file_get_contents($path);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Repository/PathBuilder/PathBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ abstract class PathBuilder
* @param ResourceLocatorInterface $locator
* @param string $uri
*/
public function __construct(ResourceLocatorInterface $locator, $uri)
public function __construct(ResourceLocatorInterface $locator, string $uri)
{
$this->locator = $locator;
$this->uri = $uri;
Expand All @@ -46,5 +46,5 @@ public function __construct(ResourceLocatorInterface $locator, $uri)
*
* @return array
*/
abstract public function buildPaths();
abstract public function buildPaths(): array;
}
4 changes: 3 additions & 1 deletion src/Repository/PathBuilder/SimpleGlobBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ class SimpleGlobBuilder extends PathBuilder
/**
* Glob together all file paths in each search path from the locator.
*
* @param string $extension (default 'php')
*
* @return array
*/
public function buildPaths($extension = 'php')
public function buildPaths(string $extension = 'php'): array
{
// Get all paths from the locator that match the uri.
// Put them in reverse order to allow later files to override earlier files.
Expand Down
2 changes: 1 addition & 1 deletion src/Repository/PathBuilder/StreamPathBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class StreamPathBuilder extends PathBuilder
*
* @return array
*/
public function buildPaths()
public function buildPaths(): array
{
// Get all paths from the locator that match the uri.
// Put them in reverse order to allow later files to override earlier files.
Expand Down
9 changes: 5 additions & 4 deletions src/Repository/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace UserFrosting\Support\Repository;

use Illuminate\Config\Repository as IlluminateRepository;
use Illuminate\Support\Arr;
use UserFrosting\Support\Util\Util;

/**
Expand All @@ -32,25 +33,25 @@ class Repository extends IlluminateRepository
* @param string|null $key
* @param mixed $items
*/
public function mergeItems($key, $items)
public function mergeItems(?string $key, $items): self
{
$targetValues = array_get($this->items, $key);
$targetValues = Arr::get($this->items, $key);

if (is_array($targetValues)) {
$modifiedValues = array_replace_recursive($targetValues, $items);
} else {
$modifiedValues = $items;
}

array_set($this->items, $key, $modifiedValues);
Arr::set($this->items, $key, $modifiedValues);

return $this;
}

/**
* Get the specified configuration value, recursively removing all null values.
*
* @param string $key
* @param string|array|null $key
*
* @return mixed
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Util/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public static function stripPrefix($str, $prefix = '')
*
* @param string|array $patterns
* @param string $subject
* @param array &$matches
* @param array $matches
* @param string $delimiter
* @param int $flags
* @param int $offset
Expand Down
12 changes: 12 additions & 0 deletions tests/DotenvEditor/DotenvEditorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* @license https://github.com/userfrosting/support/blob/master/LICENSE.md (MIT License)
*/

namespace UserFrosting\Support\Tests\DotenvEditor;

use PHPUnit\Framework\TestCase;
use UserFrosting\Support\DotenvEditor\DotenvEditor;

Expand Down Expand Up @@ -73,6 +75,16 @@ public function testLoadPathNotExist()
$this->assertEquals($editor, $result);
}

/**
* @depends testConstructor
*/
public function testLoadPathIsNull()
{
$editor = new DotenvEditor($this->basePath.'.env-backups/');
$this->expectException(\InvalidArgumentException::class);
$result = $editor->load();
}

/**
* @depends testConstructor
*/
Expand Down
2 changes: 2 additions & 0 deletions tests/Exception/HttpExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* @license https://github.com/userfrosting/support/blob/master/LICENSE.md (MIT License)
*/

namespace UserFrosting\Support\Tests\Exception;

use PHPUnit\Framework\TestCase;
use UserFrosting\Support\Exception\HttpException;
use UserFrosting\Support\Message\UserMessage;
Expand Down
2 changes: 2 additions & 0 deletions tests/Repository/PathBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* @license https://github.com/userfrosting/support/blob/master/LICENSE.md (MIT License)
*/

namespace UserFrosting\Support\Tests\Repository;

use PHPUnit\Framework\TestCase;
use UserFrosting\Support\Repository\PathBuilder\SimpleGlobBuilder;
use UserFrosting\Support\Repository\PathBuilder\StreamPathBuilder;
Expand Down
Loading

0 comments on commit 1dba247

Please sign in to comment.