diff --git a/composer.lock b/composer.lock index 76cb6e76e..7911b3822 100644 --- a/composer.lock +++ b/composer.lock @@ -84,16 +84,16 @@ }, { "name": "composer/class-map-generator", - "version": "1.5.0", + "version": "1.6.0", "source": { "type": "git", "url": "https://github.com/composer/class-map-generator.git", - "reference": "4b0a223cf5be7c9ee7e0ef1bc7db42b4a97c9915" + "reference": "ffe442c5974c44a9343e37a0abcb1cc37319f5b9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/class-map-generator/zipball/4b0a223cf5be7c9ee7e0ef1bc7db42b4a97c9915", - "reference": "4b0a223cf5be7c9ee7e0ef1bc7db42b4a97c9915", + "url": "https://api.github.com/repos/composer/class-map-generator/zipball/ffe442c5974c44a9343e37a0abcb1cc37319f5b9", + "reference": "ffe442c5974c44a9343e37a0abcb1cc37319f5b9", "shasum": "" }, "require": { @@ -137,7 +137,7 @@ ], "support": { "issues": "https://github.com/composer/class-map-generator/issues", - "source": "https://github.com/composer/class-map-generator/tree/1.5.0" + "source": "https://github.com/composer/class-map-generator/tree/1.6.0" }, "funding": [ { @@ -153,7 +153,7 @@ "type": "tidelift" } ], - "time": "2024-11-25T16:11:06+00:00" + "time": "2025-02-05T10:05:34+00:00" }, { "name": "composer/metadata-minifier", @@ -2020,16 +2020,16 @@ "packages-dev": [ { "name": "phpstan/phpstan", - "version": "1.12.16", + "version": "1.12.18", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "e0bb5cb78545aae631220735aa706eac633a6be9" + "reference": "fef9f07814a573399229304bb0046affdf558812" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/e0bb5cb78545aae631220735aa706eac633a6be9", - "reference": "e0bb5cb78545aae631220735aa706eac633a6be9", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/fef9f07814a573399229304bb0046affdf558812", + "reference": "fef9f07814a573399229304bb0046affdf558812", "shasum": "" }, "require": { @@ -2074,7 +2074,7 @@ "type": "github" } ], - "time": "2025-01-21T14:50:05+00:00" + "time": "2025-02-13T12:44:44+00:00" }, { "name": "phpstan/phpstan-deprecation-rules", diff --git a/src/Composer/Json/JsonManipulator.php b/src/Composer/Json/JsonManipulator.php index c6c5eb555..0b45d6556 100644 --- a/src/Composer/Json/JsonManipulator.php +++ b/src/Composer/Json/JsonManipulator.php @@ -288,15 +288,9 @@ class JsonManipulator return $matches['start'] . $this->format($value, 1) . $matches['end']; }, $children); - } else { - Preg::match('#^{ (?P\s*?) (?P\S+.*?)? (?P\s*) }$#sx', $children, $match); - - $whitespace = ''; - if (!empty($match['trailingspace'])) { - $whitespace = $match['trailingspace']; - } - - if (!empty($match['content'])) { + } elseif (Preg::isMatch('#^\{(?P\s*?)(?P\S+.*?)?(?P\s*)\}$#s', $children, $match)) { + $whitespace = $match['trailingspace']; + if (null !== $match['content']) { if ($subName !== null) { $value = [$subName => $value]; } @@ -309,11 +303,7 @@ class JsonManipulator $children ); } else { - $whitespace = ''; - if (!empty($match['leadingspace'])) { - $whitespace = $match['leadingspace']; - } - + $whitespace = $match['leadingspace']; $children = Preg::replace( '#^{'.$whitespace.'#', addcslashes('{' . $whitespace . JsonFile::encode($name).': '.$this->format($value, 1) . ',' . $this->newline . $this->indent . $this->indent, '\\$'), @@ -328,6 +318,8 @@ class JsonManipulator // children present but empty $children = '{' . $this->newline . $this->indent . $this->indent . JsonFile::encode($name).': '.$this->format($value, 1) . $whitespace . '}'; } + } else { + throw new \LogicException('Nothing matched above for: '.$children); } $this->contents = Preg::replaceCallback($nodeRegex, static function ($m) use ($children): string { @@ -411,26 +403,27 @@ class JsonManipulator // no child data left, $name was the only key in unset($match); - Preg::match('#^{ \s*? (?P\S+.*?)? (?P\s*) }$#sx', $childrenClean, $match); - if (empty($match['content'])) { - $newline = $this->newline; - $indent = $this->indent; + if (Preg::isMatch('#^\{\s*?(?P\S+.*?)?(?P\s*)\}$#s', $childrenClean, $match)) { + if (null === $match['content']) { + $newline = $this->newline; + $indent = $this->indent; - $this->contents = Preg::replaceCallback($nodeRegex, static function ($matches) use ($indent, $newline): string { - return $matches['start'] . '{' . $newline . $indent . '}' . $matches['end']; - }, $this->contents); + $this->contents = Preg::replaceCallback($nodeRegex, static function ($matches) use ($indent, $newline): string { + return $matches['start'] . '{' . $newline . $indent . '}' . $matches['end']; + }, $this->contents); - // we have a subname, so we restore the rest of $name - if ($subName !== null) { - $curVal = json_decode($children, true); - unset($curVal[$name][$subName]); - if ($curVal[$name] === []) { - $curVal[$name] = new \ArrayObject(); + // we have a subname, so we restore the rest of $name + if ($subName !== null) { + $curVal = json_decode($children, true); + unset($curVal[$name][$subName]); + if ($curVal[$name] === []) { + $curVal[$name] = new \ArrayObject(); + } + $this->addSubNode($mainNode, $name, $curVal[$name]); } - $this->addSubNode($mainNode, $name, $curVal[$name]); - } - return true; + return true; + } } $this->contents = Preg::replaceCallback($nodeRegex, function ($matches) use ($name, $subName, $childrenClean): string {