From 1f9ffc0e954c6f73c25accbe6a689deff0181621 Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Tue, 18 Jun 2024 20:39:21 +0200 Subject: [PATCH 1/2] FEATURE: Introduce phpstan with level 8 --- .../Fusion/XmlSitemapUrlsImplementation.php | 35 ++++++++++++------- composer.json | 3 ++ phpstan.neon.dist | 4 +++ 3 files changed, 30 insertions(+), 12 deletions(-) create mode 100644 phpstan.neon.dist diff --git a/Classes/Fusion/XmlSitemapUrlsImplementation.php b/Classes/Fusion/XmlSitemapUrlsImplementation.php index a1588da..f558cc6 100644 --- a/Classes/Fusion/XmlSitemapUrlsImplementation.php +++ b/Classes/Fusion/XmlSitemapUrlsImplementation.php @@ -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, + * changeFrequency?: true + * } + */ class XmlSitemapUrlsImplementation extends AbstractFusionObject { #[Flow\Inject] @@ -36,7 +44,7 @@ class XmlSitemapUrlsImplementation extends AbstractFusionObject protected PersistenceManager $persistenceManager; /** - * @var array> + * @var array> */ protected array $assetPropertiesByNodeType = []; @@ -47,7 +55,7 @@ class XmlSitemapUrlsImplementation extends AbstractFusionObject protected ?Node $startingPoint = null; /** - * @var array|null + * @var list|null */ protected ?array $items = null; @@ -84,8 +92,7 @@ public function getStartingPoint(): Node /** * Evaluate this Fusion object and return the result * - * @return array - * @throws PropertyNotAccessibleException + * @return list */ public function evaluate(): array { @@ -105,7 +112,9 @@ 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; } @@ -113,6 +122,9 @@ public function evaluate(): array return $this->items; } + /** + * @return list + */ private function getAssetPropertiesForNodeType(NodeType $nodeType): array { if (!array_key_exists($nodeType->name->value, $this->assetPropertiesByNodeType)) { @@ -136,7 +148,7 @@ private function getAssetPropertiesForNodeType(NodeType $nodeType): array } /** - * @throws PropertyNotAccessibleException + * @param list $items */ protected function collectItems(array &$items, Subtree $subtree): void { @@ -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); } @@ -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 { diff --git a/composer.json b/composer.json index ca8513c..c1f084e 100644 --- a/composer.json +++ b/composer.json @@ -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" diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 0000000..d0cf7bd --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,4 @@ +parameters: + level: 8 + paths: + - Classes From 8f437d21a52b181797c516a2dcdfdb941a224e25 Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Mon, 24 Jun 2024 21:35:20 +0200 Subject: [PATCH 2/2] FEATURE: Introduce PHPStan level 8 for CI --- .github/workflows/tests.yml | 64 +++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..2e286ac --- /dev/null +++ b/.github/workflows/tests.yml @@ -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