Skip to content

Commit

Permalink
FEATURE: Introduce phpstan with level 8
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Jun 18, 2024
1 parent 32c8d5c commit 1f9ffc0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
35 changes: 23 additions & 12 deletions Classes/Fusion/XmlSitemapUrlsImplementation.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,16 @@
use Neos\Flow\Persistence\Doctrine\PersistenceManager;
use Neos\Fusion\FusionObjects\AbstractFusionObject;
use Neos\Media\Domain\Model\ImageInterface;
use Neos\Utility\Exception\PropertyNotAccessibleException;

/**
* @phpstan-type SitemapUrlItem array{
* node: Node,
* lastModificationDateTime: \DateTimeImmutable,
* priority: string,
* images: array<string, ImageInterface>,
* changeFrequency?: true
* }
*/
class XmlSitemapUrlsImplementation extends AbstractFusionObject
{
#[Flow\Inject]
Expand All @@ -36,7 +44,7 @@ class XmlSitemapUrlsImplementation extends AbstractFusionObject
protected PersistenceManager $persistenceManager;

/**
* @var array<string, array<int, string>>
* @var array<string, list<string>>
*/
protected array $assetPropertiesByNodeType = [];

Expand All @@ -47,7 +55,7 @@ class XmlSitemapUrlsImplementation extends AbstractFusionObject
protected ?Node $startingPoint = null;

/**
* @var array|null
* @var list<SitemapUrlItem>|null
*/
protected ?array $items = null;

Expand Down Expand Up @@ -84,8 +92,7 @@ public function getStartingPoint(): Node
/**
* Evaluate this Fusion object and return the result
*
* @return array
* @throws PropertyNotAccessibleException
* @return list<SitemapUrlItem>
*/
public function evaluate(): array
{
Expand All @@ -105,14 +112,19 @@ public function evaluate(): array
$startingPoint->aggregateId,
FindSubtreeFilter::create(nodeTypes: NodeTypeCriteria::create($nodeTypeNames, NodeTypeNames::createEmpty()))
);

if (!$subtree) {
throw new \RuntimeException(sprintf('The "startingPoint" Node with identifier "%s" doesnt exist anymore.', $startingPoint->aggregateId->value), 1718735861);
}
$this->collectItems($items, $subtree);
$this->items = $items;
}

return $this->items;
}

/**
* @return list<string>
*/
private function getAssetPropertiesForNodeType(NodeType $nodeType): array
{
if (!array_key_exists($nodeType->name->value, $this->assetPropertiesByNodeType)) {
Expand All @@ -136,7 +148,7 @@ private function getAssetPropertiesForNodeType(NodeType $nodeType): array
}

/**
* @throws PropertyNotAccessibleException
* @param list<SitemapUrlItem> $items
*/
protected function collectItems(array &$items, Subtree $subtree): void
{
Expand Down Expand Up @@ -171,7 +183,9 @@ protected function collectItems(array &$items, Subtree $subtree): void
$node->aggregateId,
FindSubtreeFilter::create(nodeTypes: NodeTypeCriteria::create($nodeTypeNames, NodeTypeNames::createEmpty()))
);

if (!$contentSubtree) {
throw new \RuntimeException(sprintf('The Node with identifier "%s" doesnt exist anymore.', $node->aggregateId->value), 1718735861);
}
$this->resolveImages($contentSubtree, $item, $nodeTypeManager);
}

Expand All @@ -184,10 +198,7 @@ protected function collectItems(array &$items, Subtree $subtree): void
}

/**
* @param Subtree $subtree
* @param array & $item
* @return void
* @throws PropertyNotAccessibleException
* @param SitemapUrlItem $item
*/
protected function resolveImages(Subtree $subtree, array &$item, NodeTypeManager $nodeTypeManager): void
{
Expand Down
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"neos/neos": "^9.0",
"neos/fusion-afx": "^9.0"
},
"scripts": {
"lint:phpstan": "../../../bin/phpstan analyse"
},
"autoload": {
"psr-4": {
"Neos\\Seo\\": "Classes"
Expand Down
4 changes: 4 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
parameters:
level: 8
paths:
- Classes

0 comments on commit 1f9ffc0

Please sign in to comment.