From 9dc8b1a698370691387b7bacc38524a1927ff95a Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Sat, 23 Mar 2024 13:59:07 +0100 Subject: [PATCH] Fixed nullable types for PHP 8.4 --- composer.json | 5 +++-- scripts/benchmarkRegexps.php | 2 +- src/Configurator/Helpers/FilterSyntaxMatcher.php | 6 +++--- src/Configurator/Helpers/TemplateInspector.php | 2 +- src/Configurator/Helpers/TemplateParser/IRProcessor.php | 4 ++-- src/Configurator/Helpers/TemplateParser/Optimizer.php | 2 +- src/Configurator/Items/Attribute.php | 2 +- src/Configurator/Items/AttributeFilters/ChoiceFilter.php | 2 +- src/Configurator/Items/AttributeFilters/HashmapFilter.php | 2 +- src/Configurator/Items/AttributeFilters/MapFilter.php | 2 +- src/Configurator/Items/Tag.php | 2 +- src/Configurator/JavaScript.php | 2 +- src/Configurator/RendererGenerators/PHP/XPathConvertor.php | 2 +- src/Configurator/TemplateChecker.php | 2 +- src/Configurator/TemplateNormalizer.php | 2 +- src/Parser/AttributeFilters/NumericFilter.php | 2 +- src/Parser/AttributeFilters/UrlFilter.php | 2 +- src/Plugins/BBCodes/Configurator/BBCode.php | 2 +- src/Plugins/MediaEmbed/Configurator.php | 2 +- tests/Parser/TagProcessingTest.php | 2 +- tests/Test.php | 2 +- 21 files changed, 26 insertions(+), 25 deletions(-) diff --git a/composer.json b/composer.json index 6b8f4177da..0f6337f661 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,8 @@ "require-dev": { "code-lts/doctum": "*", "matthiasmullie/minify": "*", - "phpunit/phpunit": "^9.5" + "phpunit/phpunit": "^9.5", + "friendsofphp/php-cs-fixer": "^3.52" }, "suggest": { "ext-curl": "Improves the performance of the MediaEmbed plugin and some JavaScript minifiers", @@ -45,4 +46,4 @@ "extra": { "version": "2.16.1-dev" } -} \ No newline at end of file +} diff --git a/scripts/benchmarkRegexps.php b/scripts/benchmarkRegexps.php index 269c58b555..743e3b1c5c 100644 --- a/scripts/benchmarkRegexps.php +++ b/scripts/benchmarkRegexps.php @@ -64,7 +64,7 @@ ]; benchmark($regexps, $input, ''); -function benchmark(array $regexps, string $input, string $replace = null) +function benchmark(array $regexps, string $input, ?string $replace = null) { foreach ($regexps as $regexp) { diff --git a/src/Configurator/Helpers/FilterSyntaxMatcher.php b/src/Configurator/Helpers/FilterSyntaxMatcher.php index 28b28731e6..302a68d844 100644 --- a/src/Configurator/Helpers/FilterSyntaxMatcher.php +++ b/src/Configurator/Helpers/FilterSyntaxMatcher.php @@ -119,7 +119,7 @@ public function parseArrayElement(string $key, string $value): array * @param string $otherElements * @return array */ - public function parseArrayElements(string $firstElement, string $otherElements = null) + public function parseArrayElements(string $firstElement, ?string $otherElements = null) { $elements = [$this->recurse($firstElement, 'ArrayElement')]; if (isset($otherElements)) @@ -171,7 +171,7 @@ public function parseFalse(): bool * @param string $args * @return array */ - public function parseFilterCallback(string $callback, string $args = null): array + public function parseFilterCallback(string $callback, ?string $args = null): array { $config = ['filter' => $callback]; if (isset($args)) @@ -187,7 +187,7 @@ public function parseFilterCallback(string $callback, string $args = null): arra * @param string $otherArgs * @return array */ - public function parseFilterArgs(string $firstArg, string $otherArgs = null) + public function parseFilterArgs(string $firstArg, ?string $otherArgs = null) { $parsedArg = $this->parser->parse($firstArg, 'FilterArg'); diff --git a/src/Configurator/Helpers/TemplateInspector.php b/src/Configurator/Helpers/TemplateInspector.php index 5611494ba1..940f4b1cc7 100644 --- a/src/Configurator/Helpers/TemplateInspector.php +++ b/src/Configurator/Helpers/TemplateInspector.php @@ -252,7 +252,7 @@ public function closesParent(TemplateInspector $parent) * @param DOMElement $node Context node * @return mixed */ - public function evaluate($expr, DOMElement $node = null) + public function evaluate($expr, ?DOMElement $node = null) { return $this->xpath->evaluate($expr, $node); } diff --git a/src/Configurator/Helpers/TemplateParser/IRProcessor.php b/src/Configurator/Helpers/TemplateParser/IRProcessor.php index 8cfbe6b109..db404e69f9 100644 --- a/src/Configurator/Helpers/TemplateParser/IRProcessor.php +++ b/src/Configurator/Helpers/TemplateParser/IRProcessor.php @@ -55,7 +55,7 @@ protected function createXPath(DOMDocument $dom) * @param DOMNode $node Context node * @return mixed */ - protected function evaluate($expr, DOMNode $node = null) + protected function evaluate($expr, ?DOMNode $node = null) { return (isset($node)) ? $this->xpath->evaluate($expr, $node) : $this->xpath->evaluate($expr); } @@ -67,7 +67,7 @@ protected function evaluate($expr, DOMNode $node = null) * @param DOMNode $node Context node * @return \DOMNodeList */ - protected function query($query, DOMNode $node = null) + protected function query($query, ?DOMNode $node = null) { return (isset($node)) ? $this->xpath->query($query, $node) : $this->xpath->query($query); } diff --git a/src/Configurator/Helpers/TemplateParser/Optimizer.php b/src/Configurator/Helpers/TemplateParser/Optimizer.php index a062bc19e1..41696c70ad 100644 --- a/src/Configurator/Helpers/TemplateParser/Optimizer.php +++ b/src/Configurator/Helpers/TemplateParser/Optimizer.php @@ -179,7 +179,7 @@ protected function removeEmptyDefaultCases() * @param DOMNode $contextNode * @return void */ - protected function removeNodes($query, DOMNode $contextNode = null) + protected function removeNodes($query, ?DOMNode $contextNode = null) { foreach ($this->query($query, $contextNode) as $node) { diff --git a/src/Configurator/Items/Attribute.php b/src/Configurator/Items/Attribute.php index 6f7b7ece8e..5c5add75bf 100644 --- a/src/Configurator/Items/Attribute.php +++ b/src/Configurator/Items/Attribute.php @@ -44,7 +44,7 @@ class Attribute implements ConfigProvider * * @param array $options This attribute's options */ - public function __construct(array $options = null) + public function __construct(?array $options = null) { $this->filterChain = new AttributeFilterChain; diff --git a/src/Configurator/Items/AttributeFilters/ChoiceFilter.php b/src/Configurator/Items/AttributeFilters/ChoiceFilter.php index 83ae7feca6..806bc18ba5 100644 --- a/src/Configurator/Items/AttributeFilters/ChoiceFilter.php +++ b/src/Configurator/Items/AttributeFilters/ChoiceFilter.php @@ -18,7 +18,7 @@ class ChoiceFilter extends RegexpFilter * @param array $values List of allowed values * @param bool $caseSensitive Whether the choice is case-sensitive */ - public function __construct(array $values = null, $caseSensitive = false) + public function __construct(?array $values = null, $caseSensitive = false) { parent::__construct(); diff --git a/src/Configurator/Items/AttributeFilters/HashmapFilter.php b/src/Configurator/Items/AttributeFilters/HashmapFilter.php index 0d3ce5e0a9..ef7e65420d 100644 --- a/src/Configurator/Items/AttributeFilters/HashmapFilter.php +++ b/src/Configurator/Items/AttributeFilters/HashmapFilter.php @@ -19,7 +19,7 @@ class HashmapFilter extends AbstractMapFilter * @param array $map Associative array in the form [key => value] * @param bool $strict Whether this map is strict (values with no match are invalid) */ - public function __construct(array $map = null, $strict = false) + public function __construct(?array $map = null, $strict = false) { parent::__construct('s9e\\TextFormatter\\Parser\\AttributeFilters\\HashmapFilter::filter'); diff --git a/src/Configurator/Items/AttributeFilters/MapFilter.php b/src/Configurator/Items/AttributeFilters/MapFilter.php index 02630622b5..9c5da31bc5 100644 --- a/src/Configurator/Items/AttributeFilters/MapFilter.php +++ b/src/Configurator/Items/AttributeFilters/MapFilter.php @@ -20,7 +20,7 @@ class MapFilter extends AbstractMapFilter * @param bool $caseSensitive Whether this map is case-sensitive * @param bool $strict Whether this map is strict (values with no match are invalid) */ - public function __construct(array $map = null, $caseSensitive = false, $strict = false) + public function __construct(?array $map = null, $caseSensitive = false, $strict = false) { parent::__construct('s9e\\TextFormatter\\Parser\\AttributeFilters\\MapFilter::filter'); diff --git a/src/Configurator/Items/Tag.php b/src/Configurator/Items/Tag.php index dbd8f4ffac..a680610a6f 100644 --- a/src/Configurator/Items/Tag.php +++ b/src/Configurator/Items/Tag.php @@ -71,7 +71,7 @@ class Tag implements ConfigProvider * * @param array $options This tag's options */ - public function __construct(array $options = null) + public function __construct(?array $options = null) { $this->attributes = new AttributeCollection; $this->attributePreprocessors = new AttributePreprocessorCollection; diff --git a/src/Configurator/JavaScript.php b/src/Configurator/JavaScript.php index 49f29f99b9..139ffdd26f 100644 --- a/src/Configurator/JavaScript.php +++ b/src/Configurator/JavaScript.php @@ -136,7 +136,7 @@ public function getMinifier() * @param array $config Config array returned by the configurator * @return string JavaScript parser */ - public function getParser(array $config = null) + public function getParser(?array $config = null) { $this->configOptimizer->reset(); diff --git a/src/Configurator/RendererGenerators/PHP/XPathConvertor.php b/src/Configurator/RendererGenerators/PHP/XPathConvertor.php index fa2852edf5..ec843fb68a 100644 --- a/src/Configurator/RendererGenerators/PHP/XPathConvertor.php +++ b/src/Configurator/RendererGenerators/PHP/XPathConvertor.php @@ -34,7 +34,7 @@ class XPathConvertor /** * Constructor */ - public function __construct(RecursiveParser $parser = null) + public function __construct(?RecursiveParser $parser = null) { $this->features = [ 'mbstring' => extension_loaded('mbstring'), diff --git a/src/Configurator/TemplateChecker.php b/src/Configurator/TemplateChecker.php index 0633045698..e602acb94e 100644 --- a/src/Configurator/TemplateChecker.php +++ b/src/Configurator/TemplateChecker.php @@ -109,7 +109,7 @@ public function checkTag(Tag $tag) * @param Tag $tag Tag this template belongs to * @return void */ - public function checkTemplate($template, Tag $tag = null) + public function checkTemplate($template, ?Tag $tag = null) { if ($this->disabled) { diff --git a/src/Configurator/TemplateNormalizer.php b/src/Configurator/TemplateNormalizer.php index 6f1b589e6f..5aad8855e0 100644 --- a/src/Configurator/TemplateNormalizer.php +++ b/src/Configurator/TemplateNormalizer.php @@ -97,7 +97,7 @@ class TemplateNormalizer implements ArrayAccess, Iterator * * @param array $normalizations List of normalizations */ - public function __construct(array $normalizations = null) + public function __construct(?array $normalizations = null) { if (!isset($normalizations)) { diff --git a/src/Parser/AttributeFilters/NumericFilter.php b/src/Parser/AttributeFilters/NumericFilter.php index f896ea8dcb..c31f30bb09 100644 --- a/src/Parser/AttributeFilters/NumericFilter.php +++ b/src/Parser/AttributeFilters/NumericFilter.php @@ -42,7 +42,7 @@ public static function filterInt($attrValue) * @param Logger $logger Parser's Logger instance * @return mixed Filtered value, or FALSE if invalid */ - public static function filterRange($attrValue, $min, $max, Logger $logger = null) + public static function filterRange($attrValue, $min, $max, ?Logger $logger = null) { $attrValue = filter_var($attrValue, FILTER_VALIDATE_INT); diff --git a/src/Parser/AttributeFilters/UrlFilter.php b/src/Parser/AttributeFilters/UrlFilter.php index 984eafe535..3c10189309 100644 --- a/src/Parser/AttributeFilters/UrlFilter.php +++ b/src/Parser/AttributeFilters/UrlFilter.php @@ -19,7 +19,7 @@ class UrlFilter * @param Logger $logger Parser's logger * @return mixed Cleaned up URL if valid, FALSE otherwise */ - public static function filter($attrValue, array $urlConfig, Logger $logger = null) + public static function filter($attrValue, array $urlConfig, ?Logger $logger = null) { /** * Trim the URL to conform with HTML5 then parse it diff --git a/src/Plugins/BBCodes/Configurator/BBCode.php b/src/Plugins/BBCodes/Configurator/BBCode.php index 524b8a97ad..c3193816d8 100644 --- a/src/Plugins/BBCodes/Configurator/BBCode.php +++ b/src/Plugins/BBCodes/Configurator/BBCode.php @@ -51,7 +51,7 @@ class BBCode implements ConfigProvider /** * @param array $options This BBCode's options */ - public function __construct(array $options = null) + public function __construct(?array $options = null) { $this->contentAttributes = new AttributeList; if (isset($options)) diff --git a/src/Plugins/MediaEmbed/Configurator.php b/src/Plugins/MediaEmbed/Configurator.php index abee198688..adf64c4931 100644 --- a/src/Plugins/MediaEmbed/Configurator.php +++ b/src/Plugins/MediaEmbed/Configurator.php @@ -104,7 +104,7 @@ public function asConfig() * @param array $siteConfig Site's config * @return Tag Tag created for this site */ - public function add($siteId, array $siteConfig = null) + public function add($siteId, ?array $siteConfig = null) { // Normalize or retrieve the site definition $siteId = $this->normalizeId($siteId); diff --git a/tests/Parser/TagProcessingTest.php b/tests/Parser/TagProcessingTest.php index b244df977d..214c298a97 100644 --- a/tests/Parser/TagProcessingTest.php +++ b/tests/Parser/TagProcessingTest.php @@ -18,7 +18,7 @@ class TagProcessingTest extends Test * @testdox Works * @dataProvider getData */ - public function test($original, $expected, $setup = null, $callback = null, array $expectedLogs = null) + public function test($original, $expected, $setup = null, $callback = null, ?array $expectedLogs = null) { $this->configurator->rulesGenerator->clear(); $this->configurator->rulesGenerator->add('AllowAll'); diff --git a/tests/Test.php b/tests/Test.php index c7183b0cbf..ce81310551 100644 --- a/tests/Test.php +++ b/tests/Test.php @@ -65,7 +65,7 @@ protected function reduceAndSortArrays(array &$expected, array &$actual, $remove } } - protected function assertParsing($original, $expected, $setup = null, $callback = null, array $expectedLogs = null) + protected function assertParsing($original, $expected, $setup = null, $callback = null, ?array $expectedLogs = null) { if (isset($setup)) {