Skip to content

Commit

Permalink
Merge pull request #4879 from ampproject/update/phpstan-1.5
Browse files Browse the repository at this point in the history
Cherry-pick: Use latest PHPStan version to run its tests and replace deprecated autoload_files option
  • Loading branch information
westonruter committed Jun 17, 2020
2 parents 33383c1 + c05ea1e commit c5603dc
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 70 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"extra": {
"downloads": {
"phpstan": {
"url": "https://github.com/phpstan/phpstan/releases/download/0.12.14/phpstan.phar",
"url": "https://github.com/phpstan/phpstan/raw/master/phpstan.phar",
"path": "vendor/bin/phpstan",
"type": "phar"
}
Expand Down Expand Up @@ -102,6 +102,6 @@
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"analyze": "if [ -z $TEST_SKIP_PHPSTAN ]; then phpstan analyze --ansi; fi"
"analyze": "if [ -z $TEST_SKIP_PHPSTAN ]; then phpstan --version; phpstan analyze --ansi; fi"
}
}
106 changes: 66 additions & 40 deletions composer.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion includes/class-amp-comment-walker.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,11 @@ public function start_el( &$output, $comment, $depth = 0, $args = [], $id = 0 )
* @param int $max_depth The maximum hierarchical depth.
* @param int $page_num The specific page number, beginning with 1.
* @param int $per_page Per page counter.
* @param mixed ...$args Optional additional arguments.
*
* @return string XHTML of the specified page of elements.
*/
public function paged_walk( $elements, $max_depth, $page_num, $per_page ) {
public function paged_walk( $elements, $max_depth, $page_num, $per_page, ...$args ) {
if ( empty( $elements ) || $max_depth < -1 ) {
return '';
}
Expand Down
21 changes: 11 additions & 10 deletions includes/class-amp-theme-support.php
Original file line number Diff line number Diff line change
Expand Up @@ -1611,16 +1611,6 @@ public static function filter_admin_bar_script_loader_tag( $tag, $handle ) {
* @param string[] $script_handles AMP script handles for components identified during output buffering.
*/
public static function ensure_required_markup( Document $dom, $script_handles = [] ) {
/**
* Elements.
*
* @var DOMElement $meta
* @var DOMElement $script
* @var DOMElement $link
* @var DOMElement $style
* @var DOMElement $noscript
*/

// Gather all links.
$links = [
Attribute::REL_PRECONNECT => [
Expand All @@ -1636,6 +1626,11 @@ public static function ensure_required_markup( Document $dom, $script_handles =
],
];
$link_elements = $dom->head->getElementsByTagName( Tag::LINK );
/**
* Link element.
*
* @var DOMElement $link
*/
foreach ( $link_elements as $link ) {
if ( $link->hasAttribute( Attribute::REL ) ) {
$links[ $link->getAttribute( Attribute::REL ) ][] = $link;
Expand Down Expand Up @@ -1673,6 +1668,12 @@ public static function ensure_required_markup( Document $dom, $script_handles =
$ordered_scripts = [];
$head_scripts = [];
$runtime_src = wp_scripts()->registered[ Amp::RUNTIME ]->src;

/**
* Script element.
*
* @var DOMElement $script
*/
foreach ( $dom->head->getElementsByTagName( Tag::SCRIPT ) as $script ) { // Note that prepare_response() already moved body scripts to head.
$head_scripts[] = $script;
}
Expand Down
11 changes: 5 additions & 6 deletions includes/sanitizers/class-amp-link-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,6 @@ public function add_meta_tag( $content = self::DEFAULT_META_CONTENT ) {
* Process links by adding adding AMP query var to links in paired mode and adding rel=amphtml.
*/
public function process_links() {
/**
* Element.
*
* @var DOMElement $element
*/

// Remove admin bar from DOM to prevent mutating it.
$admin_bar_container = $this->dom->getElementById( 'wpadminbar' );
$admin_bar_placeholder = null;
Expand All @@ -144,6 +138,11 @@ public function process_links() {
$admin_bar_container->parentNode->replaceChild( $admin_bar_placeholder, $admin_bar_container );
}

/**
* Element.
*
* @var DOMElement $element
*/
foreach ( $this->dom->xpath->query( '//*[ local-name() = "a" or local-name() = "area" ]' ) as $element ) {
if ( ! $element->hasAttribute( 'href' ) ) {
continue;
Expand Down
4 changes: 2 additions & 2 deletions lib/common/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"downloads": {
"phpstan": {
"url": "https://github.com/phpstan/phpstan/releases/download/0.12.14/phpstan.phar",
"url": "https://github.com/phpstan/phpstan/raw/master/phpstan.phar",
"path": "vendor/bin/phpstan",
"type": "phar"
}
Expand All @@ -58,7 +58,7 @@
"@cs",
"@analyze"
],
"analyze": "if [ -z $TEST_SKIP_PHPSTAN ]; then phpstan analyze --ansi; fi",
"analyze": "if [ -z $TEST_SKIP_PHPSTAN ]; then phpstan --version; phpstan analyze --ansi; fi",
"unit": "if [ -z $TEST_SKIP_PHPUNIT ]; then phpunit --colors=always; fi"
}
}
8 changes: 1 addition & 7 deletions lib/common/phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ parameters:
level: 4
inferPrivatePropertyTypeFromConstructor: true
paths:
- %currentWorkingDirectory%/src/
autoload_files:
- %currentWorkingDirectory%/vendor/autoload.php
- src/
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
4 changes: 2 additions & 2 deletions lib/optimizer/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"downloads": {
"phpstan": {
"url": "https://github.com/phpstan/phpstan/releases/download/0.12.14/phpstan.phar",
"url": "https://github.com/phpstan/phpstan/raw/master/phpstan.phar",
"path": "vendor/bin/phpstan",
"type": "phar"
}
Expand Down Expand Up @@ -71,7 +71,7 @@
"@cs",
"@analyze"
],
"analyze": "if [ -z $TEST_SKIP_PHPSTAN ]; then phpstan analyze --ansi; fi",
"analyze": "if [ -z $TEST_SKIP_PHPSTAN ]; then phpstan --version; phpstan analyze --ansi; fi",
"unit": "if [ -z $TEST_SKIP_PHPUNIT ]; then phpunit --colors=always; fi",
"update-test-specs": "rm -rf tests/spec && bin/sync-amp-toolbox-test-suite.php"
}
Expand Down
4 changes: 4 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ parameters:
ignoreErrors:
# Uses func_get_args()
- '#^Function apply_filters(_ref_array)? invoked with [34567] parameters, 2 required\.$#'
# Missing declaration in PHPStan/PHPStorm stubs
# See https://github.com/phpstan/phpstan/issues/3492
# and https://github.com/JetBrains/phpstorm-stubs/pull/845
- '#^Access to an undefined property DOMNamedNodeMap::\$length.$#'

0 comments on commit c5603dc

Please sign in to comment.