Skip to content

Commit

Permalink
Raise PHPStan level to 4 in lib/common (#4686)
Browse files Browse the repository at this point in the history
* Bump level to 4

* Add additional null typehint

* Add additional null typehint

* Fix bug with status code comparison

* Rewrite logic and add exception for false positive when checking libxml version
  • Loading branch information
schlessera authored May 15, 2020
1 parent 69b78da commit 83d7964
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 22 deletions.
6 changes: 5 additions & 1 deletion lib/common/phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ 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/
autoload_files:
- %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
38 changes: 19 additions & 19 deletions lib/common/src/Dom/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
'#^.+?(?=<body)#is',
function ($headMatches) {
return preg_replace_callback(
'#<noscript[^>]*>.*?</noscript>#si',
function ($noscriptMatches) {
$placeholder = sprintf('<!--noscript:%s-->', (string)$this->rand());

$this->noscriptPlaceholderComments[$placeholder] = $noscriptMatches[0];
return $placeholder;
},
$headMatches[0]
);
},
$html
);
}

return preg_replace_callback(
'#^.+?(?=<body)#is',
function ($headMatches) {
return preg_replace_callback(
'#<noscript[^>]*>.*?</noscript>#si',
function ($noscriptMatches) {
$placeholder = sprintf('<!--noscript:%s-->', (string)$this->rand());

$this->noscriptPlaceholderComments[$placeholder] = $noscriptMatches[0];
return $placeholder;
},
$headMatches[0]
);
},
$html
);
return $html;
}

/**
Expand Down Expand Up @@ -1420,7 +1420,7 @@ public function deduplicateTag($tagName)
/**
* Main tag to keep.
*
* @var DOMElement $mainTag
* @var DOMElement|null $mainTag
*/
$mainTag = $tags->item(0);

Expand Down
2 changes: 1 addition & 1 deletion lib/common/src/Exception/FailedToGetFromRemoteUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class FailedToGetFromRemoteUrl extends RuntimeException implements FailedR
*
* This is not always set.
*
* @var int
* @var int|null
*/
private $statusCode;

Expand Down
2 changes: 1 addition & 1 deletion lib/common/src/RuntimeVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

Expand Down

0 comments on commit 83d7964

Please sign in to comment.