diff --git a/src/Analyzers/ArrayAnalyzer.php b/src/Analyzers/ArrayAnalyzer.php index 0d7d520..c1cab03 100644 --- a/src/Analyzers/ArrayAnalyzer.php +++ b/src/Analyzers/ArrayAnalyzer.php @@ -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. * @@ -27,6 +25,7 @@ class ArrayAnalyzer * Provides a mapping between configuration keys and their associated Types. * * @see Types + * * @var array */ protected $keyTypeMapping = []; @@ -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) @@ -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; } @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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]; } @@ -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) @@ -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) @@ -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) @@ -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, ]; } @@ -363,7 +376,7 @@ public function getCompoundStructure($structure, $value) foreach ($structure as $struct) { $last = [ - $struct => $last + $struct => $last, ]; } @@ -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) @@ -382,5 +396,4 @@ public function getAbsoluteRoot($key) return $parts[0]; } - } diff --git a/src/Analyzers/ConfigAnalyzer.php b/src/Analyzers/ConfigAnalyzer.php index 688b5a7..1552d27 100644 --- a/src/Analyzers/ConfigAnalyzer.php +++ b/src/Analyzers/ConfigAnalyzer.php @@ -21,16 +21,14 @@ use Stillat\Proteus\Writers\StringWriter; /** - * Class ConfigAnalyzer + * Class ConfigAnalyzer. * * * - * @package Stillat\Proteus\Analyzers * @since 1.0.0 */ class ConfigAnalyzer { - /** * The loaded file path. * @@ -59,7 +57,6 @@ class ConfigAnalyzer */ private $lexer = null; - /** * The original statements, to help preserve formatting. * @@ -76,6 +73,7 @@ class ConfigAnalyzer /** * The old tokens, which contain the original formatting details. + * * @var array */ private $oldTokens = []; @@ -180,8 +178,8 @@ public function getValues() /** * Maps a known key to a resolved node. * - * @param string $key The key. - * @param Node $node The node. + * @param string $key The key. + * @param Node $node The node. */ public function mapNode($key, Node $node) { @@ -191,8 +189,8 @@ public function mapNode($key, Node $node) /** * Inserts a new value with the provided root key. * - * @param string $key The new value's key. - * @param Node $node The new value. + * @param string $key The new value's key. + * @param Node $node The new value. */ public function insertRootValue($key, Node $node) { @@ -202,8 +200,9 @@ public function insertRootValue($key, Node $node) /** * Wraps the provided value in an ArrayItem object. * - * @param string $key The desired key. - * @param Node $node The node value to wrap. + * @param string $key The desired key. + * @param Node $node The node value to wrap. + * * @return ArrayItem */ private function wrapInArrayItem($key, $node) @@ -222,8 +221,8 @@ private function wrapInArrayItem($key, $node) /** * Attempts to insert the provided values at the target key location. * - * @param string $key The key insertion point. - * @param mixed $values The values to insert. + * @param string $key The key insertion point. + * @param mixed $values The values to insert. */ public function insertValuesAtNode($key, $values) { @@ -248,6 +247,7 @@ public function insertValuesAtNode($key, $values) * Checks if a node with the provided key exists. * * @param string $key The desired key. + * * @return bool */ public function hasNode($key) @@ -258,9 +258,9 @@ public function hasNode($key) /** * Attempts to replace a value at a known location with the provided node value. * - * @param string $key The replacement location. - * @param Node $node The value to insert. - * @param bool $completeReplace Whether or not merging behavior is enabled. + * @param string $key The replacement location. + * @param Node $node The value to insert. + * @param bool $completeReplace Whether or not merging behavior is enabled. */ public function replaceNodeValue($key, Node $node, $completeReplace = false) { @@ -268,7 +268,6 @@ public function replaceNodeValue($key, Node $node, $completeReplace = false) if ($currentNode instanceof ArrayItem) { if ($currentNode->value instanceof Array_ && $node instanceof Array_) { - if ($completeReplace === false) { /** @var ArrayItem $mergeItem */ @@ -311,6 +310,7 @@ public function replaceNodeValue($key, Node $node, $completeReplace = false) } else { $currentNode->value = $node; } + return; } @@ -326,6 +326,7 @@ public function replaceNodeValue($key, Node $node, $completeReplace = false) if ($this->shouldProceedWithFunctionRewrite($key, $currentCheckValue)) { $this->functionHandler->handle($boolCastNode->expr, $currentNode, $node, $key); } + return; } elseif ($currentNode->value instanceof Node\Expr\Cast\String_) { $stringCastNode = $currentNode->value; @@ -333,6 +334,7 @@ public function replaceNodeValue($key, Node $node, $completeReplace = false) if ($this->shouldProceedWithFunctionRewrite($key, $currentCheckValue)) { $this->functionHandler->handle($stringCastNode->expr, $currentNode, $node, $key); } + return; } elseif ($currentNode->value instanceof Node\Expr\Cast\Int_) { $intCastNode = $currentNode->value; @@ -340,6 +342,7 @@ public function replaceNodeValue($key, Node $node, $completeReplace = false) if ($this->shouldProceedWithFunctionRewrite($key, $currentCheckValue)) { $this->functionHandler->handle($intCastNode->expr, $currentNode, $node, $key); } + return; } elseif ($currentNode->value instanceof Node\Expr\Cast\Double) { $doubleCastNode = $currentNode->value; @@ -347,11 +350,13 @@ public function replaceNodeValue($key, Node $node, $completeReplace = false) if ($this->shouldProceedWithFunctionRewrite($key, $currentCheckValue)) { $this->functionHandler->handle($doubleCastNode->expr, $currentNode, $node, $key); } + return; } elseif ($currentNode->value instanceof FuncCall) { if ($this->shouldProceedWithFunctionRewrite($key, $currentCheckValue)) { $this->functionHandler->handle($currentNode->value, $currentNode, $node, $key); } + return; } else { // Replace node value. @@ -363,8 +368,9 @@ public function replaceNodeValue($key, Node $node, $completeReplace = false) /** * Guards against resupplying an already configured value in env() calls. * - * @param string $key The configuration key. - * @param mixed $checkValue The check value. + * @param string $key The configuration key. + * @param mixed $checkValue The check value. + * * @return bool */ private function shouldProceedWithFunctionRewrite($key, $checkValue) @@ -390,6 +396,7 @@ private function shouldProceedWithFunctionRewrite($key, $checkValue) * Checks if a known node is an array. * * @param string $key The desired key. + * * @return bool */ public function isNodeArray($key) @@ -420,7 +427,9 @@ private function isFunctionLike($node) public function containsFunctionCall($key) { - if (!$this->hasNode($key) || !$this->nodeMapping[$key] instanceof ArrayItem) { return false; } + if (!$this->hasNode($key) || !$this->nodeMapping[$key] instanceof ArrayItem) { + return false; + } return $this->isFunctionLike($this->nodeMapping[$key]->value); } @@ -428,8 +437,8 @@ public function containsFunctionCall($key) /** * Appends a value to an existing array at a known location. * - * @param string $key The target location. - * @param Node $node The value to append. + * @param string $key The target location. + * @param Node $node The value to append. */ public function appendArrayItem($key, Node $node) { @@ -446,8 +455,8 @@ public function appendArrayItem($key, Node $node) /** * Replaces a node's value with the provided new value. * - * @param string $key The key. - * @param mixed $newValue The value to insert. + * @param string $key The key. + * @param mixed $newValue The value to insert. */ public function replaceNode($key, $newValue) { @@ -461,11 +470,11 @@ public function replaceNode($key, $newValue) /** * Replaces a node's key and value, and overrides an existing docblock. * - * @param string $key The original key. - * @param string $newKey The new key. - * @param mixed $newValue The value to insert. - * @param string $docBlock The Laravel "block" comment. - * @param bool $forceNewLine Whether or not to force a new line. + * @param string $key The original key. + * @param string $newKey The new key. + * @param mixed $newValue The value to insert. + * @param string $docBlock The Laravel "block" comment. + * @param bool $forceNewLine Whether or not to force a new line. */ public function replaceNodeWithDocBlock($key, $newKey, $newValue, $docBlock, $forceNewLine = true) { @@ -502,9 +511,7 @@ public function replaceNodeWithDocBlock($key, $newKey, $newValue, $docBlock, $fo $currentNode->setAttribute('comments', $comments); } } - } - } } @@ -512,6 +519,7 @@ public function replaceNodeWithDocBlock($key, $newKey, $newValue, $docBlock, $fo * Removes the key and its associated value from the configuration. * * @param string $key The key to remove. + * * @return bool */ public function removeNode($key) @@ -651,7 +659,7 @@ public function getSourceNodeKeys() public function dumpConfig() { $printer = new Printer([ - 'shortArraySyntax' => true + 'shortArraySyntax' => true, ]); return $printer->printFormatPreserving($this->newStmts, $this->oldStmts, $this->oldTokens); @@ -667,7 +675,9 @@ public function dumpConfig() * 'newkey' => ['value1', 'value2'] * * @param Array_ $node The node to check. + * * @return Array_ + * * @deprecated */ private function checkForNestedUselessArrays(Array_ $node) @@ -708,5 +718,4 @@ private function checkForNestedUselessArrays(Array_ $node) return $node; } - } diff --git a/src/Analyzers/FunctionHandler.php b/src/Analyzers/FunctionHandler.php index b9aa7f5..74ce8f5 100644 --- a/src/Analyzers/FunctionHandler.php +++ b/src/Analyzers/FunctionHandler.php @@ -7,15 +7,12 @@ use Stillat\Proteus\Contracts\FunctionHandlerContract; /** - * Class FunctionHandler + * Class FunctionHandler. * * Provides a centralized location to analyze and handle a variety of function calls. - * - * @package Stillat\Proteus\Analyzers */ class FunctionHandler { - /** * @var FunctionHandlerContract[] */ @@ -24,7 +21,7 @@ class FunctionHandler /** * Registers a new function handler. * - * @param string $name The function name. + * @param string $name The function name. * @param FunctionHandlerContract $handler The handler. */ public function addHandler($name, FunctionHandlerContract $handler) @@ -35,10 +32,11 @@ public function addHandler($name, FunctionHandlerContract $handler) /** * Analyzes the source expression and applies any required function mutations. * - * @param Expr $expr The source expression. - * @param mixed $currentNode The current node. - * @param mixed $referenceNode The reference node. - * @param string $referenceKey The reference key. + * @param Expr $expr The source expression. + * @param mixed $currentNode The current node. + * @param mixed $referenceNode The reference node. + * @param string $referenceKey The reference key. + * * @return mixed */ public function handle(Expr $expr, $currentNode, $referenceNode, string $referenceKey) @@ -58,6 +56,7 @@ public function handle(Expr $expr, $currentNode, $referenceNode, string $referen * Attempts to retrieve the function call's name. * * @param Expr $expr The expression. + * * @return string|null */ private function getFunctionName(Expr $expr) @@ -68,5 +67,4 @@ private function getFunctionName(Expr $expr) return null; } - } diff --git a/src/Analyzers/FunctionHandlers/LaravelEnv.php b/src/Analyzers/FunctionHandlers/LaravelEnv.php index 89fd843..8473dee 100644 --- a/src/Analyzers/FunctionHandlers/LaravelEnv.php +++ b/src/Analyzers/FunctionHandlers/LaravelEnv.php @@ -2,27 +2,25 @@ namespace Stillat\Proteus\Analyzers\FunctionHandlers; +use PhpParser\Node\Arg; use PhpParser\Node\Expr\FuncCall; use Stillat\Proteus\Contracts\FunctionHandlerContract; -use PhpParser\Node\Arg; /** - * Class LaravelEnv + * Class LaravelEnv. * * Provides support for rewriting Laravel env() helper function calls. - * - * @package Stillat\Proteus\Analyzers\FunctionHandlers */ class LaravelEnv implements FunctionHandlerContract { - /** * Analyzes the source expression and applies any required function mutations. * - * @param FuncCall $expr The source expression. - * @param mixed $currentNode The current node. - * @param mixed $referenceNode The reference node. - * @param string $referenceKey The reference key. + * @param FuncCall $expr The source expression. + * @param mixed $currentNode The current node. + * @param mixed $referenceNode The reference node. + * @param string $referenceKey The reference key. + * * @return mixed */ public function handle(FuncCall $expr, $currentNode, $referenceNode, string $referenceKey) @@ -40,5 +38,4 @@ public function handle(FuncCall $expr, $currentNode, $referenceNode, string $ref return $expr; } - } diff --git a/src/Analyzers/FunctionHandlers/SimpleFunctionHandler.php b/src/Analyzers/FunctionHandlers/SimpleFunctionHandler.php index 548e897..b487831 100644 --- a/src/Analyzers/FunctionHandlers/SimpleFunctionHandler.php +++ b/src/Analyzers/FunctionHandlers/SimpleFunctionHandler.php @@ -7,22 +7,20 @@ use Stillat\Proteus\Contracts\FunctionHandlerContract; /** - * Class LaravelResourcePath + * Class LaravelResourcePath. * * Provides support for the simple named functions accepting one or zero parameters. - * - * @package Stillat\Proteus\Analyzers\FunctionHandlers */ class SimpleFunctionHandler implements FunctionHandlerContract { - /** * Analyzes the source expression and applies any required function mutations. * - * @param FuncCall $expr The source expression. - * @param mixed $currentNode The current node. - * @param mixed $referenceNode The reference node. - * @param string $referenceKey The reference key. + * @param FuncCall $expr The source expression. + * @param mixed $currentNode The current node. + * @param mixed $referenceNode The reference node. + * @param string $referenceKey The reference key. + * * @return mixed */ public function handle(FuncCall $expr, $currentNode, $referenceNode, string $referenceKey) @@ -45,5 +43,4 @@ public function handle(FuncCall $expr, $currentNode, $referenceNode, string $ref return $expr; } - } diff --git a/src/Analyzers/MutationGraph.php b/src/Analyzers/MutationGraph.php index 463ef58..d66a785 100644 --- a/src/Analyzers/MutationGraph.php +++ b/src/Analyzers/MutationGraph.php @@ -3,16 +3,14 @@ namespace Stillat\Proteus\Analyzers; /** - * Class MutationGraph + * Class MutationGraph. * * Represents a collection of mutations to apply to a configuration document. * - * @package Stillat\Proteus\Analyzers * @since 1.0.0 */ class MutationGraph { - /** * The probable insertions. * @@ -26,5 +24,4 @@ class MutationGraph * @var array */ public $updates = []; - } diff --git a/src/Analyzers/RecursiveKeyAnalyzer.php b/src/Analyzers/RecursiveKeyAnalyzer.php index f14fd0b..a033b0d 100644 --- a/src/Analyzers/RecursiveKeyAnalyzer.php +++ b/src/Analyzers/RecursiveKeyAnalyzer.php @@ -3,20 +3,18 @@ namespace Stillat\Proteus\Analyzers; /** - * Class RecursiveKeyAnalyzer + * Class RecursiveKeyAnalyzer. * * Provides utilities for recursively retrieving key information from arrays. - * - * @package Stillat\Proteus\Analyzers */ class RecursiveKeyAnalyzer { - /** * Returns all nested keys in dot notation for the provided array. * - * @param array $values The key/value pairs to check. + * @param array $values The key/value pairs to check. * @param string $startKey The root key. + * * @return array */ public static function getDotKeysRecursively(array $values, $startKey) @@ -34,5 +32,4 @@ public static function getDotKeysRecursively(array $values, $startKey) return $keys; } - } diff --git a/src/Analyzers/TypeAnalyzer.php b/src/Analyzers/TypeAnalyzer.php index 01a3d19..7299e2a 100644 --- a/src/Analyzers/TypeAnalyzer.php +++ b/src/Analyzers/TypeAnalyzer.php @@ -5,20 +5,19 @@ use Exception; /** - * Class TypeAnalyzer + * Class TypeAnalyzer. * * Provides utilities to analyze runtime value's types. * - * @package Stillat\Proteus\Analyzers * @since 1.0.0 */ class TypeAnalyzer { - /** * Converts the type mapping to a known string representation. * * @param int $type The type. + * * @return string */ public static function typeToString($type) @@ -42,8 +41,10 @@ public static function typeToString($type) * Infers the type from the provided value. * * @param mixed $value The value to analyze. - * @return int + * * @throws Exception + * + * @return int */ public static function typeOf($value) { @@ -63,7 +64,6 @@ public static function typeOf($value) return Types::TYPE_BOOL; } - throw new Exception("Support type: " . gettype($value)); + throw new Exception('Support type: '.gettype($value)); } - } diff --git a/src/Analyzers/Types.php b/src/Analyzers/Types.php index f13d61a..1012e9f 100644 --- a/src/Analyzers/Types.php +++ b/src/Analyzers/Types.php @@ -3,21 +3,18 @@ namespace Stillat\Proteus\Analyzers; /** - * Class Types + * Class Types. * * Provides a known mapping of runtime value types. * - * @package Stillat\Proteus\Analyzers * @since 1.0.0 */ class Types { - const TYPE_DOUBLE = 0; const TYPE_INT = 1; const TYPE_STRING = 2; const TYPE_ARRAY = 3; const TYPE_SPECIAL_NULL = 4; const TYPE_BOOL = 5; - } diff --git a/src/ConfigUpdateWrapper.php b/src/ConfigUpdateWrapper.php index 4e0f546..a341266 100644 --- a/src/ConfigUpdateWrapper.php +++ b/src/ConfigUpdateWrapper.php @@ -3,12 +3,10 @@ namespace Stillat\Proteus; /** - * Class ConfigUpdateWrapper + * Class ConfigUpdateWrapper. * * Provides a snytax-friendly wrapper around common mutations, allowing * for greater control of fine-grained configuration management/updates. - * - * @package Stillat\Proteus */ class ConfigUpdateWrapper { @@ -54,8 +52,9 @@ class ConfigUpdateWrapper /** * ConfigUpdaterWrapper constructor. - * @param LaravelConfigWriter $writer The writer instance. - * @param string $namespace The configuration namespace. + * + * @param LaravelConfigWriter $writer The writer instance. + * @param string $namespace The configuration namespace. */ public function __construct(LaravelConfigWriter $writer, $namespace) { @@ -67,6 +66,7 @@ public function __construct(LaravelConfigWriter $writer, $namespace) * Constructs an absolute namespaced configuration key. * * @param string $relativeKey The relative key. + * * @return string */ private function makeAbsolute($relativeKey) @@ -77,8 +77,9 @@ private function makeAbsolute($relativeKey) /** * Merges the provided values with the existing configuration values. * - * @param string $key The configuration usage. - * @param array $value The values to add. + * @param string $key The configuration usage. + * @param array $value The values to add. + * * @return $this */ public function merge($key, $value) @@ -92,8 +93,9 @@ public function merge($key, $value) /** * Replaces the existing value at the configuration key's location. * - * @param string $key The configuration key. - * @param mixed $value The new value. + * @param string $key The configuration key. + * @param mixed $value The new value. + * * @return $this */ public function replace($key, $value) @@ -102,10 +104,10 @@ public function replace($key, $value) $this->mutations[] = [ self::KEY_MUTATION => self::MUTATION_REPLACE, - self::KEY_VALUE => [ - self::KEY_KEY => $key, - self::KEY_VALUE => $value - ] + self::KEY_VALUE => [ + self::KEY_KEY => $key, + self::KEY_VALUE => $value, + ], ]; return $this; @@ -114,11 +116,12 @@ public function replace($key, $value) /** * Replaces an existing node structure. * - * @param string $key The original key. - * @param string $newKey The new key. - * @param mixed $value The value to insert. - * @param string $docBlock The Laravel "block" comment. - * @param bool $forceNewLine Whether or not to force a new line. + * @param string $key The original key. + * @param string $newKey The new key. + * @param mixed $value The value to insert. + * @param string $docBlock The Laravel "block" comment. + * @param bool $forceNewLine Whether or not to force a new line. + * * @return $this */ public function replaceStructure($key, $newKey, $value, $docBlock, $forceNewLine = true) @@ -126,12 +129,12 @@ public function replaceStructure($key, $newKey, $value, $docBlock, $forceNewLine $this->knownKeys[] = $this->makeAbsolute($key); $this->mutations[] = [ - self::KEY_MUTATION => self::MUTATION_REPLACE_STRUCTURE, - self::KEY_KEY => $key, - self::KEY_NEW_KEY => $newKey, - self::KEY_VALUE => $value, - self::KEY_COMMENT => $docBlock, - self::KEY_FORCE_NEWLINE => $forceNewLine + self::KEY_MUTATION => self::MUTATION_REPLACE_STRUCTURE, + self::KEY_KEY => $key, + self::KEY_NEW_KEY => $newKey, + self::KEY_VALUE => $value, + self::KEY_COMMENT => $docBlock, + self::KEY_FORCE_NEWLINE => $forceNewLine, ]; return $this; @@ -141,6 +144,7 @@ public function replaceStructure($key, $newKey, $value, $docBlock, $forceNewLine * Removes the value at the configuration key's location, and removes the key. * * @param string $key The configuration key. + * * @return $this */ public function remove($key) @@ -149,7 +153,7 @@ public function remove($key) $this->mutations[] = [ self::KEY_MUTATION => self::MUTATION_REMOVE, - self::KEY_VALUE => $key + self::KEY_VALUE => $key, ]; return $this; @@ -158,8 +162,9 @@ public function remove($key) /** * Updates the value at the configuration key's location. * - * @param string $key The configuration key. - * @param mixed $value The new value. + * @param string $key The configuration key. + * @param mixed $value The new value. + * * @return $this */ public function change($key, $value) @@ -168,9 +173,9 @@ public function change($key, $value) $this->mutations[] = [ self::KEY_MUTATION => self::MUTATION_UPDATE, - self::KEY_VALUE => [ - $key => $value - ] + self::KEY_VALUE => [ + $key => $value, + ], ]; return $this; @@ -179,8 +184,9 @@ public function change($key, $value) /** * Updates a single entry, or multiple if a key/value pair supplied as the key, and no value is set. * - * @param array|string $key The configuration key, or a key/value list of multiple changes. - * @param mixed|null $value The new value. + * @param array|string $key The configuration key, or a key/value list of multiple changes. + * @param mixed|null $value The new value. + * * @return $this */ public function set($key, $value = null) @@ -199,10 +205,11 @@ public function set($key, $value = null) /** * Attempts to persist the configuration changes to disk. * - * @return bool * @throws Exceptions\ConfigNotFoundException * @throws Exceptions\ConfigNotWriteableException * @throws Exceptions\GuardedConfigurationMutationException + * + * @return bool */ public function save() { @@ -227,10 +234,11 @@ public function save() /** * Applies all queued changes and returns the modified configuration document. * - * @return string * @throws Exceptions\ConfigNotFoundException * @throws Exceptions\ConfigNotWriteableException * @throws Exceptions\GuardedConfigurationMutationException + * + * @return string */ public function preview() { @@ -267,12 +275,12 @@ public function preview() } /** - * @param ConfigUpdater $updater The updater instance. - * @param string $key The original key. - * @param string $newKey The new key. - * @param mixed $value The value to insert. - * @param string $docBlock The Laravel "block" comment. - * @param bool $forceNewLine Whether or not to force a new line. + * @param ConfigUpdater $updater The updater instance. + * @param string $key The original key. + * @param string $newKey The new key. + * @param mixed $value The value to insert. + * @param string $docBlock The Laravel "block" comment. + * @param bool $forceNewLine Whether or not to force a new line. */ private function doReplaceStructure($updater, $key, $newKey, $value, $docBlock, $forceNewLine = true) { @@ -280,9 +288,9 @@ private function doReplaceStructure($updater, $key, $newKey, $value, $docBlock, } /** - * @param ConfigUpdater $updater The updater instance. - * @param string $key The key to update. - * @param mixed $newValue The value to insert. + * @param ConfigUpdater $updater The updater instance. + * @param string $key The key to update. + * @param mixed $newValue The value to insert. */ private function doReplace($updater, $key, $newValue) { @@ -291,7 +299,7 @@ private function doReplace($updater, $key, $newValue) /** * @param ConfigUpdater $updater The updater instance. - * @param string $key The key to remove. + * @param string $key The key to remove. */ private function doRemove($updater, $key) { @@ -300,11 +308,10 @@ private function doRemove($updater, $key) /** * @param ConfigUpdater $updater The updater instance. - * @param array $update The key/value pair to update. + * @param array $update The key/value pair to update. */ private function doUpdate($updater, $update) { $updater->update($update); } - } diff --git a/src/ConfigUpdater.php b/src/ConfigUpdater.php index 629b1e7..c6cc9b1 100644 --- a/src/ConfigUpdater.php +++ b/src/ConfigUpdater.php @@ -11,18 +11,16 @@ use Stillat\Proteus\Writers\TypeWriter; /** - * Class ConfigUpdater + * Class ConfigUpdater. * * Provides utilities and features to update Laravel-style configuration files. * * This class is a wrapper around the ConfigAnalyzer and the ArrayAnalyzer. * - * @package Stillat\Proteus * @since 1.0.0 */ class ConfigUpdater { - /** * The ConfigAnalyzer instance. * @@ -53,6 +51,7 @@ class ConfigUpdater /** * A list of configuration keys that should be preserved. + * * @var array */ private $preserveKeys = []; @@ -68,6 +67,7 @@ public function __construct() * Sets whether function calls are ignored when updating the configuration. * * @param bool $ignore + * * @return $this */ public function setIgnoreFunctions($ignore) @@ -83,6 +83,7 @@ public function setIgnoreFunctions($ignore) * Sets a list of configuration keys that should always be preserved. * * @param array $keys + * * @return $this */ public function setPreserveKeys($keys) @@ -95,8 +96,9 @@ public function setPreserveKeys($keys) /** * Flattens deeply nested arrays using "dot" notation, while preserving root keys. * - * @param array $array + * @param array $array * @param string $prefix + * * @return array */ private function flattenKeys($array, $prefix = '') @@ -123,6 +125,7 @@ private function flattenKeys($array, $prefix = '') * Attempts to remove the key and its value from the configuration. * * @param string $key The key to remove. + * * @return bool */ public function remove($key) @@ -149,6 +152,7 @@ public function config() * Opens the provided file and parses the configuration values. * * @param string $filePath The file to open. + * * @throws Exception * @throws ConfigNotFoundException */ @@ -168,8 +172,9 @@ public function open($filePath) /** * Replaces a node's value with the provided new value. * - * @param string $key The key to update. - * @param mixed $value The value to replace. + * @param string $key The key to update. + * @param mixed $value The value to replace. + * * @throws Exception */ public function replace($key, $value) @@ -182,11 +187,12 @@ public function replace($key, $value) /** * Replaces an existing node structure. * - * @param string $key The original key. - * @param string $newKey The new key. - * @param mixed $value The value to insert. - * @param string $docBlock The Laravel "block" comment. - * @param bool $forceNewLine Whether or not to force a new line. + * @param string $key The original key. + * @param string $newKey The new key. + * @param mixed $value The value to insert. + * @param string $docBlock The Laravel "block" comment. + * @param bool $forceNewLine Whether or not to force a new line. + * * @throws Exception */ public function replaceStructure($key, $newKey, $value, $docBlock, $forceNewLine = true) @@ -200,7 +206,8 @@ public function replaceStructure($key, $newKey, $value, $docBlock, $forceNewLine * Attempts to apply the requested changes to the existing configuration values. * * @param array $changes The changes to apply to the existing configuration. - * @param bool $isMerge Indicates if merge or forced overwrite behavior should be used. + * @param bool $isMerge Indicates if merge or forced overwrite behavior should be used. + * * @throws Exception */ public function update(array $changes, $isMerge = false) @@ -211,7 +218,7 @@ public function update(array $changes, $isMerge = false) $isMerge = true; } - if (! empty($this->preserveKeys)) { + if (!empty($this->preserveKeys)) { $currentConfig = $this->analyzer->getValues(); foreach ($this->preserveKeys as $keyToPreserve) { @@ -237,7 +244,6 @@ public function update(array $changes, $isMerge = false) $this->analyzer->replaceNodeValue($insert, $valuesToInsert, $completeReplace); } else { - if ($this->arrayAnalyzer->isCompound($insert)) { $insertionPoint = $this->arrayAnalyzer->getInsertionPoint($insert); @@ -259,6 +265,7 @@ public function update(array $changes, $isMerge = false) $this->analyzer->replaceNodeValue($insertionPoint, $valuesToInsert); } + return; } else { $this->analyzer->insertValuesAtNode($insert, $valuesToInsert); @@ -270,7 +277,6 @@ public function update(array $changes, $isMerge = false) $constructedValue = TypeWriter::write($changes[$update]); if ($this->analyzer->hasNode($update)) { - if ($this->analyzer->isNodeArray($update) && is_array($changes[$update]) === false) { $this->analyzer->appendArrayItem($update, $constructedValue); } else { @@ -301,12 +307,10 @@ public function update(array $changes, $isMerge = false) $this->analyzer->insertRootValue($update, $constructedValue); } } else { - if ($this->arrayAnalyzer->isCompound($update)) { $components = $this->arrayAnalyzer->getCompoundWithoutRoot($update); $compoundStruct = $this->arrayAnalyzer->getCompoundStructure($components, $changes[$update]); - $constructedValue = TypeWriter::write($compoundStruct); $this->analyzer->insertRootValue($rootReplacement, $constructedValue); @@ -327,5 +331,4 @@ public function getDocument() { return $this->transformer->transform($this->analyzer->dumpConfig()); } - } diff --git a/src/Contracts/ConfigWriterContract.php b/src/Contracts/ConfigWriterContract.php index 53620e0..f97cd9d 100644 --- a/src/Contracts/ConfigWriterContract.php +++ b/src/Contracts/ConfigWriterContract.php @@ -3,20 +3,18 @@ namespace Stillat\Proteus\Contracts; /** - * Interface ConfigWriterContract + * Interface ConfigWriterContract. * * Provides a consistent API for interacting with the config writer and the Laravel configuration system. - * - * @package Stillat\Proteus\Contracts */ interface ConfigWriterContract { - /** * Attempts to change a single configuration item and write the changes to disk. * - * @param string $key The configuration key. - * @param mixed $value The value to update. + * @param string $key The configuration key. + * @param mixed $value The value to update. + * * @return bool */ public function write($key, $value); @@ -25,8 +23,9 @@ public function write($key, $value); * Attempts to apply multiple changes to a configuration namespace. * * @param string $configNamespace The configuration namespace. - * @param array $values The key/value pairs to update. - * @param bool $isMerge Indiciates if the current operation is a merge, or forced update. + * @param array $values The key/value pairs to update. + * @param bool $isMerge Indiciates if the current operation is a merge, or forced update. + * * @return bool */ public function writeMany($configNamespace, array $values, $isMerge = false); @@ -35,7 +34,8 @@ public function writeMany($configNamespace, array $values, $isMerge = false); * Attempts to merge multiple changes to a configuration namespace. * * @param string $configNamespace The configuration namespace. - * @param array $values The key/value pairs to update. + * @param array $values The key/value pairs to update. + * * @return bool */ public function mergeMany($configNamespace, array $values); @@ -44,6 +44,7 @@ public function mergeMany($configNamespace, array $values); * Checks if a configuration file with the provided key exists. * * @param string $key The key to check. + * * @return bool */ public function hasConfig($key); @@ -52,6 +53,7 @@ public function hasConfig($key); * Checks if a configuration file with the provided key exists. * * @param string $key The key to check. + * * @return array|null */ public function getFile($key); @@ -74,6 +76,7 @@ public function ignoreFunctionCalls(); * Sets a list of configuration keys that should always be preserved. * * @param array $config + * * @return mixed */ public function preserve($config); @@ -81,8 +84,9 @@ public function preserve($config); /** * Attempts to update the source configuration and returns the modified document. * - * @param string $key The configuration item to update. - * @param mixed $value The value to set. + * @param string $key The configuration item to update. + * @param mixed $value The value to set. + * * @return string */ public function preview($key, $value); @@ -91,10 +95,10 @@ public function preview($key, $value); * Attempts to apply many changes to a source configuration document and return the modified document. * * @param string $configNamespace The root configuration namespace. - * @param array $values The key/value mapping of all changes. - * @param bool $isMerge Indiciates if the current operation is a merge, or forced update. + * @param array $values The key/value mapping of all changes. + * @param bool $isMerge Indiciates if the current operation is a merge, or forced update. + * * @return string */ public function previewMany($configNamespace, array $values, $isMerge = false); - } diff --git a/src/Contracts/FunctionHandlerContract.php b/src/Contracts/FunctionHandlerContract.php index 19aa749..bffbc54 100644 --- a/src/Contracts/FunctionHandlerContract.php +++ b/src/Contracts/FunctionHandlerContract.php @@ -5,25 +5,22 @@ use PhpParser\Node\Expr\FuncCall; /** - * Interface FunctionHandlerContract + * Interface FunctionHandlerContract. * * Function handlers are responsible for analyzing an expression to * apply mutations to function-based configuration items/values. - * - * @package Stillat\Proteus\Contracts */ interface FunctionHandlerContract { - /** * Analyzes the source expression and applies any required function mutations. * - * @param FuncCall $expr The source expression. - * @param mixed $currentNode The current node. - * @param mixed $referenceNode The reference node. - * @param string $referenceKey The reference key. + * @param FuncCall $expr The source expression. + * @param mixed $currentNode The current node. + * @param mixed $referenceNode The reference node. + * @param string $referenceKey The reference key. + * * @return mixed */ public function handle(FuncCall $expr, $currentNode, $referenceNode, string $referenceKey); - } diff --git a/src/Contracts/ValueWriterContract.php b/src/Contracts/ValueWriterContract.php index 51e755b..dd24cd1 100644 --- a/src/Contracts/ValueWriterContract.php +++ b/src/Contracts/ValueWriterContract.php @@ -3,22 +3,20 @@ namespace Stillat\Proteus\Contracts; /** - * Interface ValueWriterContract + * Interface ValueWriterContract. * * Provides a consistent interface for converting runtime value types to mutable node types. * - * @package Stillat\Proteus\Contracts * @since 1.0.0 */ interface ValueWriterContract { - /** * Writes the provided value. * * @param mixed $value The value to write. + * * @return mixed */ public function write($value); - } diff --git a/src/Document/Printer.php b/src/Document/Printer.php index af6cf09..d3b30a1 100644 --- a/src/Document/Printer.php +++ b/src/Document/Printer.php @@ -4,35 +4,33 @@ use Exception; use PhpParser\Builder\Class_; -use PhpParser\Node\Stmt\InlineHTML; -use PhpParser\Node\Expr\New_; use PhpParser\Internal\PrintableNewAnonClassNode; use PhpParser\Node; -use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\ArrayItem; +use PhpParser\Node\Expr\FuncCall; +use PhpParser\Node\Expr\New_; +use PhpParser\Node\Stmt\InlineHTML; use PhpParser\PrettyPrinter\Standard; /** - * Class Printer + * Class Printer. * * Provides utilities for converting an AST tree back to a PHP document. * - * @package Stillat\Proteus\Document * @since 1.0.0 */ class Printer extends Standard { - protected function pExpr_Array(Array_ $node) { - return '[' . $this->pMaybeMultiline($node->items, true) . ']'; + return '['.$this->pMaybeMultiline($node->items, true).']'; } - - protected function pExpr_FuncCall(FuncCall $node) { + protected function pExpr_FuncCall(FuncCall $node) + { return $this->pCallLhs($node->name) - . '(' . $this->pCommaSeparated($node->args) . ')'; + .'('.$this->pCommaSeparated($node->args).')'; } /** @@ -40,16 +38,18 @@ protected function pExpr_FuncCall(FuncCall $node) { * * This method also handles formatting preservation for nodes. * - * @param Node $node Node to be pretty printed + * @param Node $node Node to be pretty printed * @param bool $parentFormatPreserved Whether parent node has preserved formatting * - * @return string Pretty printed node * @throws Exception + * + * @return string Pretty printed node */ - protected function p(Node $node, $parentFormatPreserved = false) : string { + protected function p(Node $node, $parentFormatPreserved = false): string + { // No orig tokens means this is a normal pretty print without preservation of formatting if (!$this->origTokens) { - return $this->{'p' . $node->getType()}($node); + return $this->{'p'.$node->getType()}($node); } /** @var Node $origNode */ @@ -102,7 +102,12 @@ protected function p(Node $node, $parentFormatPreserved = false) : string { if (is_array($subNode) && is_array($origSubNode)) { // Array subnode changed, we might be able to reconstruct it $listResult = $this->pArray( - $subNode, $origSubNode, $pos, $indentAdjustment, $type, $subNodeName, + $subNode, + $origSubNode, + $pos, + $indentAdjustment, + $type, + $subNodeName, $fixupInfo[$subNodeName] ?? null ); if (null === $listResult) { @@ -115,7 +120,7 @@ protected function p(Node $node, $parentFormatPreserved = false) : string { if (is_int($subNode) && is_int($origSubNode)) { // Check if this is a modifier change - $key = $type . '->' . $subNodeName; + $key = $type.'->'.$subNodeName; if (!isset($this->modifierChangeMap[$key])) { return $this->pFallback($fallbackNode); } @@ -145,7 +150,7 @@ protected function p(Node $node, $parentFormatPreserved = false) : string { } // A node has been inserted, check if we have insertion information for it - $key = $type . '->' . $subNodeName; + $key = $type.'->'.$subNodeName; if (!isset($this->insertionMap[$key])) { return $this->pFallback($fallbackNode); } @@ -167,7 +172,7 @@ protected function p(Node $node, $parentFormatPreserved = false) : string { if (null === $subNode) { // A node has been removed, check if we have removal information for it - $key = $type . '->' . $subNodeName; + $key = $type.'->'.$subNodeName; if (!isset($this->removalMap[$key])) { return $this->pFallback($fallbackNode); } @@ -212,6 +217,7 @@ protected function p(Node $node, $parentFormatPreserved = false) : string { } $result .= $this->origTokens->getTokenCode($pos, $endPos + 1, $indentAdjustment); + return $result; } @@ -225,7 +231,8 @@ protected function p(Node $node, $parentFormatPreserved = false) : string { * * @return string Comma separated pretty printed nodes in multiline style */ - protected function pCommaSeparatedMultiline(array $nodes, bool $trailingComma) : string { + protected function pCommaSeparatedMultiline(array $nodes, bool $trailingComma): string + { $this->indent(); $result = ''; @@ -234,10 +241,10 @@ protected function pCommaSeparatedMultiline(array $nodes, bool $trailingComma) : if ($node !== null) { $comments = $node->getComments(); if ($comments) { - $result .= $this->nl. $this->pComments($comments); + $result .= $this->nl.$this->pComments($comments); } - $result .= $this->nl . $this->p($node); + $result .= $this->nl.$this->p($node); } else { $result .= $this->nl; } @@ -247,12 +254,13 @@ protected function pCommaSeparatedMultiline(array $nodes, bool $trailingComma) : } $this->outdent(); + return $result; } protected function pMaybeMultiline(array $nodes, bool $trailingComma = false) { - return $this->pCommaSeparatedMultiline($nodes, $trailingComma) . $this->nl; + return $this->pCommaSeparatedMultiline($nodes, $trailingComma).$this->nl; } /** @@ -264,7 +272,7 @@ protected function pMaybeMultiline(array $nodes, bool $trailingComma = false) */ protected function pCommaSeparated(array $nodes): string { - return $this->pImplode($nodes, ","); + return $this->pImplode($nodes, ','); } protected function pExpr_ArrayItem(ArrayItem $node) @@ -279,6 +287,7 @@ protected function hasNodeWithComments(array $nodes) return true; } } + return false; } @@ -290,7 +299,8 @@ protected function hasNodeWithComments(array $nodes) * * @return string Imploded pretty printed nodes */ - protected function pImplode(array $nodes, string $glue = '') : string { + protected function pImplode(array $nodes, string $glue = ''): string + { $pNodes = []; foreach ($nodes as $node) { if (null === $node) { @@ -302,5 +312,4 @@ protected function pImplode(array $nodes, string $glue = '') : string { return implode($glue.$this->nl, $pNodes); } - } diff --git a/src/Document/Transformer.php b/src/Document/Transformer.php index ebfa8c9..49ad3b7 100644 --- a/src/Document/Transformer.php +++ b/src/Document/Transformer.php @@ -3,11 +3,10 @@ namespace Stillat\Proteus\Document; /** - * Class Transformer + * Class Transformer. * * Transforms a temporary document structure into its final, consumable form. * - * @package Stillat\Proteus\Document * @since 1.0.0 */ class Transformer @@ -20,19 +19,20 @@ class Transformer * @var string[] */ protected $simpleReplacements = [ - "(bool) ''" => 'false', - "(bool) '1'" => 'true', - "(double) '/*W:D:ST*/" => '', - "(int) '/*W:INT:ST*/" => '', - "/*W:D:SQ*/'" => '', - "/*W:INT:SQ*/'" => '', - Transformer::PROTEUS_NL => "\n" + "(bool) ''" => 'false', + "(bool) '1'" => 'true', + "(double) '/*W:D:ST*/" => '', + "(int) '/*W:INT:ST*/" => '', + "/*W:D:SQ*/'" => '', + "/*W:INT:SQ*/'" => '', + Transformer::PROTEUS_NL => "\n", ]; /** * Prepares a final document for consumption. * * @param string $content The content. + * * @return string */ public function transform($content) @@ -48,6 +48,7 @@ public function transform($content) * Normalizes all line endings in the provided string. * * @param string $string The value to normalize. + * * @return string */ public static function normalizeLineEndings($string) @@ -57,5 +58,4 @@ public static function normalizeLineEndings($string) return $string; } - } diff --git a/src/Exceptions/ConfigNotFoundException.php b/src/Exceptions/ConfigNotFoundException.php index 092047b..ce54c82 100644 --- a/src/Exceptions/ConfigNotFoundException.php +++ b/src/Exceptions/ConfigNotFoundException.php @@ -6,5 +6,4 @@ class ConfigNotFoundException extends Exception { - } diff --git a/src/Exceptions/ConfigNotWriteableException.php b/src/Exceptions/ConfigNotWriteableException.php index 927c893..91d9973 100644 --- a/src/Exceptions/ConfigNotWriteableException.php +++ b/src/Exceptions/ConfigNotWriteableException.php @@ -6,5 +6,4 @@ class ConfigNotWriteableException extends Exception { - } diff --git a/src/Exceptions/GuardedConfigurationMutationException.php b/src/Exceptions/GuardedConfigurationMutationException.php index b1df74e..ea78112 100644 --- a/src/Exceptions/GuardedConfigurationMutationException.php +++ b/src/Exceptions/GuardedConfigurationMutationException.php @@ -6,5 +6,4 @@ class GuardedConfigurationMutationException extends Exception { - } diff --git a/src/LaravelConfigWriter.php b/src/LaravelConfigWriter.php index 5c0f7dd..19561be 100644 --- a/src/LaravelConfigWriter.php +++ b/src/LaravelConfigWriter.php @@ -3,10 +3,9 @@ namespace Stillat\Proteus; use Illuminate\Contracts\Config\Repository; -use Illuminate\Support\Arr; +use Illuminate\Contracts\Foundation\Application; use Illuminate\Support\Str; use SplFileInfo; -use Illuminate\Contracts\Foundation\Application; use Stillat\Proteus\Analyzers\RecursiveKeyAnalyzer; use Stillat\Proteus\Contracts\ConfigWriterContract; use Stillat\Proteus\Exceptions\ConfigNotFoundException; @@ -16,11 +15,9 @@ use Symfony\Component\Finder\Finder; /** - * Class LaravelConfigWriter + * Class LaravelConfigWriter. * * Interacts with the Laravel configuration services to provide config-writing features. - * - * @package Stillat\Proteus */ class LaravelConfigWriter implements ConfigWriterContract { @@ -81,6 +78,7 @@ class LaravelConfigWriter implements ConfigWriterContract /** * A list of configuration keys that should be preserved. + * * @var array */ protected $preserveKeys = []; @@ -124,6 +122,7 @@ public function guard($entry) * Get all of the configuration files for the application. * * @param Application $app + * * @return array */ protected function getConfigurationFiles(Application $app) @@ -135,7 +134,7 @@ protected function getConfigurationFiles(Application $app) foreach (Finder::create()->files()->name('*.php')->in($configPath) as $file) { $directory = $this->getNestedDirectory($file, $configPath); - $files[$directory . basename($file->getRealPath(), '.php')] = $file->getRealPath(); + $files[$directory.basename($file->getRealPath(), '.php')] = $file->getRealPath(); } ksort($files, SORT_NATURAL); @@ -147,7 +146,8 @@ protected function getConfigurationFiles(Application $app) * Get the configuration file nesting path. * * @param SplFileInfo $file - * @param string $configPath + * @param string $configPath + * * @return string */ protected function getNestedDirectory(SplFileInfo $file, $configPath) @@ -155,7 +155,7 @@ protected function getNestedDirectory(SplFileInfo $file, $configPath) $directory = $file->getPath(); if ($nested = trim(str_replace($configPath, '', $directory), DIRECTORY_SEPARATOR)) { - $nested = str_replace(DIRECTORY_SEPARATOR, '.', $nested) . '.'; + $nested = str_replace(DIRECTORY_SEPARATOR, '.', $nested).'.'; } return $nested; @@ -165,6 +165,7 @@ protected function getNestedDirectory(SplFileInfo $file, $configPath) * Attempts to locate the most specific configuration match available. * * @param string $key The configuration key. + * * @return array|null */ public function getFile($key) @@ -172,8 +173,8 @@ public function getFile($key) foreach ($this->configNamespaces as $configNamespace) { if (Str::startsWith($key, $configNamespace)) { return [ - self::KEY_FILEPATH => $this->files[$configNamespace], - self::KEY_NAMESPACE => $configNamespace + self::KEY_FILEPATH => $this->files[$configNamespace], + self::KEY_NAMESPACE => $configNamespace, ]; } } @@ -183,8 +184,9 @@ public function getFile($key) /** * Retrieves the value for the provided key. - * + * * @param string $key The configuration key. + * * @return mixed */ public function getConfigItem($key) @@ -196,6 +198,7 @@ public function getConfigItem($key) * Checks if a configuration file with the provided key exists. * * @param string $key The key to check. + * * @return bool */ public function hasConfig($key) @@ -207,7 +210,8 @@ public function hasConfig($key) * Adjusts the provided configuration key with respect to the configuration namespace. * * @param string $configNamespace The configuration namespace. - * @param string $configKey The configuration key to update. + * @param string $configKey The configuration key to update. + * * @return string */ protected function adjustKey($configNamespace, $configKey) @@ -218,12 +222,14 @@ protected function adjustKey($configNamespace, $configKey) /** * Attempts to change a single configuration item and write the changes to disk. * - * @param string $key The configuration key. - * @param mixed $value The value to update. - * @return bool + * @param string $key The configuration key. + * @param mixed $value The value to update. + * * @throws ConfigNotFoundException * @throws ConfigNotWriteableException * @throws GuardedConfigurationMutationException + * + * @return bool */ public function write($key, $value) { @@ -244,6 +250,7 @@ public function write($key, $value) * Returns an update wrapper for the provided configuration namespace. * * @param string $namespace The configuration instance. + * * @return ConfigUpdateWrapper */ public function edit($namespace) @@ -255,6 +262,7 @@ public function edit($namespace) * Sets a list of configuration items that will never be updated. * * @param array $config The configuration keys to preserve. + * * @return $this */ public function preserve($config) @@ -280,12 +288,14 @@ public function ignoreFunctionCalls() * Attempts to apply multiple changes to a configuration namespace. * * @param string $configNamespace The configuration namespace. - * @param array $values The key/value pairs to update. - * @param bool $isMerge Indiciates if the current operation is a merge, or forced update. - * @return bool + * @param array $values The key/value pairs to update. + * @param bool $isMerge Indiciates if the current operation is a merge, or forced update. + * * @throws ConfigNotFoundException * @throws ConfigNotWriteableException * @throws GuardedConfigurationMutationException + * + * @return bool */ public function writeMany($configNamespace, array $values, $isMerge = false) { @@ -306,11 +316,13 @@ public function writeMany($configNamespace, array $values, $isMerge = false) * Attempts to merge multiple changes to a configuration namespace. * * @param string $configNamespace The configuration namespace. - * @param array $values The key/value pairs to update. - * @return bool + * @param array $values The key/value pairs to update. + * * @throws ConfigNotFoundException * @throws ConfigNotWriteableException * @throws GuardedConfigurationMutationException + * + * @return bool */ public function mergeMany($configNamespace, array $values) { @@ -321,7 +333,8 @@ public function mergeMany($configNamespace, array $values) * Checks all requested changes against any restricted configuration levels. * * @param string $namespace The configuration namespace. - * @param array $changes The changes to validate. + * @param array $changes The changes to validate. + * * @throws GuardedConfigurationMutationException */ private function checkChangesWithGuard($namespace, array $changes) @@ -335,6 +348,7 @@ private function checkChangesWithGuard($namespace, array $changes) * Checks the provided keys against any restricted configuration levels. * * @param string[] $keys The keys to check. + * * @throws GuardedConfigurationMutationException */ public function checkGuard($keys) @@ -351,14 +365,16 @@ public function checkGuard($keys) /** * Attempts to apply the specified changes to the configuration file. * - * @param string $file The path to the configuration file. + * @param string $file The path to the configuration file. * @param string $namespace The configuration namespace. - * @param array $changes The changes to apply. - * @param bool $isMerge Indicates if merge or forced overwrite behavior should be used. - * @return string + * @param array $changes The changes to apply. + * @param bool $isMerge Indicates if merge or forced overwrite behavior should be used. + * * @throws ConfigNotFoundException * @throws ConfigNotWriteableException * @throws GuardedConfigurationMutationException + * + * @return string */ protected function getChanges($file, $namespace, array $changes, $isMerge = false) { @@ -385,12 +401,14 @@ protected function getChanges($file, $namespace, array $changes, $isMerge = fals * Attempts to apply many changes to a source configuration document and return the modified document. * * @param string $configNamespace The root configuration namespace. - * @param array $values The key/value mapping of all changes. - * @param bool $isMerge Indicates if the current operation is a merge, or forced update. - * @return string + * @param array $values The key/value mapping of all changes. + * @param bool $isMerge Indicates if the current operation is a merge, or forced update. + * * @throws ConfigNotFoundException * @throws ConfigNotWriteableException * @throws GuardedConfigurationMutationException + * + * @return string */ public function previewMany($configNamespace, array $values, $isMerge = false) { @@ -409,9 +427,11 @@ public function previewMany($configNamespace, array $values, $isMerge = false) * Creates and returns a ConfigUpdater instance for the requested namespace. * * @param string $namespace The configuration namespace. - * @return ConfigUpdater + * * @throws ConfigNotFoundException * @throws ConfigNotWriteableException + * + * @return ConfigUpdater */ public function getUpdater($namespace) { @@ -423,7 +443,6 @@ public function getUpdater($namespace) $file = $configDetails[self::KEY_FILEPATH]; - if (!file_exists($file)) { throw new ConfigNotFoundException("Config file for '{$namespace}' could not be located."); } @@ -441,12 +460,14 @@ public function getUpdater($namespace) /** * Attempts to update the source configuration and returns the modified document. * - * @param string $key The configuration item to update. - * @param mixed $value The value to set. - * @return string + * @param string $key The configuration item to update. + * @param mixed $value The value to set. + * * @throws ConfigNotFoundException * @throws ConfigNotWriteableException * @throws GuardedConfigurationMutationException + * + * @return string */ public function preview($key, $value) { @@ -460,8 +481,7 @@ public function preview($key, $value) $file = $configDetails[self::KEY_FILEPATH]; return $this->getChanges($file, $configDetails[self::KEY_NAMESPACE], [ - $adjustedKey => $value + $adjustedKey => $value, ]); } - } diff --git a/src/Support/Facades/ConfigWriter.php b/src/Support/Facades/ConfigWriter.php index 8cfadbe..934174f 100644 --- a/src/Support/Facades/ConfigWriter.php +++ b/src/Support/Facades/ConfigWriter.php @@ -25,7 +25,6 @@ */ class ConfigWriter extends Facade { - /** * Get the registered name of the component. * @@ -35,5 +34,4 @@ protected static function getFacadeAccessor() { return ConfigWriterContract::class; } - } diff --git a/src/Support/Facades/Func.php b/src/Support/Facades/Func.php index 6ff7b47..d88331d 100644 --- a/src/Support/Facades/Func.php +++ b/src/Support/Facades/Func.php @@ -7,10 +7,8 @@ class Func extends Facade { - protected static function getFacadeAccessor() { return FunctionWriter::class; } - } diff --git a/src/Visitors/ConfigNodeVisitor.php b/src/Visitors/ConfigNodeVisitor.php index 165ccfd..3e52aa1 100644 --- a/src/Visitors/ConfigNodeVisitor.php +++ b/src/Visitors/ConfigNodeVisitor.php @@ -2,24 +2,22 @@ namespace Stillat\Proteus\Visitors; +use Illuminate\Support\Str; use PhpParser\Node; use PhpParser\Node\Expr\ArrayItem; use PhpParser\Node\Scalar\String_; use PhpParser\NodeVisitor; use Stillat\Proteus\Analyzers\ConfigAnalyzer; -use Illuminate\Support\Str; /** - * Class ConfigNodeVisitor + * Class ConfigNodeVisitor. * * Visits each AST node and sets information about the parent history. * - * @package Stillat\Proteus\Visitors * @since 1.0.0 */ class ConfigNodeVisitor implements NodeVisitor { - /** * @var null|ConfigAnalyzer */ @@ -64,7 +62,7 @@ private function getParentKeyChainItem(Node $node, $key) if ($parent != null) { $nodeKey = $this->getArrayItemKey($parent); - return $this->getParentKeyChainItem($parent, $nodeKey . '.' . $key); + return $this->getParentKeyChainItem($parent, $nodeKey.'.'.$key); } return $key; @@ -92,5 +90,4 @@ public function leaveNode(Node $node) public function afterTraverse(array $nodes) { } - } diff --git a/src/Visitors/CreateParentVisitor.php b/src/Visitors/CreateParentVisitor.php index 7c3bb2b..15076a4 100644 --- a/src/Visitors/CreateParentVisitor.php +++ b/src/Visitors/CreateParentVisitor.php @@ -6,11 +6,10 @@ use PhpParser\NodeVisitorAbstract; /** - * Class CreateParentVisitor + * Class CreateParentVisitor. * * Visits each node and sets its parent relationship. * - * @package Stillat\Proteus\Visitors * @since 1.0.0 */ class CreateParentVisitor extends NodeVisitorAbstract diff --git a/src/WriterServiceProvider.php b/src/WriterServiceProvider.php index 0559e0b..25e7550 100644 --- a/src/WriterServiceProvider.php +++ b/src/WriterServiceProvider.php @@ -4,20 +4,15 @@ use Illuminate\Support\ServiceProvider; use Stillat\Proteus\Contracts\ConfigWriterContract; -use Stillat\Proteus\Repository\ConfigRepository; use Stillat\Proteus\Writers\FunctionWriter; /** - * Class WriterServiceProvider + * Class WriterServiceProvider. * * Registers the required dependencies to make Proteus work. - * - * @package Stillat\Proteus */ class WriterServiceProvider extends ServiceProvider { - - public function register() { $this->app->singleton(FunctionWriter::class, function () { @@ -25,5 +20,4 @@ public function register() }); $this->app->singleton(ConfigWriterContract::class, LaravelConfigWriter::class); } - } diff --git a/src/Writers/ArrayWriter.php b/src/Writers/ArrayWriter.php index 88fdca4..77e731b 100644 --- a/src/Writers/ArrayWriter.php +++ b/src/Writers/ArrayWriter.php @@ -6,16 +6,14 @@ use PhpParser\Node\Expr\ArrayItem; /** - * Class ArrayWriter + * Class ArrayWriter. * * Provides utilities for converting runtime arrays to a mutable node value. * - * @package Stillat\Proteus\Writers * @since 1.0.0 */ class ArrayWriter { - public function analyze($value) { $items = []; @@ -38,5 +36,4 @@ private function wrap($value) { return $value; } - } diff --git a/src/Writers/BoolWriter.php b/src/Writers/BoolWriter.php index 0abd7d0..e4bc8f6 100644 --- a/src/Writers/BoolWriter.php +++ b/src/Writers/BoolWriter.php @@ -7,19 +7,16 @@ use Stillat\Proteus\Contracts\ValueWriterContract; /** - * Class BoolWriter + * Class BoolWriter. * * Provides utilities for converting runtime boolean values to a mutable node value. * - * @package Stillat\Proteus\Writers * @since 1.0.0 */ class BoolWriter implements ValueWriterContract { - public function write($value) { return new Bool_(new String_($value)); } - } diff --git a/src/Writers/ClassFetchWriter.php b/src/Writers/ClassFetchWriter.php index 007a81e..d46c03b 100644 --- a/src/Writers/ClassFetchWriter.php +++ b/src/Writers/ClassFetchWriter.php @@ -8,19 +8,17 @@ use Stillat\Proteus\Contracts\ValueWriterContract; /** - * Class ClassFetchWriter + * Class ClassFetchWriter. * * Provides utilities for converting runtime string values PHP class fetch constants. * - * @package Stillat\Proteus\Writers * @since 1.0.6 */ class ClassFetchWriter implements ValueWriterContract { - /** - * * @param string $value The input value. + * * @return ClassConstFetch */ public function write($value) @@ -29,5 +27,4 @@ public function write($value) return new ClassConstFetch($fqn, new Identifier('class')); } - } diff --git a/src/Writers/DoubleWriter.php b/src/Writers/DoubleWriter.php index 74985f8..7a00406 100644 --- a/src/Writers/DoubleWriter.php +++ b/src/Writers/DoubleWriter.php @@ -7,11 +7,10 @@ use Stillat\Proteus\Contracts\ValueWriterContract; /** - * Class DoubleWriter + * Class DoubleWriter. * * Provides utilities for converting runtime float values to mutable node values. * - * @package Stillat\Proteus\Writers * @since 1.0.0 */ class DoubleWriter implements ValueWriterContract @@ -28,5 +27,4 @@ public function write($value) { return new Double(new String_($this->wrap($value))); } - } diff --git a/src/Writers/FunctionWriter.php b/src/Writers/FunctionWriter.php index f4966eb..7fc1972 100644 --- a/src/Writers/FunctionWriter.php +++ b/src/Writers/FunctionWriter.php @@ -3,8 +3,8 @@ namespace Stillat\Proteus\Writers; use PhpParser\Node\Arg; -use PhpParser\Node\Name; use PhpParser\Node\Expr\FuncCall; +use PhpParser\Node\Name; use PhpParser\Node\Scalar\String_; class FunctionWriter @@ -18,7 +18,6 @@ class FunctionWriter const FUNC_LARAVEL_PUBLIC_PATH = 'public_path'; const FUNC_LARAVEL_STORAGE_PATH = 'storage_path'; - protected function makeSimpleFunctionCall($name, $arg = null) { $n = new Name($name); @@ -68,5 +67,4 @@ public function resourcePath($path) { return $this->makeSimpleFunctionCall(self::FUNC_LARAVEL_RESOURCE_PATH, $path); } - } diff --git a/src/Writers/IntWriter.php b/src/Writers/IntWriter.php index d128503..943c07e 100644 --- a/src/Writers/IntWriter.php +++ b/src/Writers/IntWriter.php @@ -7,11 +7,10 @@ use Stillat\Proteus\Contracts\ValueWriterContract; /** - * Class IntWriter + * Class IntWriter. * * Provides utilities for converting runtime integer values into mutable node values. * - * @package Stillat\Proteus\Writers * @since 1.0.0 */ class IntWriter implements ValueWriterContract @@ -26,6 +25,6 @@ public function write($value) private function wrap($value) { - return self::PROTEUS_INT_PREFIX . strval($value) . self::PROTEUS_INT_SUFFIX_QUOTE; + return self::PROTEUS_INT_PREFIX.strval($value).self::PROTEUS_INT_SUFFIX_QUOTE; } } diff --git a/src/Writers/NullWriter.php b/src/Writers/NullWriter.php index ea8ee05..f2bfbd1 100644 --- a/src/Writers/NullWriter.php +++ b/src/Writers/NullWriter.php @@ -7,20 +7,19 @@ use Stillat\Proteus\Contracts\ValueWriterContract; /** - * Class NullWriter + * Class NullWriter. * * Provides utilities for converting `null` values to a valid node. * - * @package Stillat\Proteus\Writers * @since 1.0.2 */ class NullWriter implements ValueWriterContract { - /** * Writes the provided value. * * @param mixed $value The value to write. + * * @return mixed */ public function write($value) @@ -29,5 +28,4 @@ public function write($value) return new ConstFetch($constName); } - } diff --git a/src/Writers/StringWriter.php b/src/Writers/StringWriter.php index 713279d..e4e7018 100644 --- a/src/Writers/StringWriter.php +++ b/src/Writers/StringWriter.php @@ -6,18 +6,17 @@ use Stillat\Proteus\Contracts\ValueWriterContract; /** - * Class StringWriter + * Class StringWriter. * * Provides utilities for converting runtime string values into mutable node values. * - * @package Stillat\Proteus\Writers * @since 1.0.0 */ class StringWriter implements ValueWriterContract { /** - * * @param string $value The input value. + * * @return String_ */ public function write($value) diff --git a/src/Writers/TypeWriter.php b/src/Writers/TypeWriter.php index f067622..d7e6874 100644 --- a/src/Writers/TypeWriter.php +++ b/src/Writers/TypeWriter.php @@ -5,30 +5,29 @@ use Exception; use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\Cast\Bool_; -use PhpParser\Node\Expr\Cast\Double; use PhpParser\Node\Expr\Cast\Int_; -use PhpParser\Node\Scalar\String_; use PhpParser\Node\Expr\FuncCall; +use PhpParser\Node\Scalar\String_; use Stillat\Proteus\Analyzers\TypeAnalyzer; use Stillat\Proteus\Analyzers\Types; /** - * Class TypeWriter + * Class TypeWriter. * * Provides a wrapper around the various type writers to convert runtime values to mutable node values. * - * @package Stillat\Proteus\Writers * @since 1.0.0 */ class TypeWriter { - /** * Attempts to convert the input value into a mutable node value. * * @param mixed $value The value to convert. - * @return mixed|Array_|Bool_|Double|Int_|String_|null + * * @throws Exception + * + * @return mixed|Array_|Bool_|float|Int_|String_|null */ public static function write($value) { @@ -40,9 +39,11 @@ public static function write($value) if ($type === Types::TYPE_ARRAY) { $arrayWriter = new ArrayWriter(); + return $arrayWriter->analyze($value); } elseif ($type === Types::TYPE_DOUBLE) { $doubleWriter = new DoubleWriter(); + return $doubleWriter->write($value); } elseif ($type === Types::TYPE_STRING) { if (class_exists($value)) { @@ -54,10 +55,12 @@ public static function write($value) return $stringWriter->write($value); } elseif ($type === Types::TYPE_INT) { - $intWriter= new IntWriter(); + $intWriter = new IntWriter(); + return $intWriter->write($value); } elseif ($type === Types::TYPE_BOOL) { $boolWriter = new BoolWriter(); + return $boolWriter->write($value); } elseif ($type === Types::TYPE_SPECIAL_NULL) { $nullWriter = new NullWriter(); @@ -67,5 +70,4 @@ public static function write($value) return null; } - } diff --git a/tests/ClearValuesTest.php b/tests/ClearValuesTest.php index dd07457..412f377 100644 --- a/tests/ClearValuesTest.php +++ b/tests/ClearValuesTest.php @@ -4,14 +4,14 @@ class ClearValuesTest extends ProteusTestCase { - public function testThatReassigningAnEmptyArrayToAnArrayClearsValues() { $this->assertChangeEquals( - __DIR__ . '/configs/clear/001.php', - __DIR__ . '/expected/clear/001.php', [ - 'nested.new.key' => [] - ]); + __DIR__.'/configs/clear/001.php', + __DIR__.'/expected/clear/001.php', + [ + 'nested.new.key' => [], + ] + ); } - } diff --git a/tests/ComplexEnvTest.php b/tests/ComplexEnvTest.php index 347d1ed..98f63f2 100644 --- a/tests/ComplexEnvTest.php +++ b/tests/ComplexEnvTest.php @@ -4,40 +4,44 @@ class ComplexEnvTest extends ProteusTestCase { - public function testThatEnvReturnCastsArePreserved() { $this->assertChangeEquals( - __DIR__ . '/configs/app.php', - __DIR__ . '/expected/envcast.php', [ - 'debug' => true - ]); + __DIR__.'/configs/app.php', + __DIR__.'/expected/envcast.php', + [ + 'debug' => true, + ] + ); } public function testThatMultipleEnvCastsSucceed() { $this->assertChangeEquals( - __DIR__ . '/configs/casts.php', - __DIR__ . '/expected/casts.php', [ - 'debug' => false, - 'string' => 'replace', - 'int' => '20', - 'double' => '40.2', - 'bool' => '0', - 'nested.test' => true, - 'test' => 40, - 'test2' => 60.3, - 'test3' => 'this is another string' - ]); + __DIR__.'/configs/casts.php', + __DIR__.'/expected/casts.php', + [ + 'debug' => false, + 'string' => 'replace', + 'int' => '20', + 'double' => '40.2', + 'bool' => '0', + 'nested.test' => true, + 'test' => 40, + 'test2' => 60.3, + 'test3' => 'this is another string', + ] + ); } public function testThatEnvAddsSecondArgumentToSingleArgEnvCalls() { $this->assertChangeEquals( - __DIR__ . '/configs/app.php', - __DIR__ . '/expected/envaddsdefault.php', [ - 'key' => 'newentry' - ]); + __DIR__.'/configs/app.php', + __DIR__.'/expected/envaddsdefault.php', + [ + 'key' => 'newentry', + ] + ); } - } diff --git a/tests/ComplexNestedTest.php b/tests/ComplexNestedTest.php index 933c73d..3a5db8a 100644 --- a/tests/ComplexNestedTest.php +++ b/tests/ComplexNestedTest.php @@ -4,70 +4,78 @@ class ComplexNestedTest extends ProteusTestCase { - public function testThatMixedTypeValuesAreAddedWhenNesting() { $this->assertChangeEquals( - __DIR__ . '/configs/nested/001.php', - __DIR__ . '/expected/nested/001.php', [ - 'test.new' => [ - 'nested' => [ - 'key-one' => 'value-one', - 'key-two' => 'value-two', - 'key-three' => 'value-three', - 'key-four' => [ - 'nested-one' => 'nested-value-one', - 'nested-two' => 'nested-value-two', - 'nested-three' => [ - 'three' => 'value-three' - ] - ] - ] + __DIR__.'/configs/nested/001.php', + __DIR__.'/expected/nested/001.php', + [ + 'test.new' => [ + 'nested' => [ + 'key-one' => 'value-one', + 'key-two' => 'value-two', + 'key-three' => 'value-three', + 'key-four' => [ + 'nested-one' => 'nested-value-one', + 'nested-two' => 'nested-value-two', + 'nested-three' => [ + 'three' => 'value-three', + ], + ], + ], + ], ] - ]); + ); } public function testThatNonArrayValuesUseLastKeyElementForNewElement() { $this->assertChangeEquals( - __DIR__ . '/configs/nested/002.php', - __DIR__ . '/expected/nested/002.php', [ - 'test.nested.type' => 1 - ]); + __DIR__.'/configs/nested/002.php', + __DIR__.'/expected/nested/002.php', + [ + 'test.nested.type' => 1, + ] + ); } public function testThatDotNotationKeysAreNotExpandedWhenUsedInsideArrays() { $this->assertChangeEquals( - __DIR__ . '/configs/nested/003.php', - __DIR__ . '/expected/nested/003.php', [ - 'nested.new.key' => [ - 'these.keys' => 'should not get expanded' + __DIR__.'/configs/nested/003.php', + __DIR__.'/expected/nested/003.php', + [ + 'nested.new.key' => [ + 'these.keys' => 'should not get expanded', + ], ] - ]); + ); } public function testThatComplexNestedKeysGetValuesReplaced() { $this->assertChangeEquals( - __DIR__ . '/configs/nested/004.php', - __DIR__ . '/expected/nested/004.php', [ - 'nested.new.key' => [ - 'these.keys' => 'replacement value' + __DIR__.'/configs/nested/004.php', + __DIR__.'/expected/nested/004.php', + [ + 'nested.new.key' => [ + 'these.keys' => 'replacement value', + ], ] - ]); + ); } public function testThatComplexReplacementsAllowAddingNewElements() { $this->assertChangeEquals( - __DIR__ . '/configs/nested/004.php', - __DIR__ . '/expected/nested/005.php', [ - 'nested.new.key' => [ - 'these.keys' => 'replacement value', - 'this' => 'should be added' + __DIR__.'/configs/nested/004.php', + __DIR__.'/expected/nested/005.php', + [ + 'nested.new.key' => [ + 'these.keys' => 'replacement value', + 'this' => 'should be added', + ], ] - ]); + ); } - } diff --git a/tests/IgnoreConfigurationItemsTest.php b/tests/IgnoreConfigurationItemsTest.php index c966724..1b883ac 100644 --- a/tests/IgnoreConfigurationItemsTest.php +++ b/tests/IgnoreConfigurationItemsTest.php @@ -11,11 +11,11 @@ public function testThatFunctionCallsWereIgnored() { $updater = new ConfigUpdater(); $updater->setIgnoreFunctions(true); - $updater->open(__DIR__ . '/configs/withenv.php'); - $expected = Transformer::normalizeLineEndings(file_get_contents(__DIR__ . '/expected/withenv.php')); + $updater->open(__DIR__.'/configs/withenv.php'); + $expected = Transformer::normalizeLineEndings(file_get_contents(__DIR__.'/expected/withenv.php')); $updater->update([ - 'some_key' => 'new-value', - 'nested.key.value' => 'inserted-value' + 'some_key' => 'new-value', + 'nested.key.value' => 'inserted-value', ]); $doc = $updater->getDocument(); @@ -28,19 +28,19 @@ public function testConfigurationItemsCanBeIgnored() $updater = new ConfigUpdater(); $updater->setPreserveKeys([ 'some_key', - 'nested.key.value' + 'nested.key.value', ]); - $updater->open(__DIR__ . '/configs/withenv.php'); - $expected = Transformer::normalizeLineEndings(file_get_contents(__DIR__ . '/expected/withenv_preserve.php')); + $updater->open(__DIR__.'/configs/withenv.php'); + $expected = Transformer::normalizeLineEndings(file_get_contents(__DIR__.'/expected/withenv_preserve.php')); $updater->update([ - 'some_key' => 'new-value', - 'nested.key.value' => 'inserted-value', - 'nested.key.append' => 'Hello, universe!' + 'some_key' => 'new-value', + 'nested.key.value' => 'inserted-value', + 'nested.key.append' => 'Hello, universe!', ]); $doc = $updater->getDocument(); $this->assertEquals($expected, $doc); } -} \ No newline at end of file +} diff --git a/tests/IgnoreFunctionsWriteManyPreserveTest.php b/tests/IgnoreFunctionsWriteManyPreserveTest.php index 7d38752..1380b3d 100644 --- a/tests/IgnoreFunctionsWriteManyPreserveTest.php +++ b/tests/IgnoreFunctionsWriteManyPreserveTest.php @@ -11,8 +11,8 @@ public function testFunctionsAreRestoredWhenWritingItemsAndPreservingKeys() { $updater = new ConfigUpdater(); $updater->setIgnoreFunctions(true); - $updater->open(__DIR__ . '/configs/issues/014.php'); - $expected = Transformer::normalizeLineEndings(file_get_contents(__DIR__ . '/expected/issues/014.php')); + $updater->open(__DIR__.'/configs/issues/014.php'); + $expected = Transformer::normalizeLineEndings(file_get_contents(__DIR__.'/expected/issues/014.php')); $updater->setPreserveKeys([ 'stripe' => [ 'api_base', @@ -23,21 +23,21 @@ public function testFunctionsAreRestoredWhenWritingItemsAndPreservingKeys() 'secret', 'webhook', 'query_params', - ] + ], ])->update([ 'stripe' => [ 'reports' => [ [ - 'id' => 'a new thing', - 'frequency' => 'daily', + 'id' => 'a new thing', + 'frequency' => 'daily', 'email_addresses' => 'helloworld@example.org', ], ], - ] + ], ], false); // The false merge should get overridden internally. $doc = $updater->getDocument(); $this->assertEquals($expected, $doc); } -} \ No newline at end of file +} diff --git a/tests/InternalStateTest.php b/tests/InternalStateTest.php index f4531f1..717859b 100644 --- a/tests/InternalStateTest.php +++ b/tests/InternalStateTest.php @@ -5,11 +5,10 @@ class InternalStateTest extends TestCase { - public function testThatSourceNodeKeysAreCorrectlyRetrieved() { $updater = new ConfigUpdater(); - $updater->open(__DIR__ . '/configs/mail.php'); + $updater->open(__DIR__.'/configs/mail.php'); $keys = $updater->config()->getSourceNodeKeys(); $expectedKeys = [ @@ -43,7 +42,7 @@ public function testThatSourceNodeKeysAreCorrectlyRetrieved() 'from.name', 'markdown', 'markdown.theme', - 'markdown.paths' + 'markdown.paths', ]; $this->assertEquals($expectedKeys, $keys); @@ -61,5 +60,4 @@ public function testThatNamespaceImportsAreIgnored() $this->assertSame(get_class($root), \PhpParser\Node\Expr\Array_::class); } } - } diff --git a/tests/LaravelFunctionCallTest.php b/tests/LaravelFunctionCallTest.php index f678e8e..3a69440 100644 --- a/tests/LaravelFunctionCallTest.php +++ b/tests/LaravelFunctionCallTest.php @@ -4,16 +4,16 @@ class LaravelFunctionCallTest extends ProteusTestCase { - public function testThatLaravelResourcePathsAreRewrittenCorrectly() { $this->assertChangeEquals( - __DIR__ . '/configs/laravelhelpers/resource.php', - __DIR__ . '/expected/laravelhelpers/resource.php', [ - 'path' => 'new-value', - 'path_two' => 'inserted-value', - 'path_three' => '' - ]); + __DIR__.'/configs/laravelhelpers/resource.php', + __DIR__.'/expected/laravelhelpers/resource.php', + [ + 'path' => 'new-value', + 'path_two' => 'inserted-value', + 'path_three' => '', + ] + ); } - -} \ No newline at end of file +} diff --git a/tests/MergeTest.php b/tests/MergeTest.php index 8aca19c..da44e0e 100644 --- a/tests/MergeTest.php +++ b/tests/MergeTest.php @@ -11,40 +11,40 @@ public function testMergeDoesNotRemoveExistingValues() { $updater = new ConfigUpdater(); $updater->setIgnoreFunctions(true); - $updater->open(__DIR__ . '/configs/merge.php'); - $expected = Transformer::normalizeLineEndings(file_get_contents(__DIR__ . '/expected/merge.php')); + $updater->open(__DIR__.'/configs/merge.php'); + $expected = Transformer::normalizeLineEndings(file_get_contents(__DIR__.'/expected/merge.php')); $updater->setPreserveKeys([ - 'stripe.leave' + 'stripe.leave', ])->update([ 'stripe' => [ - 'leave' => 'hello, there!', + 'leave' => 'hello, there!', 'reports' => [ [ - 'frequency' => 'daily', + 'frequency' => 'daily', 'email_addresses' => 'entry1', ], [ - 'frequency' => 'daily', + 'frequency' => 'daily', 'email_addresses' => 'entry2', ], [ - 'frequency' => 'daily', + 'frequency' => 'daily', 'email_addresses' => 'entry3', ], ], 'test' => [ 'what' => [ - 'nested' => 'value', + 'nested' => 'value', 'happens' => [ - 1, 2, 3, 'four', 'five', 5, 'six', 'seven' => [8] - ] - ] - ] - ] + 1, 2, 3, 'four', 'five', 5, 'six', 'seven' => [8], + ], + ], + ], + ], ], true); $doc = $updater->getDocument(); $this->assertEquals($expected, $doc); } -} \ No newline at end of file +} diff --git a/tests/NewRootEntriesAreAddedTest.php b/tests/NewRootEntriesAreAddedTest.php index 07ec89b..6f214c7 100644 --- a/tests/NewRootEntriesAreAddedTest.php +++ b/tests/NewRootEntriesAreAddedTest.php @@ -4,180 +4,195 @@ class NewRootEntriesAreAddedTest extends ProteusTestCase { - public function testThatNewRootArrayEntriesAreAdded() { $this->assertChangeEquals( - __DIR__ . '/configs/app.php', - __DIR__ . '/expected/simplenewkey.php', [ - 'new' => [ - 'value-one', - 'value-two' - ], - ]); + __DIR__.'/configs/app.php', + __DIR__.'/expected/simplenewkey.php', + [ + 'new' => [ + 'value-one', + 'value-two', + ], + ] + ); } public function testThatNewKeysUsingDotNotationAreProperlyNested() { $this->assertChangeEquals( - __DIR__ . '/configs/app.php', - __DIR__ . '/expected/simpledotnotationkeyset.php', [ - 'new.key' => 'value' - ]); + __DIR__.'/configs/app.php', + __DIR__.'/expected/simpledotnotationkeyset.php', + [ + 'new.key' => 'value', + ] + ); } public function testThatNewDeeplyNestedKeysAreCreated() { $this->assertChangeEquals( - __DIR__ . '/configs/app.php', - __DIR__ . '/expected/deeplynestedtest.php', [ - 'new.deeply.nested.key' => [ - 'hello', - 'world' + __DIR__.'/configs/app.php', + __DIR__.'/expected/deeplynestedtest.php', + [ + 'new.deeply.nested.key' => [ + 'hello', + 'world', + ], ] - ]); + ); } public function testThatNewSimpleItemsAreAppendedToArrays() { $this->assertChangeEquals( - __DIR__ . '/configs/appendarray.php', - __DIR__ . '/expected/appendarray.php', [ - 'test' => 'new-value' - ]); + __DIR__.'/configs/appendarray.php', + __DIR__.'/expected/appendarray.php', + [ + 'test' => 'new-value', + ] + ); } public function testThatResettingAnArrayReplacesTheArray() { $this->assertChangeEquals( - __DIR__ . '/configs/appendarray.php', - __DIR__ . '/expected/arrayreplacesarray.php', [ - 'test' => ['new-value'] - ]); + __DIR__.'/configs/appendarray.php', + __DIR__.'/expected/arrayreplacesarray.php', + [ + 'test' => ['new-value'], + ] + ); } - public function testThatNullValuesAreProperlyConvertedAndSaved() { $this->assertChangeEquals( - __DIR__ . '/configs/issues/004.php', - __DIR__ . '/expected/issues/004.php', [ - 'forms.another_form' => [ - 'name_field' => 'name3', - 'first_name_field' => 'first_name', - 'last_name_field' => 'last_name', - 'email_field' => 'email3', - 'content_field' => 'message', - 'handle' => 'contact_you', - 'consent_field' => null - ], - ]); + __DIR__.'/configs/issues/004.php', + __DIR__.'/expected/issues/004.php', + [ + 'forms.another_form' => [ + 'name_field' => 'name3', + 'first_name_field' => 'first_name', + 'last_name_field' => 'last_name', + 'email_field' => 'email3', + 'content_field' => 'message', + 'handle' => 'contact_you', + 'consent_field' => null, + ], + ] + ); } - public function testThatNewNestedEntriesAreProperlyCreated() { $this->assertChangeEquals( - __DIR__ . '/configs/issues/001/setnew.php', - __DIR__ . '/expected/issues/001/setnew.php', [ - 'forms' => [ - 'contact_us' => [ - 'name_field' => 'name', - 'first_name_field' => 'first_name', - 'last_name_field' => 'last_name', - 'email_field' => 'email', - 'content_field' => 'message', - 'handle' => 'contact_us', - ], - 'contact_you' => - [ - 'name_field' => 'name3', + __DIR__.'/configs/issues/001/setnew.php', + __DIR__.'/expected/issues/001/setnew.php', + [ + 'forms' => [ + 'contact_us' => [ + 'name_field' => 'name', 'first_name_field' => 'first_name', - 'last_name_field' => 'last_name', - 'email_field' => 'email3', - 'content_field' => 'message', - 'handle' => 'contact_you', + 'last_name_field' => 'last_name', + 'email_field' => 'email', + 'content_field' => 'message', + 'handle' => 'contact_us', ], + 'contact_you' => [ + 'name_field' => 'name3', + 'first_name_field' => 'first_name', + 'last_name_field' => 'last_name', + 'email_field' => 'email3', + 'content_field' => 'message', + 'handle' => 'contact_you', + ], + ], ] - ]); + ); } public function testThatNewNestedEntriesAreProperlyUpdatedOnExistingPlaceholder() { $this->assertChangeEquals( - __DIR__ . '/configs/issues/001/fromplaceholder.php', - __DIR__ . '/expected/issues/001/fromplaceholder.php', [ - 'forms' => [ - 'contact_us' => [ - 'name_field' => 'name', - 'first_name_field' => 'first_name', - 'last_name_field' => 'last_name', - 'email_field' => 'email', - 'content_field' => 'message', - 'handle' => 'contact_us', - ], - 'contact_you' => - [ - 'name_field' => 'name3', + __DIR__.'/configs/issues/001/fromplaceholder.php', + __DIR__.'/expected/issues/001/fromplaceholder.php', + [ + 'forms' => [ + 'contact_us' => [ + 'name_field' => 'name', + 'first_name_field' => 'first_name', + 'last_name_field' => 'last_name', + 'email_field' => 'email', + 'content_field' => 'message', + 'handle' => 'contact_us', + ], + 'contact_you' => [ + 'name_field' => 'name3', 'first_name_field' => 'first_name', - 'last_name_field' => 'last_name', - 'email_field' => 'email3', - 'content_field' => 'message', - 'handle' => 'contact_you', + 'last_name_field' => 'last_name', + 'email_field' => 'email3', + 'content_field' => 'message', + 'handle' => 'contact_you', ], + ], ] - ]); + ); } public function testThatAdditionalEntriesAreProperlyAdded() { $this->assertChangeEquals( - __DIR__ . '/configs/issues/001/addnew.php', - __DIR__ . '/expected/issues/001/addnew.php', [ - 'forms.another_form' => - [ - 'name_field' => 'name4', + __DIR__.'/configs/issues/001/addnew.php', + __DIR__.'/expected/issues/001/addnew.php', + [ + 'forms.another_form' => [ + 'name_field' => 'name4', 'first_name_field' => 'first_name', - 'last_name_field' => 'last_name', - 'email_field' => 'email3', - 'content_field' => 'message', - 'handle' => 'contact_you', + 'last_name_field' => 'last_name', + 'email_field' => 'email3', + 'content_field' => 'message', + 'handle' => 'contact_you', ], - ]); + ] + ); } public function testThatSimpleArraysInsideArraysArePreserved() { $this->assertChangeEquals( - __DIR__ . '/configs/issues/005.php', - __DIR__ . '/expected/issues/005.php', [ - 'forms' => [[ - 'name_field' => 'name3', - 'first_name_field' => 'first_name', - 'last_name_field' => 'last_name', - 'email_field' => 'email3', - 'content_field' => 'message', - 'handle' => 'contact_you', - 'consent_field' => null - ]], - ]); + __DIR__.'/configs/issues/005.php', + __DIR__.'/expected/issues/005.php', + [ + 'forms' => [[ + 'name_field' => 'name3', + 'first_name_field' => 'first_name', + 'last_name_field' => 'last_name', + 'email_field' => 'email3', + 'content_field' => 'message', + 'handle' => 'contact_you', + 'consent_field' => null, + ]], + ] + ); } public function testThatSimpleArraysInsideArraysArePreservedWhenSourceKeyAlreadyExists() { $this->assertChangeEquals( - __DIR__ . '/configs/issues/005-2.php', - __DIR__ . '/expected/issues/005-2.php', [ - 'forms' => [[ - 'name_field' => 'name3', - 'first_name_field' => 'first_name', - 'last_name_field' => 'last_name', - 'email_field' => 'email3', - 'content_field' => 'message', - 'handle' => 'contact_you', - 'consent_field' => null - ]], - ]); + __DIR__.'/configs/issues/005-2.php', + __DIR__.'/expected/issues/005-2.php', + [ + 'forms' => [[ + 'name_field' => 'name3', + 'first_name_field' => 'first_name', + 'last_name_field' => 'last_name', + 'email_field' => 'email3', + 'content_field' => 'message', + 'handle' => 'contact_you', + 'consent_field' => null, + ]], + ] + ); } - } diff --git a/tests/PreserveArrayKeysTest.php b/tests/PreserveArrayKeysTest.php index 951281a..686dbca 100644 --- a/tests/PreserveArrayKeysTest.php +++ b/tests/PreserveArrayKeysTest.php @@ -11,42 +11,42 @@ public function testUsingArraysForKeyPreservationWorks() { $updater = new ConfigUpdater(); $updater->setIgnoreFunctions(true); - $updater->open(__DIR__ . '/configs/merge.php'); - $expected = Transformer::normalizeLineEndings(file_get_contents(__DIR__ . '/expected/merge.php')); + $updater->open(__DIR__.'/configs/merge.php'); + $expected = Transformer::normalizeLineEndings(file_get_contents(__DIR__.'/expected/merge.php')); $updater->setPreserveKeys([ 'stripe' => [ 'leave', - ] + ], ])->update([ 'stripe' => [ - 'leave' => 'hello, there!', + 'leave' => 'hello, there!', 'reports' => [ [ - 'frequency' => 'daily', + 'frequency' => 'daily', 'email_addresses' => 'entry1', ], [ - 'frequency' => 'daily', + 'frequency' => 'daily', 'email_addresses' => 'entry2', ], [ - 'frequency' => 'daily', + 'frequency' => 'daily', 'email_addresses' => 'entry3', ], ], 'test' => [ 'what' => [ - 'nested' => 'value', + 'nested' => 'value', 'happens' => [ - 1, 2, 3, 'four', 'five', 5, 'six', 'seven' => [8] - ] - ] - ] - ] + 1, 2, 3, 'four', 'five', 5, 'six', 'seven' => [8], + ], + ], + ], + ], ], true); $doc = $updater->getDocument(); $this->assertEquals($expected, $doc); } -} \ No newline at end of file +} diff --git a/tests/ProteusTestCase.php b/tests/ProteusTestCase.php index 3e20ef7..966c311 100644 --- a/tests/ProteusTestCase.php +++ b/tests/ProteusTestCase.php @@ -6,7 +6,6 @@ class ProteusTestCase extends TestCase { - protected function assertChangeEquals($configPath, $expectedPath, $changes) { $updater = new ConfigUpdater(); @@ -42,5 +41,4 @@ protected function assertRemoveEquals($configPath, $expectedPath, $k) $this->assertEquals($expected, $doc); } - } diff --git a/tests/RemoveValuesTest.php b/tests/RemoveValuesTest.php index c75a7fd..b69e193 100644 --- a/tests/RemoveValuesTest.php +++ b/tests/RemoveValuesTest.php @@ -4,15 +4,13 @@ class RemoveValuesTest extends ProteusTestCase { - public function testThatArrayElementsCanBeRemovedFromArray() { - $this->assertRemoveEquals(__DIR__ . '/configs/mail.php', __DIR__ . '/expected/remove/001.php', 'from.address'); + $this->assertRemoveEquals(__DIR__.'/configs/mail.php', __DIR__.'/expected/remove/001.php', 'from.address'); } public function testThatEntireArraysCanBeRemoved() { - $this->assertRemoveEquals(__DIR__ . '/configs/mail.php', __DIR__ . '/expected/remove/002.php', 'from'); + $this->assertRemoveEquals(__DIR__.'/configs/mail.php', __DIR__.'/expected/remove/002.php', 'from'); } - } diff --git a/tests/SimpleReplacementTest.php b/tests/SimpleReplacementTest.php index 503a999..5a5a2ef 100644 --- a/tests/SimpleReplacementTest.php +++ b/tests/SimpleReplacementTest.php @@ -4,63 +4,73 @@ class SimpleReplacementTest extends ProteusTestCase { - public function testRootReplacementWorks() { $this->assertChangeEquals( - __DIR__ . '/configs/app.php', - __DIR__ . '/expected/simple_replace.php', [ - 'timezone' => 'America/Chicago', - 'fallback_locale' => 'fr' - ]); + __DIR__.'/configs/app.php', + __DIR__.'/expected/simple_replace.php', + [ + 'timezone' => 'America/Chicago', + 'fallback_locale' => 'fr', + ] + ); } public function testEnvCallsAreRetained() { $this->assertChangeEquals( - __DIR__ . '/configs/app.php', - __DIR__ . '/expected/retain_env.php', [ - 'name' => 'Statamic' - ]); + __DIR__.'/configs/app.php', + __DIR__.'/expected/retain_env.php', + [ + 'name' => 'Statamic', + ] + ); } public function testMultipleChangesPreserveEnvCalls() { $this->assertChangeEquals( - __DIR__ . '/configs/app.php', - __DIR__ . '/expected/multi_replace_env.php', [ - 'name' => 'Statamic', - 'locale' => 'fr', - 'env' => 'development', - 'debug' => true, - 'url' => 'http://local.test' - ]); + __DIR__.'/configs/app.php', + __DIR__.'/expected/multi_replace_env.php', + [ + 'name' => 'Statamic', + 'locale' => 'fr', + 'env' => 'development', + 'debug' => true, + 'url' => 'http://local.test', + ] + ); } public function testOutputRetainsUsingStatements() { $this->assertChangeEquals( - __DIR__ . '/configs/configwithusing.php', - __DIR__ . '/expected/configwithusing.php', [ - 'test' => 'updated-value' - ]); + __DIR__.'/configs/configwithusing.php', + __DIR__.'/expected/configwithusing.php', + [ + 'test' => 'updated-value', + ] + ); } public function testThatCustomFunctionsAreRetained() { $this->assertChangeEquals( - __DIR__ . '/configs/retain/func.php', - __DIR__ . '/expected/retain/func.php', [ - ]); + __DIR__.'/configs/retain/func.php', + __DIR__.'/expected/retain/func.php', + [ + ] + ); } public function testThatValuesCanBeCompletelyReplaced() { $this->assertReplaceEquals( - __DIR__ . '/configs/mail.php', - __DIR__ . '/expected/replace/001.php', - 'from', [ - 'my-values' => 'hi' + __DIR__.'/configs/mail.php', + __DIR__.'/expected/replace/001.php', + 'from', + [ + 'my-values' => 'hi', ] ); } @@ -71,7 +81,7 @@ public function testThatRootStructuresCanBeReplacedWithComments() $updater->open(__DIR__.'/configs/issues/008.php'); $expected = \Stillat\Proteus\Document\Transformer::normalizeLineEndings(file_get_contents(__DIR__.'/expected/issues/008.php')); - $docBlock = <<replaceStructure('cart_key', 'cart', [ 'driver' => \Stillat\Proteus\ConfigUpdater::class, - 'key' => 'simple-commerce-cart' + 'key' => 'simple-commerce-cart', ], $docBlock, true); $doc = $updater->getDocument(); $this->assertEquals($expected, $doc); } - } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 5db046f..e91cc12 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,3 +1,3 @@