Skip to content

Commit

Permalink
Optimize find method
Browse files Browse the repository at this point in the history
  • Loading branch information
odan committed Apr 3, 2020
1 parent d0e2505 commit 103f51a
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/Configuration.php
Expand Up @@ -11,14 +11,14 @@
final class Configuration
{
/**
* @var array The data
* @var array<mixed> The data
*/
private $data;

/**
* Constructor.
*
* @param array $data Data
* @param array<mixed> $data Data
*/
public function __construct(array $data = [])
{
Expand Down Expand Up @@ -109,11 +109,11 @@ public function findString(string $key, string $default = null)
* Get value as array.
*
* @param string $key The key
* @param array|null $default The default value
* @param array<mixed>|null $default The default value
*
* @throws InvalidArgumentException
*
* @return array The value
* @return array<mixed> The value
*/
public function getArray(string $key, array $default = null): array
{
Expand All @@ -130,9 +130,9 @@ public function getArray(string $key, array $default = null): array
* Get value as array or null.
*
* @param string $key The key
* @param array $default The default value
* @param array<mixed> $default The default value
*
* @return array|null The value
* @return array<mixed>|null The value
*/
public function findArray(string $key, array $default = null)
{
Expand Down Expand Up @@ -283,6 +283,14 @@ public function findChronos(string $key, Chronos $default = null)
*/
public function find(string $path, $default = null)
{
if (array_key_exists($path, $this->data)) {
return $this->data[$path] ?? $default;
}

if (strpos($path, '.') === false) {
return $default;
}

$pathKeys = explode('.', $path);

$arrayCopyOrValue = $this->data;
Expand All @@ -300,7 +308,7 @@ public function find(string $path, $default = null)
/**
* Return all settings as array.
*
* @return array The data
* @return array<mixed> The data
*/
public function all(): array
{
Expand Down

0 comments on commit 103f51a

Please sign in to comment.