Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise PHPStan level to 4 in lib/common #4686

Merged
merged 5 commits into from
May 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume your PR on the phpstan repo (phpstan/phpstan-src#203) fixes this. Once a new release is made with that change we should be able to remove this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. The general idea is to update to latest PHPStan and revisit the exceptions here each time we bump the level.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW I think PHPStan will complain if an exception is no longer encountered. In other words, it will tell you that you can remove it :-)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, indeed, it does.

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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bug means that the fallback stylesheet would almost always be used?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we should backport this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. Then I'll squash merge and cherry-pick.

return '0';
}

Expand Down