Skip to content
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

FEATURE: Introduce phpstan with level 8 #188

Merged
merged 2 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Tests

on:
push:
branches: [ main, '[0-9]+.x' ]
pull_request:
branches: [ main, '[0-9]+.x' ]
workflow_dispatch: # Allow manual triggering on any branch via `gh workflow run tests.yml -r branch-name`

jobs:
build:
env:
FLOW_PATH_ROOT: ../neos-base-distribution

runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
include:
- php-version: "8.2"
neos-version: "9.0"
- php-version: "8.3"
neos-version: "9.0"

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, xml, json, zlib, iconv, intl, pdo_sqlite, mysql

- id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
shell: bash

- uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: Prepare Neos distribution
run: |
git clone --depth 1 --branch ${{ matrix.neos-version }} https://github.com/neos/neos-development-distribution.git ${FLOW_PATH_ROOT}
cd ${FLOW_PATH_ROOT}
composer config --no-plugins allow-plugins.neos/composer-plugin true
composer config repositories.package '{ "type": "path", "url": "../neos-seo", "options": { "symlink": false } }'
composer require --no-update --no-interaction neos/seo:@dev
composer require --dev --no-update --no-interaction phpstan/phpstan:^1.10

- name: Install dependencies
run: |
cd ${FLOW_PATH_ROOT}
rm -rf composer.lock
composer install --no-interaction --no-progress --prefer-dist

- name: Linting
run: |
cd ${FLOW_PATH_ROOT}/Packages/Application/Neos.Seo
composer run lint:phpstan
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
Loading