Skip to content

Commit

Permalink
API Explicity mark nullable paramters for PHP 8.4
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Nov 28, 2024
1 parent c651007 commit aa97a54
Show file tree
Hide file tree
Showing 43 changed files with 105 additions and 105 deletions.
24 changes: 12 additions & 12 deletions src/Control/Director.php
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ protected static function validateUserAndPass($url)
* @param HTTPRequest $request
* @return string Host name, including port (if present)
*/
public static function host(HTTPRequest $request = null)
public static function host(?HTTPRequest $request = null)
{
// Check if overridden by alternate_base_url
if ($baseURL = static::config()->get('alternate_base_url')) {
Expand Down Expand Up @@ -553,7 +553,7 @@ public static function host(HTTPRequest $request = null)
* @param HTTPRequest $request
* @return int|null
*/
public static function port(HTTPRequest $request = null)
public static function port(?HTTPRequest $request = null)
{
$host = static::host($request);
return (int)parse_url($host ?? '', PHP_URL_PORT) ?: null;
Expand All @@ -565,7 +565,7 @@ public static function port(HTTPRequest $request = null)
* @param HTTPRequest|null $request
* @return string|null
*/
public static function hostName(HTTPRequest $request = null)
public static function hostName(?HTTPRequest $request = null)
{
$host = static::host($request);
return parse_url($host ?? '', PHP_URL_HOST) ?: null;
Expand All @@ -578,7 +578,7 @@ public static function hostName(HTTPRequest $request = null)
* @param HTTPRequest $request
* @return bool|string
*/
public static function protocolAndHost(HTTPRequest $request = null)
public static function protocolAndHost(?HTTPRequest $request = null)
{
return static::protocol($request) . static::host($request);
}
Expand All @@ -589,7 +589,7 @@ public static function protocolAndHost(HTTPRequest $request = null)
* @param HTTPRequest $request
* @return string
*/
public static function protocol(HTTPRequest $request = null)
public static function protocol(?HTTPRequest $request = null)
{
return (Director::is_https($request)) ? 'https://' : 'http://';
}
Expand All @@ -600,7 +600,7 @@ public static function protocol(HTTPRequest $request = null)
* @param HTTPRequest $request
* @return bool
*/
public static function is_https(HTTPRequest $request = null)
public static function is_https(?HTTPRequest $request = null)
{
// Check override from alternate_base_url
if ($baseURL = static::config()->uninherited('alternate_base_url')) {
Expand Down Expand Up @@ -925,7 +925,7 @@ public static function absoluteBaseURL()
* @param HTTPRequest|null $request
* @return string
*/
public static function absoluteBaseURLWithAuth(HTTPRequest $request = null)
public static function absoluteBaseURLWithAuth(?HTTPRequest $request = null)
{
// Detect basic auth
$login = '';
Expand Down Expand Up @@ -985,7 +985,7 @@ protected static function force_redirect($destURL)
* Can include port number.
* @param HTTPRequest|null $request Request object to check
*/
public static function forceSSL($patterns = null, $secureDomain = null, HTTPRequest $request = null)
public static function forceSSL($patterns = null, $secureDomain = null, ?HTTPRequest $request = null)
{
$handler = CanonicalURLMiddleware::singleton()->setForceSSL(true);
if ($patterns) {
Expand All @@ -1002,7 +1002,7 @@ public static function forceSSL($patterns = null, $secureDomain = null, HTTPRequ
*
* @param HTTPRequest $request
*/
public static function forceWWW(HTTPRequest $request = null)
public static function forceWWW(?HTTPRequest $request = null)
{
$handler = CanonicalURLMiddleware::singleton()->setForceWWW(true);
$handler->throwRedirectIfNeeded($request);
Expand All @@ -1018,7 +1018,7 @@ public static function forceWWW(HTTPRequest $request = null)
* @param HTTPRequest $request
* @return bool
*/
public static function is_ajax(HTTPRequest $request = null)
public static function is_ajax(?HTTPRequest $request = null)
{
$request = Director::currentRequest($request);
if ($request) {
Expand Down Expand Up @@ -1063,7 +1063,7 @@ public static function get_environment_type()
*
* @return string|null null if not overridden, otherwise the actual value
*/
public static function get_session_environment_type(HTTPRequest $request = null)
public static function get_session_environment_type(?HTTPRequest $request = null)
{
$request = static::currentRequest($request);

Expand Down Expand Up @@ -1139,7 +1139,7 @@ public static function get_template_global_variables()
* @param HTTPRequest $request
* @return HTTPRequest Request object if one is both current and valid
*/
protected static function currentRequest(HTTPRequest $request = null)
protected static function currentRequest(?HTTPRequest $request = null)
{
// Ensure we only use a registered HTTPRequest and don't
// incidentally construct a singleton
Expand Down
4 changes: 2 additions & 2 deletions src/Control/Email/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ private function getDefaultFrom(): string|array
/**
* Passing a string of HTML for $body will have no affect if you also call either setData() or addData()
*/
public function setBody(AbstractPart|string $body = null): static
public function setBody(AbstractPart|string|null $body = null): static
{
if ($body instanceof AbstractPart) {
// pass to Symfony\Component\Mime\Message::setBody()
Expand Down Expand Up @@ -326,7 +326,7 @@ public function addAttachment(string $path, ?string $alias = null, ?string $mime
return $this->attachFromPath($path, $alias, $mime);
}

public function addAttachmentFromData(string $data, string $name, string $mime = null): static
public function addAttachmentFromData(string $data, string $name, ?string $mime = null): static
{
return $this->attach($data, $name, $mime);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Control/Middleware/CanonicalURLMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ protected function getRedirect(HTTPRequest $request)
* @param HTTPRequest|null $request Allow HTTPRequest to be used for the base comparison
* @throws HTTPResponse_Exception
*/
public function throwRedirectIfNeeded(HTTPRequest $request = null)
public function throwRedirectIfNeeded(?HTTPRequest $request = null)
{
$request = $this->getOrValidateRequest($request);
if (!$request) {
Expand All @@ -328,7 +328,7 @@ public function throwRedirectIfNeeded(HTTPRequest $request = null)
* @param HTTPRequest $request
* @return HTTPRequest|null
*/
protected function getOrValidateRequest(HTTPRequest $request = null)
protected function getOrValidateRequest(?HTTPRequest $request = null)
{
if ($request instanceof HTTPRequest) {
return $request;
Expand Down Expand Up @@ -526,7 +526,7 @@ protected function isEnabled()
* @param HTTPResponse $response
* @return bool
*/
protected function hasBasicAuthPrompt(HTTPResponse $response = null)
protected function hasBasicAuthPrompt(?HTTPResponse $response = null)
{
if (!$response) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/Control/Middleware/RequestHandlerMiddlewareAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class RequestHandlerMiddlewareAdapter extends RequestHandler
*/
protected $requestHandler = null;

public function __construct(RequestHandler $handler = null)
public function __construct(?RequestHandler $handler = null)
{
if ($handler) {
$this->setRequestHandler($handler);
Expand Down
2 changes: 1 addition & 1 deletion src/Control/PjaxResponseNegotiator.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class PjaxResponseNegotiator
* @param array $callbacks
* @param HTTPResponse $response An existing response to reuse (optional)
*/
public function __construct($callbacks = [], HTTPResponse $response = null)
public function __construct($callbacks = [], ?HTTPResponse $response = null)
{
$this->callbacks = $callbacks;
$this->response = $response ?: HTTPResponse::create();
Expand Down
2 changes: 1 addition & 1 deletion src/Control/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ private function isCookieSecure(string $sameSite, bool $isHttps): bool
* @param bool $removeCookie
* @param HTTPRequest $request The request for which to destroy a session
*/
public function destroy($removeCookie = true, HTTPRequest $request = null)
public function destroy($removeCookie = true, ?HTTPRequest $request = null)
{
if (session_id()) {
if ($removeCookie) {
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Cache/AbstractCacheFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ abstract class AbstractCacheFactory implements CacheFactory
/**
* @param LoggerInterface $logger Logger instance to assign
*/
public function __construct(LoggerInterface $logger = null)
public function __construct(?LoggerInterface $logger = null)
{
$this->logger = $logger;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Cache/DefaultCacheFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class DefaultCacheFactory extends AbstractCacheFactory
* @param array $args List of global options to merge with args during create()
* @param LoggerInterface $logger Logger instance to assign
*/
public function __construct($args = [], LoggerInterface $logger = null)
public function __construct($args = [], ?LoggerInterface $logger = null)
{
$this->args = $args;
parent::__construct($logger);
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Cache/ManifestCacheFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
class ManifestCacheFactory extends DefaultCacheFactory
{
public function __construct(array $args = [], LoggerInterface $logger = null)
public function __construct(array $args = [], ?LoggerInterface $logger = null)
{
// Build default manifest logger
if (!$logger) {
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Config/CoreConfigFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class CoreConfigFactory
*
* @param CacheFactory $cacheFactory
*/
public function __construct(CacheFactory $cacheFactory = null)
public function __construct(?CacheFactory $cacheFactory = null)
{
$this->cacheFactory = $cacheFactory;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Manifest/ClassManifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class ClassManifest
* @param string $base The manifest base path.
* @param CacheFactory $cacheFactory Optional cache to use. Set to null to not cache.
*/
public function __construct($base, CacheFactory $cacheFactory = null)
public function __construct($base, ?CacheFactory $cacheFactory = null)
{
$this->base = $base;
$this->cacheFactory = $cacheFactory;
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Manifest/ModuleManifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class ModuleManifest
* @param string $base The project base path.
* @param CacheFactory $cacheFactory Cache factory to use
*/
public function __construct($base, CacheFactory $cacheFactory = null)
public function __construct($base, ?CacheFactory $cacheFactory = null)
{
$this->base = $base;
$this->cacheKey = sha1($base ?? '') . '_modules';
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Validation/FieldValidation/DecimalFieldValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public function __construct(
mixed $value,
int $wholeSize,
int $decimalSize,
int $minValue = null,
int $maxValue = null,
?int $minValue = null,
?int $maxValue = null,
) {
parent::__construct($name, $value, $minValue, $maxValue);
$this->wholeSize = $wholeSize;
Expand Down
14 changes: 7 additions & 7 deletions src/Dev/Debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Debug
* @param bool $showHeader
* @param HTTPRequest|null $request
*/
public static function show($val, $showHeader = true, HTTPRequest $request = null)
public static function show($val, $showHeader = true, ?HTTPRequest $request = null)
{
// Don't show on live
if (Director::isLive()) {
Expand Down Expand Up @@ -80,7 +80,7 @@ public static function caller()
* @param bool $showHeader
* @param HTTPRequest $request
*/
public static function endshow($val, $showHeader = true, HTTPRequest $request = null)
public static function endshow($val, $showHeader = true, ?HTTPRequest $request = null)
{
// Don't show on live
if (Director::isLive()) {
Expand All @@ -100,7 +100,7 @@ public static function endshow($val, $showHeader = true, HTTPRequest $request =
* @param mixed $val
* @param HTTPRequest $request Current request to influence output format
*/
public static function dump($val, HTTPRequest $request = null)
public static function dump($val, ?HTTPRequest $request = null)
{
echo Debug::create_debug_view($request)
->renderVariable($val, Debug::caller());
Expand All @@ -113,7 +113,7 @@ public static function dump($val, HTTPRequest $request = null)
* @param HTTPRequest $request
* @return string
*/
public static function text($val, HTTPRequest $request = null)
public static function text($val, ?HTTPRequest $request = null)
{
return static::create_debug_view($request)
->debugVariableText($val);
Expand All @@ -127,7 +127,7 @@ public static function text($val, HTTPRequest $request = null)
* @param bool $showHeader
* @param HTTPRequest|null $request
*/
public static function message($message, $showHeader = true, HTTPRequest $request = null)
public static function message($message, $showHeader = true, ?HTTPRequest $request = null)
{
// Don't show on live
if (Director::isLive()) {
Expand All @@ -144,7 +144,7 @@ public static function message($message, $showHeader = true, HTTPRequest $reques
* @param HTTPRequest $request Optional request to target this view for
* @return DebugView
*/
public static function create_debug_view(HTTPRequest $request = null)
public static function create_debug_view(?HTTPRequest $request = null)
{
$service = static::supportsHTML($request)
? DebugView::class
Expand All @@ -158,7 +158,7 @@ public static function create_debug_view(HTTPRequest $request = null)
* @param HTTPRequest $request
* @return bool
*/
protected static function supportsHTML(HTTPRequest $request = null)
protected static function supportsHTML(?HTTPRequest $request = null)
{
// No HTML output in CLI
if (Director::is_cli()) {
Expand Down
2 changes: 1 addition & 1 deletion src/Dev/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public function post($url, $data, $headers = null, $session = null, $body = null
* @param array $data Map of GET/POST data.
* @param bool $withSecurityToken Submit with the form's security token if there is one.
*/
public function submitForm(string $formID, string $button = null, array $data = [], bool $withSecurityToken = true): HTTPResponse
public function submitForm(string $formID, ?string $button = null, array $data = [], bool $withSecurityToken = true): HTTPResponse
{
$this->cssParser = null;
$response = $this->mainSession->submitForm($formID, $button, $data, $withSecurityToken);
Expand Down
4 changes: 2 additions & 2 deletions src/Dev/TestMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(
$this->dispatcher = $dispatcher;
}

public function send(RawMessage $message, Envelope $envelope = null): void
public function send(RawMessage $message, ?Envelope $envelope = null): void
{
if (!is_a($message, Email::class)) {
throw new InvalidArgumentException('$message must be a ' . Email::class);
Expand Down Expand Up @@ -122,7 +122,7 @@ private function convertAddressesToString(array $addresses): string
return implode(',', array_map(fn(Address $address) => $address->getAddress(), $addresses));
}

private function dispatchEvent(Email $email, Envelope $envelope = null): void
private function dispatchEvent(Email $email, ?Envelope $envelope = null): void
{
$sender = $email->getSender()[0] ?? $email->getFrom()[0] ?? new Address('[email protected]');
$recipients = empty($email->getTo()) ? [new Address('[email protected]')] : $email->getTo();
Expand Down
2 changes: 1 addition & 1 deletion src/Dev/TestSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public function sendRequest($method, $url, $data, $headers = null, $session = nu
* @param array $data Map of GET/POST data.
* @param bool $withSecurityToken Submit with the form's security token if there is one.
*/
public function submitForm(string $formID, string $button = null, array $data = [], bool $withSecurityToken = true): HTTPResponse
public function submitForm(string $formID, ?string $button = null, array $data = [], bool $withSecurityToken = true): HTTPResponse
{
$page = $this->lastPage();
if ($page) {
Expand Down
8 changes: 4 additions & 4 deletions src/Forms/DefaultFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct()
* @return Form
* @throws InvalidArgumentException When required context is missing
*/
public function getForm(RequestHandler $controller = null, $name = FormFactory::DEFAULT_NAME, $context = [])
public function getForm(?RequestHandler $controller = null, $name = FormFactory::DEFAULT_NAME, $context = [])
{
// Validate context
foreach ($this->getRequiredContext() as $required) {
Expand Down Expand Up @@ -64,7 +64,7 @@ public function getForm(RequestHandler $controller = null, $name = FormFactory::
* @param array $context
* @return FieldList
*/
protected function getFormFields(RequestHandler $controller = null, $name, $context = [])
protected function getFormFields(?RequestHandler $controller = null, $name, $context = [])
{
// Fall back to standard "getCMSFields" which itself uses the FormScaffolder as a fallback
$fields = $context['Record']->getCMSFields();
Expand All @@ -80,7 +80,7 @@ protected function getFormFields(RequestHandler $controller = null, $name, $cont
* @param array $context
* @return FieldList
*/
protected function getFormActions(RequestHandler $controller = null, $name, $context = [])
protected function getFormActions(?RequestHandler $controller = null, $name, $context = [])
{
$actions = $context['Record']->getCMSActions();
$this->invokeWithExtensions('updateFormActions', $actions, $controller, $name, $context);
Expand All @@ -93,7 +93,7 @@ protected function getFormActions(RequestHandler $controller = null, $name, $con
* @param array $context
* @return null|Validator
*/
protected function getFormValidator(RequestHandler $controller = null, $name, $context = [])
protected function getFormValidator(?RequestHandler $controller = null, $name, $context = [])
{
if (!$context['Record'] instanceof DataObject) {
return null;
Expand Down
Loading

0 comments on commit aa97a54

Please sign in to comment.