From a5bb14d244890bfb6bfe0b32e5e966a0324af80f Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 12 May 2020 21:29:50 +0200 Subject: [PATCH 1/5] Bump level to 4 --- lib/common/phpstan.neon.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/common/phpstan.neon.dist b/lib/common/phpstan.neon.dist index fb2b62bf871..0946588ab5d 100644 --- a/lib/common/phpstan.neon.dist +++ b/lib/common/phpstan.neon.dist @@ -2,7 +2,7 @@ includes: # @see https://github.com/phpstan/phpstan-src/blob/master/conf/bleedingEdge.neon - phar://phpstan.phar/conf/bleedingEdge.neon parameters: - level: 3 + level: 4 inferPrivatePropertyTypeFromConstructor: true paths: - %currentWorkingDirectory%/src/ From 82f7b02ca1f5b73a23508cfaa0bffe20a460e619 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 12 May 2020 21:48:49 +0200 Subject: [PATCH 2/5] Add additional null typehint --- lib/common/src/Dom/Document.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/common/src/Dom/Document.php b/lib/common/src/Dom/Document.php index 428e9c6f472..c7fc801e42f 100644 --- a/lib/common/src/Dom/Document.php +++ b/lib/common/src/Dom/Document.php @@ -1420,7 +1420,7 @@ public function deduplicateTag($tagName) /** * Main tag to keep. * - * @var DOMElement $mainTag + * @var DOMElement|null $mainTag */ $mainTag = $tags->item(0); From 8481781ecaca6f91acb1b57a9350bb94914e9cff Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 12 May 2020 21:49:50 +0200 Subject: [PATCH 3/5] Add additional null typehint --- lib/common/src/Exception/FailedToGetFromRemoteUrl.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/common/src/Exception/FailedToGetFromRemoteUrl.php b/lib/common/src/Exception/FailedToGetFromRemoteUrl.php index 015d1dca6b6..d05ae7f6767 100644 --- a/lib/common/src/Exception/FailedToGetFromRemoteUrl.php +++ b/lib/common/src/Exception/FailedToGetFromRemoteUrl.php @@ -18,7 +18,7 @@ final class FailedToGetFromRemoteUrl extends RuntimeException implements FailedR * * This is not always set. * - * @var int + * @var int|null */ private $statusCode; From 0cda75a8081b76fb9464216b287192909ddb651c Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 12 May 2020 21:50:48 +0200 Subject: [PATCH 4/5] Fix bug with status code comparison --- lib/common/src/RuntimeVersion.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/common/src/RuntimeVersion.php b/lib/common/src/RuntimeVersion.php index 9b359aea653..96db846fe59 100644 --- a/lib/common/src/RuntimeVersion.php +++ b/lib/common/src/RuntimeVersion.php @@ -78,7 +78,7 @@ public function currentVersion($options = []) $response = $this->remoteRequest->get(self::RUNTIME_METADATA_ENDPOINT); $statusCode = $response->getStatusCode(); - if (200 < $statusCode || $statusCode >= 300) { + if ($statusCode < 200 || $statusCode >= 300) { return '0'; } From ba20769f3e6b3ddd7cb066e9d529426da2ccd3cc Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 12 May 2020 22:04:47 +0200 Subject: [PATCH 5/5] Rewrite logic and add exception for false positive when checking libxml version --- lib/common/phpstan.neon.dist | 4 ++++ lib/common/src/Dom/Document.php | 36 ++++++++++++++++----------------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/lib/common/phpstan.neon.dist b/lib/common/phpstan.neon.dist index 0946588ab5d..841272db310 100644 --- a/lib/common/phpstan.neon.dist +++ b/lib/common/phpstan.neon.dist @@ -10,3 +10,7 @@ parameters: - %currentWorkingDirectory%/vendor/autoload.php ignoreErrors: - '#^PHPDoc tag @throws with type AmpProject\\Exception\\FailedRemoteRequest is not subtype of Throwable$#' + - + message: '#^If condition is always false\.$#' + path: 'src/Dom/Document.php' + # See https://github.com/phpstan/phpstan/issues/3291 diff --git a/lib/common/src/Dom/Document.php b/lib/common/src/Dom/Document.php index c7fc801e42f..4ffc1c079b1 100644 --- a/lib/common/src/Dom/Document.php +++ b/lib/common/src/Dom/Document.php @@ -847,26 +847,26 @@ private function restoreSelfClosingTags($html) */ private function maybeReplaceNoscriptElements($html) { - if (! version_compare(LIBXML_DOTTED_VERSION, '2.8', '<')) { - return $html; + if (version_compare(LIBXML_DOTTED_VERSION, '2.8', '<')) { + $html = preg_replace_callback( + '#^.+?(?=]*>.*?#si', + function ($noscriptMatches) { + $placeholder = sprintf('', (string)$this->rand()); + + $this->noscriptPlaceholderComments[$placeholder] = $noscriptMatches[0]; + return $placeholder; + }, + $headMatches[0] + ); + }, + $html + ); } - return preg_replace_callback( - '#^.+?(?=]*>.*?#si', - function ($noscriptMatches) { - $placeholder = sprintf('', (string)$this->rand()); - - $this->noscriptPlaceholderComments[$placeholder] = $noscriptMatches[0]; - return $placeholder; - }, - $headMatches[0] - ); - }, - $html - ); + return $html; } /**