Skip to content
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
17 changes: 13 additions & 4 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
version: 2
updates:
- package-ecosystem: composer
directory: "/"
directory: '/'
schedule:
interval: daily
time: "12:00"
timezone: America/Los_Angeles
interval: monthly
open-pull-requests-limit: 10
- package-ecosystem: github-actions
directory: '/'
schedule:
interval: monthly
open-pull-requests-limit: 10
labels:
- Dependencies
groups:
github-actions:
patterns:
- '*'
2 changes: 1 addition & 1 deletion .github/workflows/sync-local-fallback-files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Configure Composer cache
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sync-spec-test-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Configure Composer cache
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ jobs:
coverage: [false]
random: [false]
include:
- php: '8.2'
- php: '8.4'
coverage: true
- php: '8.2'
random: true
- php: '8.4'
random: true
- php: '8.5'
experimental: true

steps:
Expand All @@ -41,7 +41,7 @@ jobs:
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Configure Composer cache
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
Expand Down Expand Up @@ -98,7 +98,7 @@ jobs:
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Configure Composer cache
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
Expand Down Expand Up @@ -137,7 +137,7 @@ jobs:
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Configure Composer cache
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"require-dev": {
"ext-zip": "*",
"civicrm/composer-downloads-plugin": "^2.1 || ^3.0",
"civicrm/composer-downloads-plugin": "^4.0",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.1 || ^1.0.0",
"mikey179/vfsstream": "^1.6",
"php-parallel-lint/php-parallel-lint": "^1.2",
Expand All @@ -22,7 +22,7 @@
"roave/security-advisories": "dev-master",
"sirbrillig/phpcs-variable-analysis": "^2.11.2",
"squizlabs/php_codesniffer": "^3",
"wp-coding-standards/wpcs": "^2.3",
"wp-coding-standards/wpcs": "^3.2",
"yoast/phpunit-polyfills": "^0.2.0 || ^1.0.0"
},
"suggest": {
Expand Down Expand Up @@ -81,8 +81,8 @@
"sync-fallback-files": "bin/sync-amp-runtime-local-fallback-resources.php",
"sync-test-specs": "rm -rf tests/spec && bin/sync-amp-toolbox-test-suite.php",
"sync": [
"sync-fallback-files",
"sync-test-specs"
"@sync-fallback-files",
"@sync-test-specs"
]
}
}
5 changes: 2 additions & 3 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ includes:
parameters:
level: 5
inferPrivatePropertyTypeFromConstructor: true
treatPhpDocTypesAsCertain: false
paths:
- include/
- src/
ignoreErrors:
- '#^PHPDoc tag @throws with type AmpProject\\Exception\\FailedRemoteRequest is not subtype of Throwable$#'
- '#^Parameter \#1 (\$exception_handler|\$callback) of function set_exception_handler expects#'

# @see https://github.com/phpstan/phpstan/issues/5655
- '#^PHPDoc tag @var for constant (?:.*) with type array(?:.*) is not subtype of value array(?:.*)\.$#'
excludePaths:
analyse:
- src/FakeEnum.php
Expand All @@ -22,3 +20,4 @@ parameters:
- src/Validator/ValidationErrorCollection.php
- src/Validator/ValidationHandler.php
- src/Validator/ValidatorRules.php
- src/Validator/Spec
2 changes: 1 addition & 1 deletion resources/local_fallback/rtv/metadata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/Cli/AmpExecutable.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ protected function setup(Options $options)
{
foreach (self::COMMAND_CLASSES as $commandClass) {
/** @var Command $command */
// @phpstan-ignore varTag.nativeType
$command = new $commandClass($this);

$command->register($options);
Expand Down
2 changes: 0 additions & 2 deletions src/Cli/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,6 @@ private function readPHPArgv()
}

if (
is_array($_SERVER)
&&
array_key_exists('argv', $_SERVER)
&&
is_array($_SERVER['argv'])
Expand Down
2 changes: 1 addition & 1 deletion src/CssLength.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function validate($allowAuto, $allowFluid)
$pattern = '/^(?<numeral>\d+(?:\.\d+)?)(?<unit>px|em|rem|vh|vw|vmin|vmax)?$/';
if (preg_match($pattern, $this->attrValue, $match)) {
$this->isValid = true;
$this->numeral = isset($match['numeral']) ? (float)$match['numeral'] : $this->numeral;
$this->numeral = (float)$match['numeral'];
$this->unit = $match['unit'] ?? $this->unit;
}
}
Expand Down
57 changes: 5 additions & 52 deletions src/Dom/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -434,11 +434,7 @@ public function saveHTMLFragment(?DOMNode $node = null)
}
}

if (null === $node || PHP_VERSION_ID >= 70300) {
$html = parent::saveHTML($node);
} else {
$html = $this->extractNodeViaFragmentBoundaries($node);
}
$html = parent::saveHTML($node);

foreach ($filtersInReverse as $filter) {
if ($filter instanceof AfterSaveFilter) {
Expand Down Expand Up @@ -474,43 +470,6 @@ private function insertMissingCharset()
$this->head->insertBefore($charset, $this->head->firstChild);
}

/**
* Extract a node's HTML via fragment boundaries.
*
* Temporarily adds fragment boundary comments in order to locate the desired node to extract from
* the given HTML document. This is required because libxml seems to only preserve whitespace when
* serializing when calling DOMDocument::saveHTML() on the entire document. If you pass the element
* to DOMDocument::saveHTML() then formatting whitespace gets added unexpectedly. This is seen to
* be fixed in PHP 7.3, but for older versions of PHP the following workaround is needed.
*
* @param DOMNode $node Node to extract the HTML for.
* @return string Extracted HTML string.
*/
private function extractNodeViaFragmentBoundaries(DOMNode $node)
{
$boundary = $this->uniqueIdManager->getUniqueId('fragment_boundary');
$startBoundary = $boundary . ':start';
$endBoundary = $boundary . ':end';
$commentStart = $this->createComment($startBoundary);
$commentEnd = $this->createComment($endBoundary);

$node->parentNode->insertBefore($commentStart, $node);
$node->parentNode->insertBefore($commentEnd, $node->nextSibling);

$pattern = '/^.*?'
. preg_quote("<!--{$startBoundary}-->", '/')
. '(.*)'
. preg_quote("<!--{$endBoundary}-->", '/')
. '.*?\s*$/s';

$html = preg_replace($pattern, '$1', parent::saveHTML());

$node->parentNode->removeChild($commentStart);
$node->parentNode->removeChild($commentEnd);

return $html;
}

/**
* Normalize the document structure.
*
Expand Down Expand Up @@ -1144,16 +1103,10 @@ private function instantiateFilter($filterClass)
foreach ($parameters as $parameter) {
$dependencyType = null;

// The use of `ReflectionParameter::getClass()` is deprecated in PHP 8, and is superseded
// by `ReflectionParameter::getType()`. See https://github.com/php/php-src/pull/5209.
if (PHP_VERSION_ID >= 70100) {
if ($parameter->getType()) {
/** @var ReflectionNamedType $returnType */
$returnType = $parameter->getType();
$dependencyType = new ReflectionClass($returnType->getName());
}
} else {
$dependencyType = $parameter->getClass();
if ($parameter->getType()) {
/** @var ReflectionNamedType $returnType */
$returnType = $parameter->getType();
$dependencyType = new ReflectionClass($returnType->getName());
}

if ($dependencyType === null) {
Expand Down
2 changes: 2 additions & 0 deletions src/Dom/Document/Filter/MustacheScriptTemplates.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ static function ($matches) use ($mustacheTagPlaceholders) {
// entities. In the case of a URL value like '/foo/?bar=1&baz=2' the result is a warning for an
// unterminated entity reference "baz". When the attribute value is updated via setAttribute() this
// same problem does not occur, so that is why the following is used.

// @phpstan-ignore method.notFound
$attribute->parentNode->setAttribute($attribute->nodeName, $value);

$this->mustacheTagsReplaced = true;
Expand Down
6 changes: 3 additions & 3 deletions src/Dom/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function addInlineStyle($style, $prepend = false)
* @return DOMAttr|false The new or modified DOMAttr or false if an error occurred.
* @throws MaxCssByteCountExceeded If the allowed max byte count is exceeded.
*/
public function setAttribute($name, $value)
public function setAttribute($name, $value) // @phpstan-ignore return.unusedType
{
// Make sure $value is always a string and not null.
$value = strval($value);
Expand Down Expand Up @@ -191,7 +191,7 @@ public static function mergeAmpActions($first, $second)
$matches = [];
$results = preg_match_all(self::AMP_EVENT_ACTIONS_REGEX_PATTERN, $eventActionString, $matches);

if (! $results || ! isset($matches['event'])) {
if (! $results) {
continue;
}

Expand All @@ -209,7 +209,7 @@ static function ($actions) use (&$actionsArray) {
$matches = [];
$results = preg_match_all(self::AMP_ACTION_REGEX_PATTERN, $actions, $matches);

if (! $results || ! isset($matches['action'])) {
if (! $results) {
$actionsArray[] = $actions;
return;
}
Expand Down
7 changes: 0 additions & 7 deletions src/Html/Parser/ParsedTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,6 @@ public function __construct($tagName, $alternatingAttributes = [])

// Sort the attribute array by (lower case) name.
usort($this->attributes, function (ParsedAttribute $a, ParsedAttribute $b) {
if (PHP_MAJOR_VERSION < 7 && $a->name() === $b->name()) {
// Hack required for PHP 5.6, as it does not maintain stable order for equal items.
// See https://bugs.php.net/bug.php?id=69158.
// To get around this, we compare the index within $this->attributes instead to maintain existing order.
return strcmp(array_search($a, $this->attributes, true), array_search($b, $this->attributes, true));
}

return strcmp($a->name(), $b->name());
});

Expand Down
4 changes: 2 additions & 2 deletions src/Optimizer/ImageDimensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ final class ImageDimensions
/**
* Unit of the width of the image.
*
* @var int|float|string|null
* @var string|null
*/
private $widthUnit;

/**
* Unit of the height of the image.
*
* @var int|float|string|null
* @var string|null
*/
private $heightUnit;

Expand Down
14 changes: 4 additions & 10 deletions src/Optimizer/TransformationEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,10 @@ private function getTransformerDependencies($transformerClass)
foreach ($constructor->getParameters() as $parameter) {
$dependencyType = null;

// The use of `ReflectionParameter::getClass()` is deprecated in PHP 8, and is superseded
// by `ReflectionParameter::getType()`. See https://github.com/php/php-src/pull/5209.
if (PHP_VERSION_ID >= 70100) {
if ($parameter->getType()) {
/** @var \ReflectionNamedType $returnType */
$returnType = $parameter->getType();
$dependencyType = new ReflectionClass($returnType->getName());
}
} else {
$dependencyType = $parameter->getClass();
if ($parameter->getType()) {
/** @var \ReflectionNamedType $returnType */
$returnType = $parameter->getType();
$dependencyType = new ReflectionClass($returnType->getName());
}

if ($dependencyType === null) {
Expand Down
1 change: 1 addition & 0 deletions src/Optimizer/Transformer/OptimizeViewport.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public function transform(Document $document, ErrorCollection $errors)
// Merge one or more meta[name=viewport] tags into one.
$parsedRules = [];

/** @var \DOMElement $metaTag */
foreach ($metaTags as $metaTag) {
$propertyPairs = explode(',', $metaTag->getAttribute('content'));

Expand Down
4 changes: 3 additions & 1 deletion src/RemoteRequest/CurlRemoteGetRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ static function ($curl, $header) use (&$headers) {
$status = curl_getinfo($curlHandle, CURLINFO_HTTP_CODE);

$curlErrno = curl_errno($curlHandle);
curl_close($curlHandle);
if (PHP_VERSION_ID < 80000) {
curl_close($curlHandle);
}

if ($body === false || $status < 200 || $status >= 300) {
if (! $retriesLeft || in_array($curlErrno, self::RETRYABLE_ERROR_CODES, true) === false) {
Expand Down
7 changes: 1 addition & 6 deletions src/RemoteRequest/TemporaryFileCachedRemoteGetRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,7 @@ public function get($url, $headers = [])

// phpcs:disable PHPCompatibility.FunctionUse.NewFunctionParameters.unserialize_optionsFound
if ($cachedResponse !== false) {
if (PHP_MAJOR_VERSION >= 7) {
$cachedResponse = unserialize($cachedResponse, [RemoteGetRequestResponse::class]);
} else {
// PHP 5.6 does not provide the second $options argument yet.
$cachedResponse = unserialize($cachedResponse);
}
$cachedResponse = unserialize($cachedResponse, [RemoteGetRequestResponse::class]);
}
// phpcs:enable PHPCompatibility.FunctionUse.NewFunctionParameters.unserialize_optionsFound

Expand Down
7 changes: 0 additions & 7 deletions src/Validator/ValidationErrorCollection.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/Validator/ValidationSeverity.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/Validator/ValidationStatus.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading