Skip to content

Commit

Permalink
TASK: Correctly mark nullable method parameters as nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin-K committed Jan 8, 2025
1 parent 7bf8615 commit fd7b3ce
Show file tree
Hide file tree
Showing 142 changed files with 546 additions and 389 deletions.
5 changes: 3 additions & 2 deletions Neos.Cache/Classes/Backend/AbstractBackend.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Neos\Cache\Backend;
Expand Down Expand Up @@ -61,7 +62,7 @@ abstract class AbstractBackend implements BackendInterface
* @param array $options Configuration options - depends on the actual backend
* @api
*/
public function __construct(EnvironmentConfiguration $environmentConfiguration = null, array $options = [])
public function __construct(?EnvironmentConfiguration $environmentConfiguration = null, array $options = [])
{
$this->environmentConfiguration = $environmentConfiguration;

Expand Down Expand Up @@ -144,7 +145,7 @@ public function setDefaultLifetime($defaultLifetime): void
* @param integer $lifetime The lifetime in seconds
* @return \DateTime The expiry time
*/
protected function calculateExpiryTime(int $lifetime = null): \DateTime
protected function calculateExpiryTime(?int $lifetime = null): \DateTime
{
if ($lifetime === self::UNLIMITED_LIFETIME || ($lifetime === null && $this->defaultLifetime === self::UNLIMITED_LIFETIME)) {
return new \DateTime(self::DATETIME_EXPIRYTIME_UNLIMITED, new \DateTimeZone('UTC'));
Expand Down
7 changes: 3 additions & 4 deletions Neos.Cache/Classes/Backend/ApcuBackend.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Neos\Cache\Backend;
Expand Down Expand Up @@ -117,7 +118,7 @@ public function getPrefixedIdentifier(string $entryIdentifier): string
* @throws \InvalidArgumentException if the identifier is not valid
* @api
*/
public function set(string $entryIdentifier, string $data, array $tags = [], int $lifetime = null): void
public function set(string $entryIdentifier, string $data, array $tags = [], ?int $lifetime = null): void
{
if (!$this->cache instanceof FrontendInterface) {
throw new Exception('No cache frontend has been set yet via setCache().', 1232986818);
Expand Down Expand Up @@ -322,9 +323,7 @@ protected function removeIdentifierFromAllTags(string $entryIdentifier)
* @return void
* @api
*/
public function collectGarbage(): void
{
}
public function collectGarbage(): void {}

/**
* Returns the data of the current cache entry pointed to by the cache entry
Expand Down
3 changes: 2 additions & 1 deletion Neos.Cache/Classes/Backend/BackendInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Neos\Cache\Backend;
Expand Down Expand Up @@ -57,7 +58,7 @@ public function getPrefixedIdentifier(string $entryIdentifier): string;
* @throws \InvalidArgumentException if the identifier is not valid
* @api
*/
public function set(string $entryIdentifier, string $data, array $tags = [], int $lifetime = null): void;
public function set(string $entryIdentifier, string $data, array $tags = [], ?int $lifetime = null): void;

/**
* Loads data from the cache.
Expand Down
5 changes: 3 additions & 2 deletions Neos.Cache/Classes/Backend/FileBackend.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Neos\Cache\Backend;
Expand Down Expand Up @@ -148,7 +149,7 @@ public function setCache(FrontendInterface $cache): void
* @throws \InvalidArgumentException
* @api
*/
public function set(string $entryIdentifier, string $data, array $tags = [], int $lifetime = null): void
public function set(string $entryIdentifier, string $data, array $tags = [], ?int $lifetime = null): void
{
if ($entryIdentifier !== basename($entryIdentifier)) {
throw new \InvalidArgumentException('The specified entry identifier must not contain a path segment.', 1282073032);
Expand Down Expand Up @@ -476,6 +477,6 @@ protected function getEntryIdentifierFromFilename(string $filename): string
{
$cacheEntryFileExtensionLength = strlen($this->cacheEntryFileExtension);

return $cacheEntryFileExtensionLength === 0 ? $filename : substr($filename, 0, - strlen($this->cacheEntryFileExtension));
return $cacheEntryFileExtensionLength === 0 ? $filename : substr($filename, 0, -strlen($this->cacheEntryFileExtension));
}
}
7 changes: 3 additions & 4 deletions Neos.Cache/Classes/Backend/MemcachedBackend.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Neos\Cache\Backend;
Expand Down Expand Up @@ -199,7 +200,7 @@ public function getPrefixedIdentifier(string $entryIdentifier): string
* @throws \InvalidArgumentException if the identifier is not valid or the final memcached key is longer than 250 characters
* @api
*/
public function set(string $entryIdentifier, string $data, array $tags = [], int $lifetime = null): void
public function set(string $entryIdentifier, string $data, array $tags = [], ?int $lifetime = null): void
{
if (strlen($this->getPrefixedIdentifier($entryIdentifier)) > 250) {
throw new \InvalidArgumentException('Could not set value. Key more than 250 characters (' . $this->getPrefixedIdentifier($entryIdentifier) . ').', 1232969508);
Expand Down Expand Up @@ -441,7 +442,5 @@ protected function removeIdentifierFromAllTags(string $entryIdentifier)
* @return void
* @api
*/
public function collectGarbage(): void
{
}
public function collectGarbage(): void {}
}
5 changes: 3 additions & 2 deletions Neos.Cache/Classes/Backend/MultiBackend.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Neos\Cache\Backend;
Expand Down Expand Up @@ -41,7 +42,7 @@ class MultiBackend extends AbstractBackend
protected ?LoggerInterface $logger = null;
protected ?ThrowableStorageInterface $throwableStorage = null;

public function __construct(EnvironmentConfiguration $environmentConfiguration = null, array $options = [])
public function __construct(?EnvironmentConfiguration $environmentConfiguration = null, array $options = [])
{
parent::__construct($environmentConfiguration, $options);

Expand Down Expand Up @@ -96,7 +97,7 @@ protected function buildSubBackend(string $backendClassName, array $backendOptio
/**
* @throws Throwable
*/
public function set(string $entryIdentifier, string $data, array $tags = [], int $lifetime = null): void
public function set(string $entryIdentifier, string $data, array $tags = [], ?int $lifetime = null): void
{
$this->prepareBackends();
foreach ($this->backends as $backend) {
Expand Down
19 changes: 6 additions & 13 deletions Neos.Cache/Classes/Backend/NullBackend.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Neos\Cache\Backend;
Expand Down Expand Up @@ -31,7 +32,7 @@ class NullBackend extends AbstractCacheBackend implements PhpCapableBackendInter
* @param mixed $propertyValue
* @return boolean TRUE
*/
protected function setProperty(string $propertyName, $propertyValue) : bool
protected function setProperty(string $propertyName, $propertyValue): bool
{
return true;
}
Expand All @@ -46,9 +47,7 @@ protected function setProperty(string $propertyName, $propertyValue) : bool
* @return void
* @api
*/
public function set(string $entryIdentifier, string $data, array $tags = [], int $lifetime = null): void
{
}
public function set(string $entryIdentifier, string $data, array $tags = [], ?int $lifetime = null): void {}

/**
* Returns False
Expand Down Expand Up @@ -104,9 +103,7 @@ public function findIdentifiersByTag(string $tag): array
* @return void
* @api
*/
public function flush(): void
{
}
public function flush(): void {}

/**
* Does nothing
Expand Down Expand Up @@ -138,9 +135,7 @@ public function flushByTags(array $tags): int
* @return void
* @api
*/
public function collectGarbage(): void
{
}
public function collectGarbage(): void {}

/**
* Does nothing
Expand All @@ -149,8 +144,6 @@ public function collectGarbage(): void
* @return void
* @api
*/
public function requireOnce(string $identifier)
{
}
public function requireOnce(string $identifier) {}
}
// @codeCoverageIgnoreEnd
5 changes: 3 additions & 2 deletions Neos.Cache/Classes/Backend/PdoBackend.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Neos\Cache\Backend;
Expand Down Expand Up @@ -182,7 +183,7 @@ protected function setBatchSize(int $batchSize): void
* @throws FilesException
* @api
*/
public function set(string $entryIdentifier, string $data, array $tags = [], int $lifetime = null): void
public function set(string $entryIdentifier, string $data, array $tags = [], ?int $lifetime = null): void
{
$this->connect();

Expand Down Expand Up @@ -406,7 +407,7 @@ public function flushByTags(array $tags): int
$statementHandle = $this->databaseHandle->prepare('SELECT "identifier" FROM "' . $this->tagsTableName . '" WHERE "context"=? AND "cache"=? AND "tag" IN (' . $tagPlaceholders . ')');
$statementHandle->execute(array_merge([$this->context(), $this->cacheIdentifier], $tagList));
$result = $statementHandle->fetchAll();
$identifiers[]= array_column($result, 'identifier');
$identifiers[] = array_column($result, 'identifier');
}
$identifiers = array_merge([], ...$identifiers);

Expand Down
11 changes: 5 additions & 6 deletions Neos.Cache/Classes/Backend/RedisBackend.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Neos\Cache\Backend;
Expand Down Expand Up @@ -109,7 +110,7 @@ public function __construct(EnvironmentConfiguration $environmentConfiguration,
* @throws CacheException
* @api
*/
public function set(string $entryIdentifier, string $data, array $tags = [], int $lifetime = null): void
public function set(string $entryIdentifier, string $data, array $tags = [], ?int $lifetime = null): void
{
if ($this->isFrozen()) {
throw new \RuntimeException(sprintf('Cannot add or modify cache entry because the backend of cache "%s" is frozen.', $this->cacheIdentifier), 1323344192);
Expand Down Expand Up @@ -254,9 +255,7 @@ public function flush(): void
*
* @api
*/
public function collectGarbage(): void
{
}
public function collectGarbage(): void {}

/**
* Removes all cache entries of this cache which are tagged by the specified tag.
Expand Down Expand Up @@ -493,7 +492,7 @@ public function setBatchSize(int|string $batchSize): void
$this->batchSize = (int)$batchSize;
}

public function setRedis(\Redis $redis = null): void
public function setRedis(?\Redis $redis = null): void
{
if ($redis !== null) {
$this->redis = $redis;
Expand Down Expand Up @@ -601,7 +600,7 @@ private function getEntryIterator(): \Iterator
$prefixLength = strlen($prefix);
$keys = $this->redis->keys($prefix . '*');
if (is_array($keys)) {
$entryIdentifiers = array_map(static fn (string $key) => substr($key, $prefixLength), $keys);
$entryIdentifiers = array_map(static fn(string $key) => substr($key, $prefixLength), $keys);
} else {
$entryIdentifiers = [];
}
Expand Down
9 changes: 4 additions & 5 deletions Neos.Cache/Classes/Backend/SimpleFileBackend.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Neos\Cache\Backend;
Expand Down Expand Up @@ -145,7 +146,7 @@ public function getCacheDirectory(): string
* @throws \InvalidArgumentException
* @api
*/
public function set(string $entryIdentifier, string $data, array $tags = [], int $lifetime = null): void
public function set(string $entryIdentifier, string $data, array $tags = [], ?int $lifetime = null): void
{
if ($entryIdentifier !== basename($entryIdentifier)) {
throw new \InvalidArgumentException('The specified entry identifier must not contain a path segment.', 1334756735);
Expand Down Expand Up @@ -303,9 +304,7 @@ protected function isCacheFileExpired(string $cacheEntryPathAndFilename): bool
* @return void
* @api
*/
public function collectGarbage(): void
{
}
public function collectGarbage(): void {}

/**
* Tries to find the cache entry for the specified identifier.
Expand Down Expand Up @@ -493,7 +492,7 @@ protected function verifyCacheDirectory(): void
* @param int|null $maxlen
* @return string|false The contents of the cache file or false on error
*/
protected function readCacheFile(string $cacheEntryPathAndFilename, int $offset = 0, int $maxlen = null)
protected function readCacheFile(string $cacheEntryPathAndFilename, int $offset = 0, ?int $maxlen = null)
{
for ($i = 0; $i < 3; $i++) {
$data = false;
Expand Down
7 changes: 3 additions & 4 deletions Neos.Cache/Classes/Backend/TransientMemoryBackend.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Neos\Cache\Backend;
Expand Down Expand Up @@ -45,7 +46,7 @@ class TransientMemoryBackend extends IndependentAbstractBackend implements Tagga
* @throws Exception if no cache frontend has been set.
* @api
*/
public function set(string $entryIdentifier, string $data, array $tags = [], int $lifetime = null): void
public function set(string $entryIdentifier, string $data, array $tags = [], ?int $lifetime = null): void
{
if (!$this->cache instanceof FrontendInterface) {
throw new Exception('No cache frontend has been set yet via setCache().', 1238244992);
Expand Down Expand Up @@ -172,7 +173,5 @@ public function flushByTags(array $tags): int
* @return void
* @api
*/
public function collectGarbage(): void
{
}
public function collectGarbage(): void {}
}
3 changes: 2 additions & 1 deletion Neos.Cache/Classes/Frontend/FrontendInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Neos\Cache\Frontend;
Expand Down Expand Up @@ -56,7 +57,7 @@ public function getBackend();
* @return void
* @api
*/
public function set(string $entryIdentifier, $data, array $tags = [], int $lifetime = null);
public function set(string $entryIdentifier, $data, array $tags = [], ?int $lifetime = null);

/**
* Finds and returns data from the cache.
Expand Down
3 changes: 2 additions & 1 deletion Neos.Cache/Classes/Frontend/PhpFrontend.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Neos\Cache\Frontend;
Expand Down Expand Up @@ -92,7 +93,7 @@ public function getWrapped(string $entryIdentifier)
* @throws \Neos\Cache\Exception
* @api
*/
public function set(string $entryIdentifier, $sourceCode, array $tags = [], int $lifetime = null)
public function set(string $entryIdentifier, $sourceCode, array $tags = [], ?int $lifetime = null)
{
if (!$this->isValidEntryIdentifier($entryIdentifier)) {
throw new \InvalidArgumentException('"' . $entryIdentifier . '" is not a valid cache entry identifier.', 1264023823);
Expand Down
3 changes: 2 additions & 1 deletion Neos.Cache/Classes/Frontend/StringFrontend.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Neos\Cache\Frontend;
Expand Down Expand Up @@ -37,7 +38,7 @@ class StringFrontend extends AbstractFrontend
* @throws \Neos\Cache\Exception
* @api
*/
public function set(string $entryIdentifier, $string, array $tags = [], int $lifetime = null)
public function set(string $entryIdentifier, $string, array $tags = [], ?int $lifetime = null)
{
if (!$this->isValidEntryIdentifier($entryIdentifier)) {
throw new \InvalidArgumentException('"' . $entryIdentifier . '" is not a valid cache entry identifier.', 1233057566);
Expand Down
3 changes: 2 additions & 1 deletion Neos.Cache/Classes/Frontend/VariableFrontend.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Neos\Cache\Frontend;
Expand Down Expand Up @@ -56,7 +57,7 @@ public function initializeObject()
* @throws \Neos\Cache\Exception
* @api
*/
public function set(string $entryIdentifier, $variable, array $tags = [], int $lifetime = null)
public function set(string $entryIdentifier, $variable, array $tags = [], ?int $lifetime = null)
{
if (!$this->isValidEntryIdentifier($entryIdentifier)) {
throw new \InvalidArgumentException('"' . $entryIdentifier . '" is not a valid cache entry identifier.', 1233058264);
Expand Down
Loading

0 comments on commit fd7b3ce

Please sign in to comment.