Skip to content

Commit

Permalink
Merge pull request #551 from swissspidy/fix/549-php84
Browse files Browse the repository at this point in the history
Improve PHP 8.4 compatibility
  • Loading branch information
westonruter authored Oct 17, 2024
2 parents 7853185 + 3d8dd37 commit b206168
Show file tree
Hide file tree
Showing 16 changed files with 28 additions and 28 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['8.2', '8.1', '7.4', '7.3', '7.2', '7.1', '7.0', '5.6']
php: ['8.3', '8.1', '8.0', '7.4']
coverage: [false]
random: [false]
include:
- php: '8.0'
- php: '8.2'
coverage: true
- php: '8.0'
- php: '8.2'
random: true
- php: '8.3'
- php: '8.4'
experimental: true

steps:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "A collection of AMP tools making it easier to publish and host AMP pages with PHP.",
"license": "Apache-2.0",
"require": {
"php": "^5.6 || ^7.0 || ^8.0",
"php": "^7.4 || ^8.0",
"ext-dom": "*",
"ext-filter": "*",
"ext-iconv": "*",
Expand Down
2 changes: 1 addition & 1 deletion src/Cli/Executable.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ abstract class Executable
* @param Colors|null $colors Optional. Instance of the Colors object to use. Defaults to null to instantiate a
* new one.
*/
public function __construct($autocatch = true, Options $options = null, Colors $colors = null)
public function __construct($autocatch = true, ?Options $options = null, ?Colors $colors = null)
{
if ($autocatch) {
set_exception_handler([$this, 'fatal']);
Expand Down
2 changes: 1 addition & 1 deletion src/Cli/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Options
* @param Colors $colors Optional. Configured color object.
* @throws InvalidArgument When arguments can't be read.
*/
public function __construct(Colors $colors = null)
public function __construct(?Colors $colors = null)
{
$this->colors = $colors instanceof Colors ? $colors : new Colors();

Expand Down
2 changes: 1 addition & 1 deletion src/Cli/TableFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class TableFormatter
*
* @param Colors|null $colors Optional. Instance of the Colors helper object.
*/
public function __construct(Colors $colors = null)
public function __construct(?Colors $colors = null)
{
// Try to get terminal width.
$width = $this->getTerminalWidth();
Expand Down
2 changes: 1 addition & 1 deletion src/CssLength.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function validate($allowAuto, $allowFluid)
if (preg_match($pattern, $this->attrValue, $match)) {
$this->isValid = true;
$this->numeral = isset($match['numeral']) ? (float)$match['numeral'] : $this->numeral;

Check failure on line 114 in src/CssLength.php

View workflow job for this annotation

GitHub Actions / Static analysis / PHP 8.0

Offset 'numeral' on array{0: string, numeral: non-empty-string, 1: non-empty-string, unit?: 'em'|'px'|'rem'|'vh'|'vmax'|'vmin'|'vw', 2?: 'em'|'px'|'rem'|'vh'|'vmax'|'vmin'|'vw'} in isset() always exists and is not nullable.
$this->unit = isset($match['unit']) ? $match['unit'] : $this->unit;
$this->unit = $match['unit'] ?? $this->unit;
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/Dom/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public static function fromHtml($html, $options = [])
$options = [Option::ENCODING => $options];
}

$encoding = isset($options[Option::ENCODING]) ? $options[Option::ENCODING] : null;
$encoding = $options[ Option::ENCODING ] ?? null;

$dom = new self('', $encoding);

Expand Down Expand Up @@ -258,7 +258,7 @@ public static function fromHtmlFragment($html, $options = [])
$options = [Option::ENCODING => $options];
}

$encoding = isset($options[Option::ENCODING]) ? $options[Option::ENCODING] : null;
$encoding = $options[ Option::ENCODING ] ?? null;

$dom = new self('', $encoding);

Expand Down Expand Up @@ -413,7 +413,7 @@ public function loadHTMLFragment($source, $options = [])
* @return string The HTML, or false if an error occurred.
*/
#[\ReturnTypeWillChange]
public function saveHTML(DOMNode $node = null)
public function saveHTML(?DOMNode $node = null)
{
return $this->saveHTMLFragment($node);
}
Expand All @@ -424,7 +424,7 @@ public function saveHTML(DOMNode $node = null)
* @param DOMNode|null $node Optional. Parameter to output a subset of the document.
* @return string The HTML fragment, or false if an error occurred.
*/
public function saveHTMLFragment(DOMNode $node = null)
public function saveHTMLFragment(?DOMNode $node = null)
{
$filtersInReverse = array_reverse($this->filters);

Expand Down Expand Up @@ -551,7 +551,7 @@ private function normalizeDocumentStructure($content)
$content = preg_replace(self::HTML_STRUCTURE_HTML_START_TAG, '', $content, 1);

preg_match(self::HTML_STRUCTURE_HTML_END_TAG, $content, $matches);
$htmlEnd = isset($matches['html_end']) ? $matches['html_end'] : $htmlEnd;
$htmlEnd = $matches['html_end'] ?? $htmlEnd;
$content = preg_replace(self::HTML_STRUCTURE_HTML_END_TAG, '', $content, 1);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Dom/Document/Filter/AmpBindAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public function afterSave($html)
||
in_array($attrName, $this->convertedAmpBindAttributes, true)
) {
$attrValue = isset($attrMatches['value']) ? $attrMatches['value'] : '=""';
$attrValue = $attrMatches['value'] ?? '=""';
$newAttrs .= " [{$attrName}]{$attrValue}";
} else {
$newAttrs .= $attrMatches[0];
Expand Down
2 changes: 1 addition & 1 deletion src/Dom/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function offsetUnset($option)
#[\ReturnTypeWillChange]
public function offsetGet($option)
{
return isset($this->options[$option]) ? $this->options[$option] : null;
return $this->options[ $option ] ?? null;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Optimizer/Error/CannotPreloadImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class CannotPreloadImage implements Error
* @param Element|null $element Optional. Image element that has the srcset attribute, or null if no element.
* @return self
*/
public static function fromImageWithSrcsetAttribute(Element $element = null)
public static function fromImageWithSrcsetAttribute(?Element $element = null)
{
$message = self::SRCSET_STRING;

Expand Down
10 changes: 5 additions & 5 deletions src/Optimizer/TransformationEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ final class TransformationEngine
* @param Configuration|null $configuration Optional. Configuration data to use for setting up the transformers.
* @param RemoteGetRequest|null $remoteRequest Optional. Transport to use for remote requests. Defaults to the
* CurlRemoteGetRequest implementation shipped with the library.
* @param Spec $spec Optional. Validator spec instance to use.
* @param Spec|null $spec Optional. Validator spec instance to use.
*/
public function __construct(
Configuration $configuration = null,
RemoteGetRequest $remoteRequest = null,
Spec $spec = null
?Configuration $configuration = null,
?RemoteGetRequest $remoteRequest = null,
?Spec $spec = null
) {
$this->configuration = isset($configuration) ? $configuration : new DefaultConfiguration();
$this->configuration = $configuration ?? new DefaultConfiguration();
$this->remoteRequest = $remoteRequest;
$this->spec = $spec;

Expand Down
2 changes: 1 addition & 1 deletion src/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ final class Url
* @param Url|null $baseUrl Base URL.
* @throws FailedToParseUrl Exception when the URL or Base URL is malformed.
*/
public function __construct($url = null, Url $baseUrl = null)
public function __construct($url = null, ?Url $baseUrl = null)
{
$parsedUrl = [];

Expand Down
2 changes: 1 addition & 1 deletion src/Validator/ValidationHandler.php

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

4 changes: 2 additions & 2 deletions src/Validator/ValidationResult.php

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

2 changes: 1 addition & 1 deletion src/Validator/ValidatorRules.php

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

2 changes: 1 addition & 1 deletion tests/Optimizer/TransformationEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function testDependencyResolution($transformerClass)
* @param Configuration|null $configuration Optional. Configuration object to use.
* @return TransformationEngine Transformation engine instance to test against.
*/
private function getTransformationEngine(Configuration $configuration = null)
private function getTransformationEngine(?Configuration $configuration = null)
{
return new TransformationEngine(
$configuration,
Expand Down

0 comments on commit b206168

Please sign in to comment.