X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=vendor%2Fpsy%2Fpsysh%2Fsrc%2FTabCompletion%2FMatcher%2FAbstractDefaultParametersMatcher.php;fp=vendor%2Fpsy%2Fpsysh%2Fsrc%2FTabCompletion%2FMatcher%2FAbstractDefaultParametersMatcher.php;h=1dc0765afb4e5904d4ef5ef4392ae654dfcd2d39;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hp=0000000000000000000000000000000000000000;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0;p=yaffs-website diff --git a/vendor/psy/psysh/src/TabCompletion/Matcher/AbstractDefaultParametersMatcher.php b/vendor/psy/psysh/src/TabCompletion/Matcher/AbstractDefaultParametersMatcher.php new file mode 100644 index 000000000..1dc0765af --- /dev/null +++ b/vendor/psy/psysh/src/TabCompletion/Matcher/AbstractDefaultParametersMatcher.php @@ -0,0 +1,76 @@ +isDefaultValueAvailable()) { + return []; + } + + $defaultValue = $this->valueToShortString($parameter->getDefaultValue()); + + $parametersProcessed[] = "\${$parameter->getName()} = $defaultValue"; + } + + if (empty($parametersProcessed)) { + return []; + } + + return [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 = []; + $chunksSequential = []; + + $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) . ']'; + } +}