Skip to content

Commit

Permalink
Merge pull request #17 from Stillat/analysis-YOMKAj
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
JohnathonKoster authored Feb 1, 2023
2 parents 18e3cbd + 1091d61 commit 06edae5
Show file tree
Hide file tree
Showing 48 changed files with 631 additions and 590 deletions.
37 changes: 25 additions & 12 deletions src/Analyzers/ArrayAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@
use Illuminate\Support\Str;

/**
* Class ArrayAnalyzer
* Class ArrayAnalyzer.
*
* Analyzes an existing configuration file by loaded it into memory and inspecting its values.
*
* @package Stillat\Proteus\Analyzers
* @since 1.0.0
*/
class ArrayAnalyzer
{

/**
* Provides a mapping between configuration items and their "dot" depth.
*
Expand All @@ -27,6 +25,7 @@ class ArrayAnalyzer
* Provides a mapping between configuration keys and their associated Types.
*
* @see Types
*
* @var array
*/
protected $keyTypeMapping = [];
Expand Down Expand Up @@ -58,6 +57,7 @@ class ArrayAnalyzer
* This is simply a friendly wrapper around analyzeArrayDepth(), and sets up the initial state.
*
* @param array $value The value to analyze.
*
* @throws Exception
*/
public function analyze(array $value)
Expand All @@ -71,16 +71,17 @@ public function analyze(array $value)
/**
* Recursively discovers all keys and depth mappings in the value.
*
* @param array $value The values to check.
* @param int $lastDepth The last observed depth.
* @param string $lastKey The last observed key.
* @param array $value The values to check.
* @param int $lastDepth The last observed depth.
* @param string $lastKey The last observed key.
*
* @throws Exception
*/
public function analyzeArrayDepth(array $value, $lastDepth, $lastKey)
{
foreach ($value as $key => $v) {
if ($lastDepth > 0) {
$dotKey = $lastKey . '.' . $key;
$dotKey = $lastKey.'.'.$key;
} else {
$dotKey = $key;
}
Expand Down Expand Up @@ -114,6 +115,7 @@ public function analyzeArrayDepth(array $value, $lastDepth, $lastKey)
* Checks if a root node with the provided key exists.
*
* @param string $root The root to check.
*
* @return bool
*/
public function hasRoot($root)
Expand All @@ -128,6 +130,7 @@ public function hasRoot($root)
* test.nested - is compound
*
* @param string $key The key in dot notation.
*
* @return bool
*/
public function isCompound($key)
Expand All @@ -139,6 +142,7 @@ public function isCompound($key)
* Checks if the provided key can be augmented (is it an array node?).
*
* @param string $key The key to check.
*
* @return bool
*/
public function canBeAugmented($key)
Expand All @@ -156,6 +160,7 @@ public function canBeAugmented($key)
* Returns the number of existing nodes that match the provided key.
*
* @param string $key The key to check.
*
* @return int
*/
public function getDepthMatchCount($key)
Expand Down Expand Up @@ -225,6 +230,7 @@ public function getKeyValueMapping()
* Determines which keys in the input mapping must be updated vs. inserted.
*
* @param array $updates A mapping of the key/value pairs to update.
*
* @return MutationGraph
*/
public function getChanges($updates)
Expand All @@ -250,6 +256,7 @@ public function getChanges($updates)
* If this method returns `null`, you will be inserting off the root node.
*
* @param string $key The key to add, in dot notation.
*
* @return string|null
*/
public function getInsertionPoint($key)
Expand All @@ -264,6 +271,7 @@ public function getInsertionPoint($key)
* Constructs all possible array paths for the given key parts.
*
* @param string[] $keyParts The key parts.
*
* @return array
*/
public function constructPaths($keyParts)
Expand All @@ -274,7 +282,7 @@ public function constructPaths($keyParts)
$limit = count($keyParts) - 1;
for ($i = 0; $i < $limit; $i += 1) {
if ($i > 0) {
$lastKey .= '.' . $keyParts[$i];
$lastKey .= '.'.$keyParts[$i];
} else {
$lastKey = $keyParts[$i];
}
Expand All @@ -289,6 +297,7 @@ public function constructPaths($keyParts)
* Checks the existing level graph and finds the furthest existing node from root.
*
* @param string[] $paths The key paths to check.
*
* @return string|null
*/
public function getFurthestExistingDepth($paths)
Expand All @@ -308,6 +317,7 @@ public function getFurthestExistingDepth($paths)
* Returns all of the nested components of the provided key.
*
* @param string $key The string to analyze.
*
* @return string[]
*/
public function getCompound($key)
Expand All @@ -319,6 +329,7 @@ public function getCompound($key)
* Returns all of the nested components, without the root value, of the provided key.
*
* @param string $key The key to analyze.
*
* @return string[]
*/
public function getCompoundWithoutRoot($key)
Expand All @@ -332,15 +343,17 @@ public function getCompoundWithoutRoot($key)
* Constructs a compound structure with the provided value as the inner-most value.
*
* @param array $structure The existing structure array.
* @param mixed $value The value to place inside.
* @param mixed $value The value to place inside.
*
* @return array|array[]
*/
public function getCompoundStructure($structure, $value)
{
if (count($structure) === 1) {
$structureNode = array_shift($structure);

return [
$structureNode => $value
$structureNode => $value,
];
}

Expand All @@ -363,7 +376,7 @@ public function getCompoundStructure($structure, $value)

foreach ($structure as $struct) {
$last = [
$struct => $last
$struct => $last,
];
}

Expand All @@ -374,6 +387,7 @@ public function getCompoundStructure($structure, $value)
* Returns the 0-th compound element of the provided key.
*
* @param string $key The key to check.
*
* @return string
*/
public function getAbsoluteRoot($key)
Expand All @@ -382,5 +396,4 @@ public function getAbsoluteRoot($key)

return $parts[0];
}

}
Loading

0 comments on commit 06edae5

Please sign in to comment.