X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fpsy%2Fpsysh%2Fsrc%2FPsy%2FTabCompletion%2FMatcher%2FAbstractDefaultParametersMatcher.php;fp=vendor%2Fpsy%2Fpsysh%2Fsrc%2FPsy%2FTabCompletion%2FMatcher%2FAbstractDefaultParametersMatcher.php;h=3d7b4214b65bbd13c8bcb8419b79b940addcc3e0;hp=0000000000000000000000000000000000000000;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hpb=aea91e65e895364e460983b890e295aa5d5540a5 diff --git a/vendor/psy/psysh/src/Psy/TabCompletion/Matcher/AbstractDefaultParametersMatcher.php b/vendor/psy/psysh/src/Psy/TabCompletion/Matcher/AbstractDefaultParametersMatcher.php new file mode 100644 index 000000000..3d7b4214b --- /dev/null +++ b/vendor/psy/psysh/src/Psy/TabCompletion/Matcher/AbstractDefaultParametersMatcher.php @@ -0,0 +1,76 @@ +isDefaultValueAvailable()) { + return array(); + } + + $defaultValue = $this->valueToShortString($parameter->getDefaultValue()); + + $parametersProcessed[] = "\${$parameter->getName()} = $defaultValue"; + } + + if (empty($parametersProcessed)) { + return array(); + } + + return array(implode(', ', $parametersProcessed) . ')'); + } + + /** + * Takes in the default value of a parameter and turns it into a + * string representation that fits inline. + * This is not 100% true to the original (newlines are inlined, for example). + * + * @param mixed $value + * + * @return string + */ + private function valueToShortString($value) + { + if (!is_array($value)) { + return json_encode($value); + } + + $chunks = array(); + $chunksSequential = array(); + + $allSequential = true; + + foreach ($value as $key => $item) { + $allSequential = $allSequential && is_numeric($key) && $key === count($chunksSequential); + + $keyString = $this->valueToShortString($key); + $itemString = $this->valueToShortString($item); + + $chunks[] = "{$keyString} => {$itemString}"; + $chunksSequential[] = $itemString; + } + + $chunksToImplode = $allSequential ? $chunksSequential : $chunks; + + return '[' . implode(', ', $chunksToImplode) . ']'; + } +}