Skip to content

Commit

Permalink
Merge pull request #4842 from mhsdesign/task/phpStan83
Browse files Browse the repository at this point in the history
TASK: PhpStan level 1 for Neos 8.3
  • Loading branch information
mhsdesign authored Feb 2, 2024
2 parents 31055c7 + 6b338b4 commit 59478f8
Show file tree
Hide file tree
Showing 40 changed files with 104 additions and 59 deletions.
6 changes: 6 additions & 0 deletions .composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
"require": {
"neos/flow-development-collection": "8.3.x-dev"
},
"scripts": {
"lint:phpstan": "../../bin/phpstan analyse",
"lint": [
"@lint:phpstan"
]
},
"replace": {
},
"suggest": {
Expand Down
32 changes: 10 additions & 22 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
contents: read # to fetch code (actions/checkout)

if: "!contains(github.event.head_commit.message, '[skip ci]') && !contains(github.event.head_commit.message, '[skip travis]')"
name: "PHP ${{ matrix.php-versions }} Test ${{ matrix.static-analysis != 'no' && matrix.static-analysis || '' }} (deps: ${{ matrix.dependencies }})"
name: "PHP ${{ matrix.php-versions }} Test ${{ matrix.static-analysis != 'no' && 'static analysis ' || '' }} (deps: ${{ matrix.dependencies }})"

continue-on-error: ${{ matrix.experimental }}

Expand All @@ -26,24 +26,11 @@ jobs:
composer-arguments: [''] # to run --ignore-platform-reqs in experimental builds
static-analysis: ['no']
experimental: [false]
#include:
#- php-versions: '7.3'
# static-analysis: 'psalm'
# experimental: false
# dependencies: 'highest'

# Experimental build for PHP nightly
#- php-versions: 'nightly'
# composer-arguments: '--ignore-platform-reqs'
# static-analysis: 'no'
# experimental: true
# dependencies: 'highest'

# Build for minimum dependencies. Fails right now, hence deactivated.
#- php-versions: '7.1'
# static-analysis: 'no'
# experimental: false
# dependencies: 'lowest'
include:
- php-versions: '8.1'
static-analysis: 'yes'
experimental: false
dependencies: 'highest'

runs-on: ubuntu-latest
services:
Expand Down Expand Up @@ -142,6 +129,7 @@ jobs:
run: echo "FLOW_CONTEXT=${{ env.FLOW_CONTEXT }}" >> $GITHUB_ENV

- name: Setup Flow configuration
if: matrix.static-analysis == 'no'
run: |
rm -f Configuration/Routes.yaml
rm -f Configuration/Testing/Settings.yaml
Expand All @@ -163,9 +151,9 @@ jobs:
./flow configuration:show
./flow routing:list
#- name: Static analysis
# if: matrix.static-analysis == 'psalm'
# run: composer test-static
- name: Static analysis
if: matrix.static-analysis == 'yes'
run: cd Packages/Neos && composer lint:phpstan

- name: Run unit tests
if: matrix.static-analysis == 'no'
Expand Down
1 change: 1 addition & 0 deletions Neos.ContentRepository/Classes/Domain/Model/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,7 @@ public function getProperty($propertyName, bool $returnNodesAsIdentifiers = fals
}

if (
/** @phpstan-ignore-next-line i will not touch this code */
isset($expectedPropertyType) &&
$expectedPropertyType === 'Neos\Media\Domain\Model\ImageInterface' &&
empty($value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function parseFilterString(string $serializedFilters): NodeTypeConstraint

// in case there are no filters, we fall back to allowing every node type.
// Furthermore, if there are only negated filters, we also fall back to allowing every node type (when the excludelist does not match)
$wildcardAllowed = empty($serializedFilters) || (!empty($serializedFilters) && $onlyNegatedFilters);
$wildcardAllowed = empty($serializedFilters) || $onlyNegatedFilters;

return new NodeTypeConstraints($wildcardAllowed, $explicitlyAllowedNodeTypeNames, $explicitlyDisallowedNodeTypeNames);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public function findByNodeIdentifier($nodeIdentifier)
* @param array $dimensions An array of dimensions with array of ordered values to use for fallback matching
* @param boolean|NULL $removedNodes Include removed nodes, NULL (all), false (no removed nodes) or true (only removed nodes)
* @throws \InvalidArgumentException
* @return NodeData The matching node if found, otherwise NULL
* @return NodeData|null The matching node if found, otherwise NULL
*/
public function findOneByPath($path, Workspace $workspace, array $dimensions = null, $removedNodes = false)
{
Expand Down Expand Up @@ -321,7 +321,7 @@ public function findOneByPathInContext($path, Context $context)
* @param Workspace $workspace The containing workspace
* @param array $dimensions An array of dimensions with array of ordered values to use for fallback matching
* @param bool $removedNodes If shadow nodes should be considered while finding the specified node
* @return NodeData The matching node if found, otherwise NULL
* @return NodeData|null The matching node if found, otherwise NULL
*/
public function findOneByIdentifier($identifier, Workspace $workspace, array $dimensions = null, $removedNodes = false)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ protected function parseDimensionsElement(\XMLReader $reader)
* @param \XMLReader $reader reader positioned just after an opening array-tag
* @param string $elementName
* @param string $currentNodeIdentifier
* @return array the array values
* @return array|null the array values
*/
protected function parseArrayElements(\XMLReader $reader, $elementName, $currentNodeIdentifier)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ abstract protected function loadConfiguration($version);
/**
* Loads a list of available versions into an array.
*
* @return array
* @return void
*/
abstract protected function registerAvailableVersions();
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class YamlConfiguration extends Configuration
/**
* Loads a list of available versions into an array.
*
* @return array
* @return void
* @throws MigrationException
*/
protected function registerAvailableVersions()
Expand Down
4 changes: 2 additions & 2 deletions Neos.Diff/Classes/SequenceMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ public function getGroupedOpcodes($context = 3)
];
}

if (!empty($group) && !(count($group) == 1 && $group[0][0] == 'equal')) {
if (!(count($group) == 1 && $group[0][0] == 'equal')) {
$groups[] = $group;
}

Expand Down Expand Up @@ -640,7 +640,7 @@ private function ratioReduce($sum, array $triple)
* Quickly return an upper bound ratio for the similarity of the strings.
* This is quicker to compute than Ratio().
*
* @return float The calculated ratio.
* @return float|null The calculated ratio.
* @todo throw away or make public
*/
private function quickRatio()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class PlainTextHandler extends AbstractRenderingExceptionHandler
*
* @param string $fusionPath path causing the exception
* @param \Exception $exception exception to handle
* @param integer $referenceCode
* @param integer|null $referenceCode
* @return string
*/
protected function handle($fusionPath, \Exception $exception, $referenceCode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ public function handleRenderingException($fusionPath, \Exception $exception)
*/
protected function handle($fusionPath, \Exception $exception, $referenceCode)
{
throw new \BadMethodCallException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function injectThrowableStorage(ThrowableStorageInterface $throwableStora
*
* @param string $fusionPath path causing the exception
* @param \Exception $exception exception to handle
* @param integer $referenceCode
* @param integer|null $referenceCode
* @return string
*/
protected function handle($fusionPath, \Exception $exception, $referenceCode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ protected static function resolveRelativePath(string $filePattern, ?string $file
*/
protected static function parseGlobPatternAndResolveFiles(string $filePattern, string $defaultFileNameEnd): array
{
$matches = null;
$fileIteratorCreator = match (1) {
// We use the flag SKIP_DOTS, as it might not be allowed to access `..` and we only are interested in files
// We use the flag UNIX_PATHS, so that stream wrapper paths are always valid on windows https://github.com/neos/neos-development-collection/issues/4358
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@

/**
* Parses a Fusion File to object ast-nodes
* @phpstan-consistent-constructor
*/
class ObjectTreeParser
{
Expand Down
2 changes: 2 additions & 0 deletions Neos.Fusion/Classes/Core/RuntimeConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public function forPath(string $fusionPath): array

// Build configuration for the remaining path parts
$remainingPath = substr($fusionPath, $pathUntilNow === '' ? 0 : strlen($pathUntilNow) + 1);
/** @var non-empty-list<string> $pathParts */
$pathParts = explode('/', $remainingPath);
foreach ($pathParts as $pathPart) {
if ($pathUntilNow === '') {
Expand All @@ -106,6 +107,7 @@ public function forPath(string $fusionPath): array
continue;
}

/** @phpstan-ignore-next-line $configuration is set */
$configuration = $this->matchCurrentPathPart($pathPart, $configuration, $currentPrototypeDefinitions);
$this->pathCache[$pathUntilNow]['c'] = $configuration;
$this->pathCache[$pathUntilNow]['p'] = $currentPrototypeDefinitions;
Expand Down
6 changes: 6 additions & 0 deletions Neos.Fusion/Classes/FusionObjects/Helpers/FusionPathProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public function __construct(TemplateImplementation $templateImplementation, $pat
* @param string $offset
* @return boolean
*/
#[\ReturnTypeWillChange]
public function offsetExists($offset)
{
return isset($this->partialFusionTree[$offset]);
Expand All @@ -88,6 +89,7 @@ public function offsetExists($offset)
* @param string $offset
* @return mixed|FusionPathProxy
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
if (!isset($this->partialFusionTree[$offset])) {
Expand All @@ -109,6 +111,7 @@ public function offsetGet($offset)
* @param mixed $value
* @throws UnsupportedProxyMethodException
*/
#[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
throw new UnsupportedProxyMethodException('Setting a property of a path proxy not supported. (tried to set: ' . $this->path . ' -- ' . $offset . ')', 1372667221);
Expand All @@ -120,6 +123,7 @@ public function offsetSet($offset, $value)
* @param string $offset
* @throws UnsupportedProxyMethodException
*/
#[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
throw new UnsupportedProxyMethodException('Unsetting a property of a path proxy not supported. (tried to unset: ' . $this->path . ' -- ' . $offset . ')', 1372667331);
Expand Down Expand Up @@ -152,6 +156,7 @@ public function objectAccess()
*
* @return \ArrayIterator
*/
#[\ReturnTypeWillChange]
public function getIterator()
{
$evaluatedArray = [];
Expand All @@ -172,6 +177,7 @@ public function getIterator()
/**
* @return integer
*/
#[\ReturnTypeWillChange]
public function count()
{
return count($this->partialFusionTree);
Expand Down
4 changes: 2 additions & 2 deletions Neos.Fusion/Classes/FusionObjects/Helpers/LazyProps.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ public function offsetGet($path): mixed

public function offsetSet($path, $value): void
{
throw new BadMethodCallException('Lazy props can not be set.', 1588182804);
throw new \BadMethodCallException('Lazy props can not be set.', 1588182804);
}

public function offsetUnset($path): void
{
throw new BadMethodCallException('Lazy props can not be unset.', 1588182805);
throw new \BadMethodCallException('Lazy props can not be unset.', 1588182805);
}

public function current(): mixed
Expand Down
1 change: 1 addition & 0 deletions Neos.Fusion/Classes/Service/DebugStack.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function dump()
$this->flush();
$output = '';
foreach ($data as $debugMessage) {
/** @phpstan-ignore-next-line var_dump is not properly autoloaded */
$output .= \Neos\Flow\var_dump($debugMessage->getData(), $debugMessage->getTitle(), true, $debugMessage->isPlaintext());
}
return $output;
Expand Down
2 changes: 1 addition & 1 deletion Neos.Media.Browser/Classes/Controller/AssetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ public function indexAction($view = null, $sortBy = null, $sortDirection = null,

$allCollectionsCount = $this->assetRepository->countAll();
$allCount = ($activeAssetCollection ? $this->assetRepository->countByAssetCollection($activeAssetCollection) : $allCollectionsCount);
$searchResultCount = isset($assetProxies) ? $assetProxies->count() : 0;
$searchResultCount = $assetProxies->count();
$untaggedCount = ($assetProxyRepository instanceof SupportsTaggingInterface ? $assetProxyRepository->countUntagged() : 0);
} catch (AssetSourceConnectionExceptionInterface $e) {
$this->view->assign('connectionError', $e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public function current(): ?AssetProxyInterface
/**
* @return void
*/
#[\ReturnTypeWillChange]
public function next()
{
$this->flowPersistenceQueryResult->next();
Expand All @@ -108,6 +109,7 @@ public function next()
/**
* @return AssetProxyInterface|null
*/
#[\ReturnTypeWillChange]
public function key()
{
return $this->flowPersistenceQueryResult->key();
Expand All @@ -116,6 +118,7 @@ public function key()
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function valid()
{
return $this->flowPersistenceQueryResult->valid();
Expand All @@ -134,6 +137,7 @@ public function rewind()
* @param mixed $offset
* @return bool
*/
#[\ReturnTypeWillChange]
public function offsetExists($offset)
{
return $this->flowPersistenceQueryResult->offsetExists($offset);
Expand All @@ -143,6 +147,7 @@ public function offsetExists($offset)
* @param mixed $offset
* @return AssetProxyInterface|mixed
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset): ?AssetProxyInterface
{
return new NeosAssetProxy($this->flowPersistenceQueryResult->offsetGet($offset), $this->assetSource);
Expand All @@ -152,6 +157,7 @@ public function offsetGet($offset): ?AssetProxyInterface
* @param mixed $offset
* @param mixed $value
*/
#[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
throw new \RuntimeException('Unsupported operation: ' . __METHOD__, 1510060444);
Expand All @@ -160,6 +166,7 @@ public function offsetSet($offset, $value)
/**
* @param mixed $offset
*/
#[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
throw new \RuntimeException('Unsupported operation: ' . __METHOD__, 1510060467);
Expand Down
2 changes: 1 addition & 1 deletion Neos.Media/Classes/Domain/Service/AssetService.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ public function replaceAssetResource(AssetInterface $asset, PersistentResource $
}
}

if ($redirectHandlerEnabled) {
if ($redirectHandlerEnabled && class_exists(RedirectStorageInterface::class)) {
/** @var RedirectStorageInterface $redirectStorage */
$redirectStorage = $this->objectManager->get(RedirectStorageInterface::class);
foreach ($uriMapping as $originalUri => $newUri) {
Expand Down
3 changes: 3 additions & 0 deletions Neos.Media/Classes/Imagine/Box.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
use Imagine\Image\Point;
use Imagine\Image\PointInterface;

/**
* @phpstan-consistent-constructor
*/
class Box implements BoxInterface
{
/**
Expand Down
1 change: 1 addition & 0 deletions Neos.Media/Classes/TypeConverter/ArrayConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,6 @@ public function convertFrom($source, $targetType, array $convertedChildPropertie
'assetCollections' => $convertedChildProperties['assetCollections']
];
}
return null;
}
}
Loading

0 comments on commit 59478f8

Please sign in to comment.