From a9f8e18dd4460b9e6c15da26ae6f994f5f95f036 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 26 May 2021 19:18:58 +0200 Subject: [PATCH 1/7] RectorsChangelogResolver: fix tests on windows --- .../ChangesReporting/Annotation/RectorsChangelogResolver.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/ChangesReporting/Annotation/RectorsChangelogResolver.php b/packages/ChangesReporting/Annotation/RectorsChangelogResolver.php index eb3bc3e1f60..721a5a12e8c 100644 --- a/packages/ChangesReporting/Annotation/RectorsChangelogResolver.php +++ b/packages/ChangesReporting/Annotation/RectorsChangelogResolver.php @@ -32,6 +32,11 @@ public function resolveIncludingMissing(array $rectorClasses): array $rectorClassesToChangelogUrls = []; foreach ($rectorClasses as $rectorClass) { $changelogUrl = $this->annotationExtractor->extractAnnotationFromClass($rectorClass, '@changelog'); + + if ($changelogUrl) { + $changelogUrl = trim($changelogUrl); + } + $rectorClassesToChangelogUrls[$rectorClass] = $changelogUrl; } From a29aedfe87c0704aca564e8055a5eccba707d5b5 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 26 May 2021 19:21:06 +0200 Subject: [PATCH 2/7] Revert "RectorsChangelogResolver: fix tests on windows" This reverts commit a9f8e18dd4460b9e6c15da26ae6f994f5f95f036. --- .../ChangesReporting/Annotation/RectorsChangelogResolver.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/ChangesReporting/Annotation/RectorsChangelogResolver.php b/packages/ChangesReporting/Annotation/RectorsChangelogResolver.php index 721a5a12e8c..eb3bc3e1f60 100644 --- a/packages/ChangesReporting/Annotation/RectorsChangelogResolver.php +++ b/packages/ChangesReporting/Annotation/RectorsChangelogResolver.php @@ -32,11 +32,6 @@ public function resolveIncludingMissing(array $rectorClasses): array $rectorClassesToChangelogUrls = []; foreach ($rectorClasses as $rectorClass) { $changelogUrl = $this->annotationExtractor->extractAnnotationFromClass($rectorClass, '@changelog'); - - if ($changelogUrl) { - $changelogUrl = trim($changelogUrl); - } - $rectorClassesToChangelogUrls[$rectorClass] = $changelogUrl; } From 0cf42773174c3867470a70fc7d7189f620267e7e Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 26 May 2021 19:21:11 +0200 Subject: [PATCH 3/7] Update AnnotationExtractor.php --- packages/ChangesReporting/Annotation/AnnotationExtractor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ChangesReporting/Annotation/AnnotationExtractor.php b/packages/ChangesReporting/Annotation/AnnotationExtractor.php index 418b163014f..ef52c217164 100644 --- a/packages/ChangesReporting/Annotation/AnnotationExtractor.php +++ b/packages/ChangesReporting/Annotation/AnnotationExtractor.php @@ -28,6 +28,6 @@ public function extractAnnotationFromClass(string $className, string $annotation // @see https://regex101.com/r/oYGaWU/1 $pattern = '#' . preg_quote($annotation, '#') . '\s+(?.*?)$#m'; $matches = Strings::match($docComment, $pattern); - return $matches['content'] ?? null; + return trim($matches['content']) ?? null; } } From 8ab6e7dbd43cc1c0633508aafa70ba8f4a243dbd Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 26 May 2021 19:23:32 +0200 Subject: [PATCH 4/7] prevent trim-on-null errors --- .../ChangesReporting/Annotation/AnnotationExtractor.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/ChangesReporting/Annotation/AnnotationExtractor.php b/packages/ChangesReporting/Annotation/AnnotationExtractor.php index ef52c217164..33bffee8ec8 100644 --- a/packages/ChangesReporting/Annotation/AnnotationExtractor.php +++ b/packages/ChangesReporting/Annotation/AnnotationExtractor.php @@ -28,6 +28,10 @@ public function extractAnnotationFromClass(string $className, string $annotation // @see https://regex101.com/r/oYGaWU/1 $pattern = '#' . preg_quote($annotation, '#') . '\s+(?.*?)$#m'; $matches = Strings::match($docComment, $pattern); - return trim($matches['content']) ?? null; + + if ($matches && $matches['content']) { + return trim($matches['content']); + } + return null; } } From 29b75e676811962a68e36a4c7accb24702ac0e5e Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 26 May 2021 21:58:29 +0200 Subject: [PATCH 5/7] Update AnnotationExtractor.php --- packages/ChangesReporting/Annotation/AnnotationExtractor.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/ChangesReporting/Annotation/AnnotationExtractor.php b/packages/ChangesReporting/Annotation/AnnotationExtractor.php index 33bffee8ec8..b2848458554 100644 --- a/packages/ChangesReporting/Annotation/AnnotationExtractor.php +++ b/packages/ChangesReporting/Annotation/AnnotationExtractor.php @@ -29,8 +29,8 @@ public function extractAnnotationFromClass(string $className, string $annotation $pattern = '#' . preg_quote($annotation, '#') . '\s+(?.*?)$#m'; $matches = Strings::match($docComment, $pattern); - if ($matches && $matches['content']) { - return trim($matches['content']); + if ($matches && isset($matches['content'])) { + return rtrim($matches['content']); } return null; } From 8271fd4c1d1d3f5b896001ed7b1057f1b4ef98d1 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 27 May 2021 21:21:57 +0200 Subject: [PATCH 6/7] Update packages/ChangesReporting/Annotation/AnnotationExtractor.php --- packages/ChangesReporting/Annotation/AnnotationExtractor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ChangesReporting/Annotation/AnnotationExtractor.php b/packages/ChangesReporting/Annotation/AnnotationExtractor.php index b2848458554..46323309c04 100644 --- a/packages/ChangesReporting/Annotation/AnnotationExtractor.php +++ b/packages/ChangesReporting/Annotation/AnnotationExtractor.php @@ -29,7 +29,7 @@ public function extractAnnotationFromClass(string $className, string $annotation $pattern = '#' . preg_quote($annotation, '#') . '\s+(?.*?)$#m'; $matches = Strings::match($docComment, $pattern); - if ($matches && isset($matches['content'])) { + if ($matches) { return rtrim($matches['content']); } return null; From e1a0df7e634d0dd08ce721508290a2322dff01f7 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 27 May 2021 21:36:59 +0200 Subject: [PATCH 7/7] Update AnnotationExtractor.php --- .../Annotation/AnnotationExtractor.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/ChangesReporting/Annotation/AnnotationExtractor.php b/packages/ChangesReporting/Annotation/AnnotationExtractor.php index 46323309c04..013e32c82c8 100644 --- a/packages/ChangesReporting/Annotation/AnnotationExtractor.php +++ b/packages/ChangesReporting/Annotation/AnnotationExtractor.php @@ -25,13 +25,11 @@ public function extractAnnotationFromClass(string $className, string $annotation return null; } - // @see https://regex101.com/r/oYGaWU/1 - $pattern = '#' . preg_quote($annotation, '#') . '\s+(?.*?)$#m'; + // @see https://3v4l.org/ouYfB + // uses '\r?\n' instead of '$' because windows compat + $pattern = '#' . preg_quote($annotation, '#') . '\s+(?.*?)\r?\n#m'; $matches = Strings::match($docComment, $pattern); - if ($matches) { - return rtrim($matches['content']); - } - return null; + return $matches['content'] ?? null; } }