From ebd57eec89123033f234ca40ef3a22f36fba5e28 Mon Sep 17 00:00:00 2001 From: Derrick Austin Date: Thu, 28 May 2026 10:51:46 -0500 Subject: [PATCH] fix(php): resolve PHP 8.4/8.5 deprecations PHP 8.4 deprecates implicitly nullable parameter types (parameters with a default of `null` that don't explicitly declare `?Type`). This adds the `?` marker to every affected signature across `modules/`, including a related "optional-before-required" fix in PluginRollback's `suggestVersionValues()`. Also fixes one PHP 8.5 deprecation: using `null` as an array offset in `Cms\Classes\Page::getLayoutOptions()` (PHP already coerced it to `""`, so runtime behavior is unchanged). All changes use the `?Type` syntax available since PHP 7.1 and remain compatible with the project's `php >=8.1` floor. Refs: - https://www.php.net/manual/en/migration84.deprecated.php - https://www.php.net/manual/en/migration85.deprecated.php --- modules/backend/behaviors/ListController.php | 6 +++--- modules/backend/facades/Backend.php | 12 ++++++------ modules/backend/traits/PreferenceMaker.php | 2 +- modules/backend/widgets/MediaManager.php | 4 ++-- modules/cms/classes/CmsException.php | 2 +- modules/cms/classes/ComponentBase.php | 2 +- modules/cms/classes/Controller.php | 2 +- modules/cms/classes/Page.php | 2 +- modules/cms/controllers/ThemeOptions.php | 2 +- modules/cms/facades/Cms.php | 2 +- modules/cms/models/ThemeExport.php | 2 +- modules/cms/models/ThemeImport.php | 2 +- modules/cms/twig/Extension.php | 6 +++--- modules/system/classes/FileManifest.php | 2 +- modules/system/classes/MarkupManager.php | 2 +- modules/system/classes/SourceManifest.php | 2 +- modules/system/console/PluginRollback.php | 2 +- .../plugins/winter/tester/components/Categories.php | 2 +- .../plugins/winter/tester/components/Comments.php | 2 +- 19 files changed, 29 insertions(+), 29 deletions(-) diff --git a/modules/backend/behaviors/ListController.php b/modules/backend/behaviors/ListController.php index 5df8ca2f4f..292a2da686 100644 --- a/modules/backend/behaviors/ListController.php +++ b/modules/backend/behaviors/ListController.php @@ -422,7 +422,7 @@ public function listMakePartial($partial, $params = []) * * @return array The list element selector as the key, and the list contents are the value. */ - public function listRefresh(string $definition = null) + public function listRefresh(?string $definition = null) { if (!count($this->listWidgets)) { $this->makeLists(); @@ -439,7 +439,7 @@ public function listRefresh(string $definition = null) * Returns the widget used by this behavior. * @return \Backend\Classes\WidgetBase */ - public function listGetWidget(string $definition = null) + public function listGetWidget(?string $definition = null) { if (!$definition) { $definition = $this->primaryDefinition; @@ -452,7 +452,7 @@ public function listGetWidget(string $definition = null) * Returns the configuration used by this behavior. * @return stdClass */ - public function listGetConfig(string $definition = null) + public function listGetConfig(?string $definition = null) { if (!$definition) { $definition = $this->primaryDefinition; diff --git a/modules/backend/facades/Backend.php b/modules/backend/facades/Backend.php index 99cb59b76f..1d679a073b 100644 --- a/modules/backend/facades/Backend.php +++ b/modules/backend/facades/Backend.php @@ -4,12 +4,12 @@ /** * @method static string uri() - * @method static string url(string $path = null, array $parameters = [], bool $secure = null) - * @method static string baseUrl(string $path = null) - * @method static string skinAsset(string $path = null) - * @method static \Illuminate\Http\RedirectResponse redirect(string $path, int $status = 302, array $headers = [], bool $secure = null) - * @method static \Illuminate\Http\RedirectResponse redirectGuest(string $path, int $status = 302, array $headers = [], bool $secure = null) - * @method static \Illuminate\Http\RedirectResponse redirectIntended(string $path, int $status = 302, array $headers = [], bool $secure = null) + * @method static string url(?string $path = null, array $parameters = [], ?bool $secure = null) + * @method static string baseUrl(?string $path = null) + * @method static string skinAsset(?string $path = null) + * @method static \Illuminate\Http\RedirectResponse redirect(string $path, int $status = 302, array $headers = [], ?bool $secure = null) + * @method static \Illuminate\Http\RedirectResponse redirectGuest(string $path, int $status = 302, array $headers = [], ?bool $secure = null) + * @method static \Illuminate\Http\RedirectResponse redirectIntended(string $path, int $status = 302, array $headers = [], ?bool $secure = null) * @method static string date($dateTime, array $options = []) * @method static string dateTime($dateTime, array $options = []) * diff --git a/modules/backend/traits/PreferenceMaker.php b/modules/backend/traits/PreferenceMaker.php index fe6e8d331d..7778ccf7ff 100644 --- a/modules/backend/traits/PreferenceMaker.php +++ b/modules/backend/traits/PreferenceMaker.php @@ -42,7 +42,7 @@ public function putUserPreference(string $key, $value) * @param mixed $default A default value to use when value is not found. * @return mixed */ - public function getUserPreference(string $key = null, $default = null) + public function getUserPreference(?string $key = null, $default = null) { $preferences = $this->getUserPreferences(); diff --git a/modules/backend/widgets/MediaManager.php b/modules/backend/widgets/MediaManager.php index 067d53a50d..321ecbe73c 100644 --- a/modules/backend/widgets/MediaManager.php +++ b/modules/backend/widgets/MediaManager.php @@ -1192,7 +1192,7 @@ protected function getViewMode(): string /** * Returns thumbnail parameters */ - protected function getThumbnailParams(string $viewMode = null): array + protected function getThumbnailParams(?string $viewMode = null): array { $result = [ 'mode' => 'crop' @@ -1316,7 +1316,7 @@ protected function getResizedImageUrl(string $path, array $params): string * * @todo Consider moving this into the File helper and accepting a $disk instance */ - protected function deduplicatePath(string $path, string $suffix = null): string + protected function deduplicatePath(string $path, ?string $suffix = null): string { $parts = pathinfo($path); $i = 1; diff --git a/modules/cms/classes/CmsException.php b/modules/cms/classes/CmsException.php index 0c75176127..3a2f05fa39 100644 --- a/modules/cms/classes/CmsException.php +++ b/modules/cms/classes/CmsException.php @@ -42,7 +42,7 @@ class CmsException extends ApplicationException * Error 400: Mask the exception as Twig content. * @param Throwable $previous Previous exception. */ - public function __construct($message = null, $code = 100, Throwable $previous = null) + public function __construct($message = null, $code = 100, ?Throwable $previous = null) { if ($message instanceof CmsCompoundObject || $message instanceof ComponentPartial) { $this->compoundObject = $message; diff --git a/modules/cms/classes/ComponentBase.php b/modules/cms/classes/ComponentBase.php index 5d959438da..e1f418f137 100644 --- a/modules/cms/classes/ComponentBase.php +++ b/modules/cms/classes/ComponentBase.php @@ -82,7 +82,7 @@ abstract class ComponentBase extends Extendable * @param null|CodeBase $cmsObject * @param array $properties */ - public function __construct(CodeBase $cmsObject = null, $properties = []) + public function __construct(?CodeBase $cmsObject = null, $properties = []) { if ($cmsObject !== null) { $this->page = $cmsObject; diff --git a/modules/cms/classes/Controller.php b/modules/cms/classes/Controller.php index 93cc9f790e..d3e855ca33 100644 --- a/modules/cms/classes/Controller.php +++ b/modules/cms/classes/Controller.php @@ -1586,7 +1586,7 @@ public function findComponentByPartial($partial) * @param ComponentBase $component * @return void */ - public function setComponentContext(ComponentBase $component = null) + public function setComponentContext(?ComponentBase $component = null) { $this->componentContext = $component; } diff --git a/modules/cms/classes/Page.php b/modules/cms/classes/Page.php index 617e405f92..6bf807eea4 100644 --- a/modules/cms/classes/Page.php +++ b/modules/cms/classes/Page.php @@ -83,7 +83,7 @@ public function getLayoutOptions() $layouts = Layout::listInTheme($theme, true); $result = []; - $result[null] = Lang::get('cms::lang.page.no_layout'); + $result[''] = Lang::get('cms::lang.page.no_layout'); foreach ($layouts as $layout) { $baseName = $layout->getBaseFileName(); diff --git a/modules/cms/controllers/ThemeOptions.php b/modules/cms/controllers/ThemeOptions.php index a2706215f6..3510f498bf 100644 --- a/modules/cms/controllers/ThemeOptions.php +++ b/modules/cms/controllers/ThemeOptions.php @@ -102,7 +102,7 @@ public function formExtendFieldsBefore($form) * @param string $dirName * @return string */ - protected function getDirName(string $dirName = null) + protected function getDirName(?string $dirName = null) { /* * Only the active theme can be managed without this permission diff --git a/modules/cms/facades/Cms.php b/modules/cms/facades/Cms.php index 8177852419..29b0206a07 100644 --- a/modules/cms/facades/Cms.php +++ b/modules/cms/facades/Cms.php @@ -3,7 +3,7 @@ use Winter\Storm\Support\Facade; /** - * @method static string url(string $path = null) + * @method static string url(?string $path = null) * * @see \Cms\Helpers\Cms */ diff --git a/modules/cms/models/ThemeExport.php b/modules/cms/models/ThemeExport.php index a732b21f4b..83856bd39e 100644 --- a/modules/cms/models/ThemeExport.php +++ b/modules/cms/models/ThemeExport.php @@ -59,7 +59,7 @@ class ThemeExport extends Model * * @return void */ - public function save(array $options = null, $sessionKey = null) + public function save(?array $options = null, $sessionKey = null) { throw new ApplicationException(sprintf("The % model is not intended to be saved, please use %s instead", get_class($this), 'ThemeData')); } diff --git a/modules/cms/models/ThemeImport.php b/modules/cms/models/ThemeImport.php index 4cfe2817ea..b31da568c7 100644 --- a/modules/cms/models/ThemeImport.php +++ b/modules/cms/models/ThemeImport.php @@ -64,7 +64,7 @@ class ThemeImport extends Model * * @return void */ - public function save(array $options = null, $sessionKey = null) + public function save(?array $options = null, $sessionKey = null) { throw new ApplicationException(sprintf("The % model is not intended to be saved, please use %s instead", get_class($this), 'ThemeData')); } diff --git a/modules/cms/twig/Extension.php b/modules/cms/twig/Extension.php index 95d20874b1..8158404db4 100644 --- a/modules/cms/twig/Extension.php +++ b/modules/cms/twig/Extension.php @@ -128,7 +128,7 @@ public function componentFunction(string $name, array $parameters = []): string /** * Renders registered assets of a given type or all types if $type not provided */ - public function assetsFunction(string $type = null): ?string + public function assetsFunction(?string $type = null): ?string { return $this->controller->makeAssets($type); } @@ -136,7 +136,7 @@ public function assetsFunction(string $type = null): ?string /** * Renders placeholder content, without removing the block, must be called before the placeholder tag itself */ - public function placeholderFunction(string $name, string $default = null): ?string + public function placeholderFunction(string $name, ?string $default = null): ?string { if (($result = Block::get($name)) === null) { return null; @@ -196,7 +196,7 @@ public function startBlock(string $name): void /** * Returns a layout block contents (or null if it doesn't exist) and removes the block. */ - public function displayBlock(string $name, string $default = null): ?string + public function displayBlock(string $name, ?string $default = null): ?string { if (($result = Block::placeholder($name)) === null) { return $default; diff --git a/modules/system/classes/FileManifest.php b/modules/system/classes/FileManifest.php index d03e5cd038..6a45eacb15 100644 --- a/modules/system/classes/FileManifest.php +++ b/modules/system/classes/FileManifest.php @@ -54,7 +54,7 @@ class FileManifest /** * Constructor. */ - public function __construct(string $root = null, array $modules = null) + public function __construct(?string $root = null, ?array $modules = null) { $this->setRoot($root ?? base_path()); $this->setModules($modules ?? Config::get('cms.loadModules', ['System', 'Backend', 'Cms'])); diff --git a/modules/system/classes/MarkupManager.php b/modules/system/classes/MarkupManager.php index 63c580aac1..4a1398d993 100644 --- a/modules/system/classes/MarkupManager.php +++ b/modules/system/classes/MarkupManager.php @@ -52,7 +52,7 @@ protected function init() /** * Make an instance of the base TwigEnvironment to extend further */ - public static function makeBaseTwigEnvironment(LoaderInterface $loader = null, array $options = []): TwigEnvironment + public static function makeBaseTwigEnvironment(?LoaderInterface $loader = null, array $options = []): TwigEnvironment { if (!$loader) { $loader = new SystemTwigLoader(); diff --git a/modules/system/classes/SourceManifest.php b/modules/system/classes/SourceManifest.php index 677de5cf94..41f8cd0553 100644 --- a/modules/system/classes/SourceManifest.php +++ b/modules/system/classes/SourceManifest.php @@ -43,7 +43,7 @@ class SourceManifest /** * Constructor */ - public function __construct(string $source = null, string $forks = null, bool $autoload = true) + public function __construct(?string $source = null, ?string $forks = null, bool $autoload = true) { $this->setSource($source ?? Config::get( 'cms.sourceManifestUrl', diff --git a/modules/system/console/PluginRollback.php b/modules/system/console/PluginRollback.php index 83e9724a51..b7ffc73bc0 100644 --- a/modules/system/console/PluginRollback.php +++ b/modules/system/console/PluginRollback.php @@ -76,7 +76,7 @@ public function handle(): int /** * Suggest values for the optional version argument */ - public function suggestVersionValues(string $value = null, array $allInput): array + public function suggestVersionValues(?string $value, array $allInput): array { // Get the currently selected plugin $pluginName = $this->getPluginIdentifier($allInput['arguments']['plugin']); diff --git a/modules/system/tests/fixtures/plugins/winter/tester/components/Categories.php b/modules/system/tests/fixtures/plugins/winter/tester/components/Categories.php index 4de6985852..b5b47642fb 100644 --- a/modules/system/tests/fixtures/plugins/winter/tester/components/Categories.php +++ b/modules/system/tests/fixtures/plugins/winter/tester/components/Categories.php @@ -5,7 +5,7 @@ class Categories extends ComponentBase { - public function __construct(CodeBase $cmsObject = null, $properties = []) + public function __construct(?CodeBase $cmsObject = null, $properties = []) { parent::__construct($cmsObject, $properties); } diff --git a/modules/system/tests/fixtures/plugins/winter/tester/components/Comments.php b/modules/system/tests/fixtures/plugins/winter/tester/components/Comments.php index ab22ce6d41..f5e38b5c5a 100644 --- a/modules/system/tests/fixtures/plugins/winter/tester/components/Comments.php +++ b/modules/system/tests/fixtures/plugins/winter/tester/components/Comments.php @@ -8,7 +8,7 @@ class Comments extends ComponentBase { private $users; - public function __construct(CodeBase $cmsObject = null, $properties = [], Users $users = null) + public function __construct(?CodeBase $cmsObject = null, $properties = [], ?Users $users = null) { parent::__construct($cmsObject, $properties); $this->users = $users;