Skip to content

DRAFT: Raise PhpStan to level 8 #3474

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

Draft
wants to merge 61 commits into
base: 10.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
efdfb99
WIP: Adjust Neos.Utility.Unicode
Apr 4, 2025
24841c8
Adjust Neos.Utility.Schema
Apr 4, 2025
dc1511e
Adjust Neos.Utility.Pdo
Apr 4, 2025
dfda13f
Adjust Neos.Utility.ObjectHandling
Apr 4, 2025
7438083
Remove erroneous class check
May 3, 2025
bc1d69e
Adjust Neos.Utility.MediaTypes
Apr 4, 2025
d065384
Adjust Neos.Utility.Files
Apr 4, 2025
9cfb4ae
Adjust Neos.Utility.Arrays
Apr 4, 2025
af67fce
Adjust Neos.Kickstarter
Apr 5, 2025
cc6955e
Adjust Neos.Http.Factories
Apr 5, 2025
756716f
Adjust Neos.Http.Factories
Apr 5, 2025
326b230
Adjust Neos.FluidAdaptor
Apr 5, 2025
5ae150c
Adjust Neos.Flow.Log
Apr 5, 2025
7f4fc26
Adjust Neos.Flow Validation subcontext
Apr 6, 2025
917b5a9
Adjust Neos.Flow Utility subcontext
Apr 6, 2025
1127202
Adjust Neos.Flow SignalSlot subcontext
Apr 6, 2025
ab3890b
Remove erroneous class check
May 3, 2025
ae5211c
Adjust Neos.Flow Session subcontext
Apr 6, 2025
ac89ec0
Adjust Neos.Flow Security subcontext
Apr 6, 2025
e20d514
Adjust Neos.Flow ResourceManagement subcontext
Apr 6, 2025
c04335b
Adjust Neos.Flow Reflection subcontext
Apr 7, 2025
a896aa2
Revert erroneous reflection and class checks
May 3, 2025
162a294
Fix TypeHandling::getTypeForValue
May 3, 2025
c9a6a3f
Adjust Neos.Flow Property subcontext
Apr 7, 2025
7283d5c
Adjust Neos.Flow Persistence subcontext
Apr 8, 2025
46e7383
Adjust Neos.Flow Package subcontext
Apr 8, 2025
8518eb7
Adjust Neos.Flow ObjectManagement subcontext
Apr 10, 2025
1f1fd6e
Revert erroneous type check simplifications
May 3, 2025
462a3d4
Adjust Neos.Flow Mvc subcontext
Apr 10, 2025
dab39e4
Adjust Neos.Flow Monitor subcontext
Apr 11, 2025
481e597
Revert erroneous JSON errors
May 3, 2025
f2000cc
Adjust Neos.Flow Log subcontext
Apr 11, 2025
4ab945e
Adjust Neos.Flow I18n subcontext
Apr 11, 2025
b18e7d4
Adjust Neos.Flow Http subcontext
Apr 12, 2025
2b2986b
Adjust Neos.Http.Factories to Neos.Flow Http subcontext adjustments
Apr 12, 2025
39cd85a
Adjust Neos.Flow Error subcontext
Apr 12, 2025
74e4187
Adjust Neos.Flow core
Apr 12, 2025
dd625de
Adjust Neos.Flow Configuration subcontext
Apr 12, 2025
320beb0
Adjust Neos.Flow Composer subcontext
Apr 12, 2025
4adc473
Adjust Neos.Flow Cli subcontext
Apr 12, 2025
16f3e3b
Adjust Neos.Flow Cache subcontext
Apr 12, 2025
9c14a39
Adjust Neos.Flow Aop subcontext
Apr 12, 2025
40d64b0
PATCH: Exception during the reflection of the `JoinPoint`
mhsdesign May 3, 2025
b0fc342
Fix erroneous class checks
May 3, 2025
36b5308
Adjust Neos.Flow Annotations subcontext
Apr 12, 2025
04cdb68
Adjust Neos.Flow application layer
Apr 12, 2025
e03066c
Adjust Neos.Error.Messages
Apr 13, 2025
ecf3392
Adjust Neos.Eel
Apr 13, 2025
297419f
Adjust Neos.Cache
Apr 13, 2025
048d932
add scanDirectories folders for special classes
Apr 13, 2025
0668bae
PATCH: Make PHP 8.2 compatible
mhsdesign May 3, 2025
d133471
Pacify linter for now
May 3, 2025
62fd9d4
PATCH: Apply style CI
mhsdesign May 3, 2025
7cda227
PATCH: Apply style CI 2.0
mhsdesign May 3, 2025
9a040aa
PATCH: Fix custom testing context auto loading
mhsdesign May 3, 2025
e888328
PATCH: Fix ScriptsTest
mhsdesign May 3, 2025
ff58ff8
PATCH: Use method->(...) instead of array call syntax for autoloader
mhsdesign May 3, 2025
4464059
PATCH: Remove wrong cookie constructor validation
mhsdesign May 4, 2025
2e16a51
PATCH: Allow cookie to have nullable path
mhsdesign May 4, 2025
3112fce
PATCH: Fix invalid @throws annotations
mhsdesign May 4, 2025
69df78b
PATCH: Document ReflectionService phpstan hack
mhsdesign May 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
21 changes: 9 additions & 12 deletions Neos.Cache/Classes/Backend/AbstractBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ abstract class AbstractBackend implements BackendInterface

/**
* Reference to the cache frontend which uses this backend
* @var FrontendInterface
* @var ?FrontendInterface
*/
protected $cache;

/**
* @var string
* @var ?string
*/
protected $cacheIdentifier;

/**
* A prefix to seperate stored by appliaction context and cache
* @var string
* A prefix to separate stored by application context and cache
* @var ?string
*/
protected $identifierPrefix;

Expand All @@ -50,28 +50,25 @@ abstract class AbstractBackend implements BackendInterface
protected $defaultLifetime = 3600;

/**
* @var EnvironmentConfiguration
* @var ?EnvironmentConfiguration
*/
protected $environmentConfiguration;

/**
* Constructs this backend
*
* @param EnvironmentConfiguration $environmentConfiguration
* @param array $options Configuration options - depends on the actual backend
* @param ?EnvironmentConfiguration $environmentConfiguration @todo is this ever null and does that even make sense?
* @param array<mixed> $options Configuration options - depends on the actual backend
* @api
*/
public function __construct(?EnvironmentConfiguration $environmentConfiguration = null, array $options = [])
{
$this->environmentConfiguration = $environmentConfiguration;

if (is_array($options) || $options instanceof \Iterator) {
$this->setProperties($options);
}
$this->setProperties($options);
}

/**
* @param array $properties
* @param array<mixed> $properties
* @param boolean $throwExceptionIfPropertyNotSettable
* @return void
* @throws \InvalidArgumentException
Expand Down
9 changes: 7 additions & 2 deletions Neos.Cache/Classes/Backend/ApcuBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ public function setCache(FrontendInterface $cache): void
{
parent::setCache($cache);

if ($this->environmentConfiguration === null) {
throw new \RuntimeException('The environment configuration is not set.', 1744537489);
}

$pathHash = substr(md5($this->environmentConfiguration->getApplicationIdentifier() . $cache->getIdentifier()), 0, 12);
$this->identifierPrefix = 'Flow_' . $pathHash . '_';
}
Expand Down Expand Up @@ -110,7 +114,7 @@ public function getPrefixedIdentifier(string $entryIdentifier): string
*
* @param string $entryIdentifier An identifier for this specific cache entry
* @param string $data The data to be stored
* @param array $tags Tags to associate with this cache entry
* @param array<string> $tags Tags to associate with this cache entry
* @param int|null $lifetime Lifetime of this cache entry in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited lifetime.
* @return void
* @throws Exception if no cache frontend has been set.
Expand Down Expand Up @@ -263,7 +267,7 @@ public function flushByTags(array $tags): int
* Associates the identifier with the given tags
*
* @param string $entryIdentifier
* @param array $tags
* @param array<string> $tags
* @return void
*/
protected function addIdentifierToTags(string $entryIdentifier, array $tags)
Expand Down Expand Up @@ -391,6 +395,7 @@ public function valid(): bool
*
* @return void
* @api
* @phpstan-assert \APCUIterator $this->cacheEntriesIterator
*/
#[\ReturnTypeWillChange]
public function rewind()
Expand Down
2 changes: 1 addition & 1 deletion Neos.Cache/Classes/Backend/BackendInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function getPrefixedIdentifier(string $entryIdentifier): string;
*
* @param string $entryIdentifier An identifier for this specific cache entry
* @param string $data The data to be stored
* @param array $tags Tags to associate with this cache entry. If the backend does not support tags, this option can be ignored.
* @param array<string> $tags Tags to associate with this cache entry. If the backend does not support tags, this option can be ignored.
* @param integer|null $lifetime Lifetime of this cache entry in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited lifetime.
* @return void
* @throws \Neos\Cache\Exception if no cache frontend has been set.
Expand Down
9 changes: 6 additions & 3 deletions Neos.Cache/Classes/Backend/FileBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class FileBackend extends SimpleFileBackend implements PhpCapableBackendInterfac
protected $cacheEntryFileExtension = '';

/**
* @var array<string>
* @var array<string, true> @phpstan-ignore property.phpDocType (this backend seems to work differently)
*/
protected $cacheEntryIdentifiers = [];

Expand Down Expand Up @@ -90,6 +90,9 @@ public function freeze(): void
$cachePathAndFileName = $this->cacheDirectory . 'FrozenCache.data';
if ($this->useIgBinary === true) {
$data = igbinary_serialize($this->cacheEntryIdentifiers);
if ($data === null) {
throw new \RuntimeException('Failed to serialize cache entry identifiers', 1744536663);
}
} else {
$data = serialize($this->cacheEntryIdentifiers);
}
Expand Down Expand Up @@ -140,8 +143,8 @@ public function setCache(FrontendInterface $cache): void
*
* @param string $entryIdentifier An identifier for this specific cache entry
* @param string $data The data to be stored
* @param array $tags Tags to associate with this cache entry
* @param integer $lifetime Lifetime of this cache entry in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited lifetime.
* @param array<string> $tags Tags to associate with this cache entry
* @param ?integer $lifetime Lifetime of this cache entry in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited lifetime.
* @return void
* @throws \RuntimeException
* @throws Exception if the directory does not exist or is not writable or exceeds the maximum allowed path length, or if no cache frontend has been set.
Expand Down
1 change: 1 addition & 0 deletions Neos.Cache/Classes/Backend/IterableBackendInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
/**
* A contract for a cache backend which provides Iterator functionality.
*
* @extends \Iterator<int|string,mixed>
* @api
*/
interface IterableBackendInterface extends BackendInterface, \Iterator
Expand Down
15 changes: 15 additions & 0 deletions Neos.Cache/Classes/Backend/IterableMultiBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public function current(): mixed
$this->prepareBackends();
foreach ($this->backends as $backend) {
try {
if (!method_exists($backend, 'current')) {
throw new \RuntimeException(get_class($backend) . ' does not implement rewind');
}
return $backend->current();
} catch (Throwable $throwable) {
$this->logger?->error('Failed retrieving current cache entry using backend ' . get_class($backend) . ' in ' . get_class($this) . ': ' . $this->throwableStorage?->logThrowable($throwable), LogEnvironment::fromMethodName(__METHOD__));
Expand All @@ -63,6 +66,9 @@ public function next(): void
$this->prepareBackends();
foreach ($this->backends as $backend) {
try {
if (!method_exists($backend, 'next')) {
throw new \RuntimeException(get_class($backend) . ' does not implement rewind');
}
$backend->next();
} catch (Throwable $throwable) {
$this->logger?->error('Failed retrieving next cache entry using backend ' . get_class($backend) . ' in ' . get_class($this) . ': ' . $this->throwableStorage?->logThrowable($throwable), LogEnvironment::fromMethodName(__METHOD__));
Expand All @@ -80,6 +86,9 @@ public function key(): string|int|bool|null|float
$this->prepareBackends();
foreach ($this->backends as $backend) {
try {
if (!method_exists($backend, 'key')) {
throw new \RuntimeException(get_class($backend) . ' does not implement rewind');
}
return $backend->key();
} catch (Throwable $throwable) {
$this->logger?->error('Failed retrieving cache entry key using backend ' . get_class($backend) . ' in ' . get_class($this) . ': ' . $this->throwableStorage?->logThrowable($throwable), LogEnvironment::fromMethodName(__METHOD__));
Expand All @@ -98,6 +107,9 @@ public function valid(): bool
$this->prepareBackends();
foreach ($this->backends as $backend) {
try {
if (!method_exists($backend, 'valid')) {
throw new \RuntimeException(get_class($backend) . ' does not implement rewind');
}
return $backend->valid();
} catch (Throwable $throwable) {
$this->logger?->error('Failed checking if current cache entry is valid using backend ' . get_class($backend) . ' in ' . get_class($this) . ': ' . $this->throwableStorage?->logThrowable($throwable), LogEnvironment::fromMethodName(__METHOD__));
Expand All @@ -116,6 +128,9 @@ public function rewind(): void
$this->prepareBackends();
foreach ($this->backends as $backend) {
try {
if (!method_exists($backend, 'rewind')) {
throw new \RuntimeException(get_class($backend) . ' does not implement rewind');
}
$backend->rewind();
} catch (Throwable $throwable) {
$this->logger?->error('Failed rewinding cache entries using backend ' . get_class($backend) . ' in ' . get_class($this) . ': ' . $this->throwableStorage?->logThrowable($throwable), LogEnvironment::fromMethodName(__METHOD__));
Expand Down
20 changes: 12 additions & 8 deletions Neos.Cache/Classes/Backend/MemcachedBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class MemcachedBackend extends IndependentAbstractBackend implements TaggableBac
/**
* Array of Memcache server configurations
*
* @var array
* @var array<string>
*/
protected $servers = [];

Expand Down Expand Up @@ -102,7 +102,7 @@ public function __construct(EnvironmentConfiguration $environmentConfiguration,
* Setter for servers to be used. Expects an array, the values are expected
* to be formatted like "<host>[:<port>]" or "unix://<path>"
*
* @param array $servers An array of servers to add.
* @param array<string> $servers An array of servers to add.
* @return void
* @throws Exception
* @api
Expand All @@ -121,12 +121,12 @@ protected function setServers(array $servers)
$host = $server;
$port = 0;

if (strpos($server, 'tcp://') === 0) {
if (str_starts_with($server, 'tcp://')) {
$port = $defaultPort;
$server = substr($server, 6);
}

if (strpos($server, ':') !== false) {
if (str_contains($server, ':')) {
[$host, $portValue] = explode(':', $server, 2);
$port = (int)$portValue;
}
Expand Down Expand Up @@ -165,6 +165,10 @@ public function setCache(FrontendInterface $cache): void
{
parent::setCache($cache);

if ($this->environmentConfiguration === null) {
throw new \RuntimeException('No environment configuration set', 1744535714);
}

$pathHash = substr(md5($this->environmentConfiguration->getApplicationIdentifier() . $cache->getIdentifier()), 0, 12);
$this->identifierPrefix = 'Flow_' . $pathHash . '_';
}
Expand Down Expand Up @@ -192,8 +196,8 @@ public function getPrefixedIdentifier(string $entryIdentifier): string
*
* @param string $entryIdentifier An identifier for this specific cache entry
* @param string $data The data to be stored
* @param array $tags Tags to associate with this cache entry
* @param integer $lifetime Lifetime of this cache entry in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited lifetime.
* @param array<string> $tags Tags to associate with this cache entry
* @param ?integer $lifetime Lifetime of this cache entry in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited lifetime.
* @return void
* @throws Exception if no cache frontend has been set.
* @throws \InvalidArgumentException if the identifier is not valid or the final memcached key is longer than 250 characters
Expand Down Expand Up @@ -325,7 +329,7 @@ public function findIdentifiersByTag(string $tag): array
* index to search for tags.
*
* @param string $identifier Identifier to find tags by
* @return array Array with tags
* @return array<string> Array with tags
*/
protected function findTagsByIdentifier(string $identifier): array
{
Expand Down Expand Up @@ -383,7 +387,7 @@ public function flushByTags(array $tags): int
* Associates the identifier with the given tags
*
* @param string $entryIdentifier
* @param array $tags
* @param array<string> $tags
* @return void
*/
protected function addIdentifierToTags(string $entryIdentifier, array $tags)
Expand Down
17 changes: 15 additions & 2 deletions Neos.Cache/Classes/Backend/MultiBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ class MultiBackend extends AbstractBackend
{
use BackendInstantiationTrait;

/**
* @var array<mixed>
*/
protected array $backendConfigurations = [];
/**
* @var array<int,BackendInterface>
*/
protected array $backends = [];
protected bool $setInAllBackends = true;
protected bool $debug = false;
Expand All @@ -48,10 +54,8 @@ public function __construct(?EnvironmentConfiguration $environmentConfiguration
if ($this->logErrors && class_exists(Bootstrap::class) && Bootstrap::$staticObjectManager instanceof ObjectManagerInterface) {
try {
$logger = Bootstrap::$staticObjectManager->get(LoggerInterface::class);
assert($logger instanceof LoggerInterface);
$this->logger = $logger;
$throwableStorage = Bootstrap::$staticObjectManager->get(ThrowableStorageInterface::class);
assert($throwableStorage instanceof ThrowableStorageInterface);
$this->throwableStorage = $throwableStorage;
} catch (UnknownObjectException) {
// Logging might not be available during compile time
Expand All @@ -78,11 +82,18 @@ protected function prepareBackends(): void
}

/**
* @param array<mixed> $backendOptions
* @throws Throwable
*/
protected function buildSubBackend(string $backendClassName, array $backendOptions): ?BackendInterface
{
try {
if ($this->cache === null) {
throw new \RuntimeException('Cache frontend is not yet initialized', 1744535490);
}
if ($this->environmentConfiguration === null) {
throw new \RuntimeException('Environment configuration is missing', 1744535532);
}
$backend = $this->instantiateBackend($backendClassName, $backendOptions, $this->environmentConfiguration);
$backend->setCache($this->cache);
} catch (Throwable $throwable) {
Expand All @@ -95,6 +106,7 @@ protected function buildSubBackend(string $backendClassName, array $backendOptio

/**
* @throws Throwable
* @param array<string> $tags
*/
public function set(string $entryIdentifier, string $data, array $tags = [], ?int $lifetime = null): void
{
Expand Down Expand Up @@ -204,6 +216,7 @@ public function collectGarbage(): void

/**
* This setter is used by AbstractBackend::setProperties()
* @param array<mixed> $backendConfigurations
*/
protected function setBackendConfigurations(array $backendConfigurations): void
{
Expand Down
4 changes: 2 additions & 2 deletions Neos.Cache/Classes/Backend/NullBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ protected function setProperty(string $propertyName, $propertyValue) : bool
*
* @param string $entryIdentifier ignored
* @param string $data ignored
* @param array $tags ignored
* @param integer $lifetime ignored
* @param array<string> $tags ignored
* @param ?integer $lifetime ignored
* @return void
* @api
*/
Expand Down
12 changes: 8 additions & 4 deletions Neos.Cache/Classes/Backend/PdoBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class PdoBackend extends IndependentAbstractBackend implements TaggableBackendIn
protected $password;

/**
* @var array
* @var array<mixed>
*/
protected $driverOptions = [];

Expand Down Expand Up @@ -83,7 +83,7 @@ class PdoBackend extends IndependentAbstractBackend implements TaggableBackendIn
protected $batchSize = 999;

/**
* @var \ArrayIterator|null
* @var \ArrayIterator<string,mixed>|null
*/
protected $cacheEntriesIterator;

Expand Down Expand Up @@ -126,7 +126,7 @@ protected function setPassword(string $password): void
/**
* Sets the driverOptions to use
*
* @param array $driverOptions The options to use for connecting to the DB
* @param array<mixed> $driverOptions The options to use for connecting to the DB
* @return void
* @api
*/
Expand Down Expand Up @@ -174,7 +174,7 @@ protected function setBatchSize(int $batchSize): void
*
* @param string $entryIdentifier An identifier for this specific cache entry
* @param string $data The data to be stored
* @param array $tags Tags to associate with this cache entry
* @param array<string> $tags Tags to associate with this cache entry
* @param int|null $lifetime Lifetime of this cache entry in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited lifetime.
* @return void
* @throws Exception if no cache frontend has been set.
Expand Down Expand Up @@ -613,6 +613,7 @@ public function valid(): bool
*
* @return void
* @api
* @phpstan-assert \ArrayIterator<string,mixed> $this->cacheEntriesIterator
*/
public function rewind(): void
{
Expand Down Expand Up @@ -647,6 +648,9 @@ public function rewind(): void
protected function context(): string
{
if ($this->context === null) {
if ($this->environmentConfiguration === null) {
throw new \RuntimeException('Environment configuration not set', 1744534618);
}
$this->context = md5($this->environmentConfiguration->getApplicationIdentifier());
}
return $this->context;
Expand Down
Loading
Loading