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

refactor: better PHP 8.4 compatibility #2030

Merged
merged 1 commit into from
Aug 27, 2024
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
"code:md": "phpmd src text codesize, naming, unusedcode",
"code:md:gh": "phpmd src github codesize, naming, unusedcode",
"code:style": "phpcs ./src/ --standard=PSR12 -n",
"code:fix": "php-cs-fixer fix ./src/ --rules=@PSR12,native_function_invocation --allow-risky=yes --show-progress=none",
"code:fix": "php-cs-fixer fix ./src/ --rules=@PSR12,native_function_invocation,nullable_type_declaration_for_default_null_value --allow-risky=yes --show-progress=none",
"test": "@test:integration",
"test:integration": "phpunit -c ./ --testsuite=IntegrationTests",
"test:coverage": "phpunit -c ./ --testsuite=IntegrationTests --coverage-text --coverage-clover=build/logs/clover.xml",
Expand Down
2 changes: 1 addition & 1 deletion src/Assets/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public function createKeyFromPath(string $path, string $relativePath): string
/**
* Creates key from an Asset source: "$filename_$ext_$tag__VERSION__MD5".
*/
public function createKeyFromAsset(Asset $asset, array $tags = null): string
public function createKeyFromAsset(Asset $asset, ?array $tags = null): string
{
$tags = implode('_', $tags ?? []);

Expand Down
2 changes: 1 addition & 1 deletion src/Assets/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Url
* @param Page|Asset|string|null $value
* @param array|null $options Rendering options, e.g.: ['canonical' => true, 'format' => 'html', 'language' => 'fr']
*/
public function __construct(Builder $builder, $value, array $options = null)
public function __construct(Builder $builder, $value, ?array $options = null)
{
$this->builder = $builder;
$this->config = $builder->getConfig();
Expand Down
8 changes: 4 additions & 4 deletions src/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class Builder implements LoggerAwareInterface
* @param Config|array|null $config
* @param LoggerInterface|null $logger
*/
public function __construct($config = null, LoggerInterface $logger = null)
public function __construct($config = null, ?LoggerInterface $logger = null)
{
// set logger
if ($logger === null) {
Expand Down Expand Up @@ -202,7 +202,7 @@ public function getConfig(): Config
/**
* Config::setSourceDir() alias.
*/
public function setSourceDir(string $sourceDir = null): self
public function setSourceDir(?string $sourceDir = null): self
{
$this->config->setSourceDir($sourceDir);

Expand All @@ -212,7 +212,7 @@ public function setSourceDir(string $sourceDir = null): self
/**
* Config::setDestinationDir() alias.
*/
public function setDestinationDir(string $destinationDir = null): self
public function setDestinationDir(?string $destinationDir = null): self
{
$this->config->setDestinationDir($destinationDir);

Expand Down Expand Up @@ -278,7 +278,7 @@ public function setData(array $data): void
/**
* Returns data collection.
*/
public function getData(string $language = null): array
public function getData(?string $language = null): array
{
if ($language) {
if (empty($this->data[$language])) {
Expand Down
2 changes: 1 addition & 1 deletion src/Collection/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public function getIterator(): \ArrayIterator
/**
* {@inheritdoc}
*/
public function usort(\Closure $callback = null): CollectionInterface
public function usort(?\Closure $callback = null): CollectionInterface
{
$callback ? usort($this->items, $callback) : usort($this->items, function ($a, $b) {
if ($a == $b) {
Expand Down
2 changes: 1 addition & 1 deletion src/Collection/CollectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function getIterator(): \ArrayIterator;
*
* @param \Closure|null $callback
*/
public function usort(\Closure $callback = null): self;
public function usort(?\Closure $callback = null): self;

/**
* Reverse items.
Expand Down
2 changes: 1 addition & 1 deletion src/Collection/Menu/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function getName(): ?string
/**
* Set the menu entry URL.
*/
public function setUrl(string $value = null): self
public function setUrl(?string $value = null): self
{
$this->offsetSet('url', $value);

Expand Down
2 changes: 1 addition & 1 deletion src/Collection/Page/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public function filter(\Closure $callback): self
/**
* {@inheritdoc}
*/
public function usort(\Closure $callback = null): self
public function usort(?\Closure $callback = null): self
{
return parent::usort($callback);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public function get(string $key, ?string $language = null, bool $fallback = true
*
* @throws \InvalidArgumentException
*/
public function setSourceDir(string $sourceDir = null): self
public function setSourceDir(?string $sourceDir = null): self
{
if ($sourceDir === null) {
$sourceDir = getcwd();
Expand All @@ -202,7 +202,7 @@ public function getSourceDir(): string
*
* @throws \InvalidArgumentException
*/
public function setDestinationDir(string $destinationDir = null): self
public function setDestinationDir(?string $destinationDir = null): self
{
if ($destinationDir === null) {
$destinationDir = $this->sourceDir;
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/ConfigException.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

class ConfigException extends \RuntimeException implements ExceptionInterface
{
public function __construct(string $message, int $code = 0, \Throwable $previous = null)
public function __construct(string $message, int $code = 0, ?\Throwable $previous = null)
{
parent::__construct("Configuration: $message", $code, $previous);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/RuntimeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class RuntimeException extends \RuntimeException implements ExceptionInterface
private $pageLine;
private $pageCol;

public function __construct(string $message, string $pageFile = null, int $pageLine = null, int $pageCol = null, \Throwable $previous = null)
public function __construct(string $message, ?string $pageFile = null, ?int $pageLine = null, ?int $pageCol = null, ?\Throwable $previous = null)
{
$this->pageFile = $pageFile;
$this->pageLine = $pageLine;
Expand Down
2 changes: 1 addition & 1 deletion src/Logger/PrintLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class PrintLogger extends AbstractLogger
/**
* Print only the $printLevelMax.
*/
public function __construct(int $printLevelMax = null)
public function __construct(?int $printLevelMax = null)
{
$this->printLevelMax = $printLevelMax;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Renderer/Extension/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public function sortByDate(\Traversable $collection, string $variable = 'date',
* @param Page|Asset|string|null $value
* @param array|null $options
*/
public function url(array $context, $value = null, array $options = null): string
public function url(array $context, $value = null, ?array $options = null): string
{
$optionsLang = [];
$optionsLang['language'] = (string) $context['site']['language'];
Expand Down
2 changes: 1 addition & 1 deletion src/Renderer/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Language
/** @var string Current language. */
protected $language;

public function __construct(\Cecil\Config $config, string $language = null)
public function __construct(\Cecil\Config $config, ?string $language = null)
{
$this->config = $config;
$this->language = $language;
Expand Down
2 changes: 1 addition & 1 deletion src/Renderer/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function offsetUnset($offset): void
*
* @throws \DomainException
*/
public function getPage(string $id, string $language = null): ?CollectionPage
public function getPage(string $id, ?string $language = null): ?CollectionPage
{
$pageId = $id;
$language = $language ?? $this->language;
Expand Down
2 changes: 1 addition & 1 deletion src/Renderer/Twig.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function __construct(Builder $builder, $templatesPath)
$this->twig->registerUndefinedFilterCallback(function ($name) {
switch ($name) {
case 'localizeddate':
return new \Twig\TwigFilter($name, function (\DateTime $value = null) {
return new \Twig\TwigFilter($name, function (?\DateTime $value = null) {
return date($this->builder->getConfig()->get('date.format') ?? 'F j, Y', $value->getTimestamp());
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/Step/Optimize/AbstractOptimize.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ abstract public function processFile(\Symfony\Component\Finder\SplFileInfo $file
/**
* Encode file content.
*/
public function encode(string $content = null): ?string
public function encode(?string $content = null): ?string
{
return $content;
}

/**
* Decode file content.
*/
public function decode(string $content = null): ?string
public function decode(?string $content = null): ?string
{
return $content;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Step/Optimize/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ public function processFile(\Symfony\Component\Finder\SplFileInfo $file): string
/**
* {@inheritdoc}
*/
public function encode(string $content = null): ?string
public function encode(?string $content = null): ?string
{
return json_encode($content);
}

/**
* {@inheritdoc}
*/
public function decode(string $content = null): ?string
public function decode(?string $content = null): ?string
{
return json_decode((string) $content);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Step/Optimize/Images.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ public function processFile(\Symfony\Component\Finder\SplFileInfo $file): string
/**
* {@inheritdoc}
*/
public function encode(string $content = null): ?string
public function encode(?string $content = null): ?string
{
return base64_encode((string) $content);
}

/**
* {@inheritdoc}
*/
public function decode(string $content = null): ?string
public function decode(?string $content = null): ?string
{
return base64_decode((string) $content);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Step/StaticFiles/Copy.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function process(): void
/**
* Copying (mirror) files.
*/
protected function copy(string $from, string $to = null, array $exclude = null): bool
protected function copy(string $from, ?string $to = null, ?array $exclude = null): bool
{
if (Util\File::getFS()->exists($from)) {
$finder = Finder::create()
Expand Down