Skip to content

Commit

Permalink
Refactor for PHPStan 2 Compatibility
Browse files Browse the repository at this point in the history
Refactor the entire package to ensure compatibility with PHPStan 2.
To reduce effort, the package is now only compatible with TYPO3 v13,
and compatibility with TYPO3 v12 and v11 has been removed.
Older TYPO3 versions will continue to be supported with version 1 of
the package. If support for TYPO3 v12 in version 2 is required,
it can still be implemented if necessary.
  • Loading branch information
sascha-egerer committed Jan 16, 2025
1 parent 4dbe17a commit 6202776
Show file tree
Hide file tree
Showing 59 changed files with 221 additions and 1,668 deletions.
62 changes: 7 additions & 55 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,70 +12,22 @@ jobs:
fail-fast: false
matrix:
include:
- typo3-version: "^11.5"
php-version: "7.4"
composer-flags: ""
- typo3-version: "^11.5"
php-version: "7.4"
composer-flags: " --prefer-lowest"
- typo3-version: "^11.5"
php-version: "8.0"
composer-flags: ""
- typo3-version: "^11.5"
php-version: "8.0"
composer-flags: " --prefer-lowest"
- typo3-version: "^11.5"
php-version: "8.1"
composer-flags: ""
- typo3-version: "^11.5"
php-version: "8.1"
composer-flags: " --prefer-lowest"
- typo3-version: "^11.5"
php-version: "8.2"
composer-flags: ""
- typo3-version: "^11.5"
php-version: "8.2"
composer-flags: " --prefer-lowest"
- typo3-version: "^11.5"
php-version: "8.3"
composer-flags: ""
- typo3-version: "^11.5"
php-version: "8.3"
composer-flags: " --prefer-lowest"
- typo3-version: "^12.4"
php-version: "8.1"
composer-flags: ""
- typo3-version: "^12.4"
php-version: "8.1"
composer-flags: " --prefer-lowest"
- typo3-version: "^12.4"
php-version: "8.2"
composer-flags: ""
- typo3-version: "^12.4"
php-version: "8.2"
composer-flags: " --prefer-lowest"
- typo3-version: "^12.4"
- typo3-version: "^13.4"
php-version: "8.3"
composer-flags: ""
- typo3-version: "^12.4"
- typo3-version: "^13.4"
php-version: "8.3"
composer-flags: " --prefer-lowest"
- typo3-version: "^13.1"
php-version: "8.2"
- typo3-version: "^13.4"
php-version: "8.4"
composer-flags: ""
- typo3-version: "^13.1"
php-version: "8.2"
composer-flags: " --prefer-lowest"
- typo3-version: "^13.1"
php-version: "8.3"
composer-flags: ""
- typo3-version: "^13.1"
php-version: "8.3"
- typo3-version: "^13.4"
php-version: "8.4"
composer-flags: " --prefer-lowest"

steps:
- name: "Checkout"
uses: "actions/checkout@v3"
uses: "actions/checkout@v4"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
Expand Down
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ This extension provides the following features (!!! not an exhaustive list !!!):

**Dynamic Return Type Extensions**
* Provides correct return type for `\TYPO3\CMS\Core\Context\Context->getAspect()`.
* Provides correct return type for `\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance()`.
* Provides correct return type for `\TYPO3\CMS\Extbase\Object\ObjectManagerInterface->get()`.
* Provides correct return type for `\TYPO3\CMS\Extbase\Object\ObjectManager->get()`.
* Provides correct return type for `\TYPO3\CMS\Extbase\Property\PropertyMapper->convert()`.
* Provides correct return type for `\TYPO3\CMS\Core\Utility\MathUtility` methods like isIntegerInRange.
* Provides correct return type for `\TYPO3\CMS\Extbase\Persistence\Generic\Query->execute()`.
Expand Down
25 changes: 12 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,25 @@
"type": "phpstan-extension",
"minimum-stability": "dev",
"prefer-stable": true,
"prefer-source": true,
"require": {
"php": "^7.4 || ^8.0",
"phpstan/phpstan": "^1.10.9 || ^1.11.0",
"typo3/cms-core": "^11.5 || ^12.4 || ^13.0",
"typo3/cms-extbase": "^11.5 || ^12.4 || ^13.0",
"php": "^8.3",
"ext-simplexml": "*",
"phpstan/phpstan": "^2.1",
"typo3/cms-core": "^13.4.3",
"typo3/cms-extbase": "^13.4.3",
"bnf/phpstan-psr-container": "^1.0",
"composer/semver": "^3.3",
"ssch/typo3-debug-dump-pass": "^0.0.2",
"ext-simplexml": "*"
"composer/semver": "^3.4",
"ssch/typo3-debug-dump-pass": "^0.0.2"
},
"require-dev": {
"nikic/php-parser": "^v4.19.1",
"consistence-community/coding-standard": "^3.10",
"consistence-community/coding-standard": "^3.11",
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
"php-parallel-lint/php-parallel-lint": "^1.4",
"phing/phing": "^2.17",
"phpstan/phpstan-strict-rules": "^1.5",
"phpunit/phpunit": "^9.6",
"symfony/polyfill-php80": "^1.29",
"phpstan/phpstan-phpunit": "^1.3"
"phpstan/phpstan-strict-rules": "^2.0",
"phpstan/phpstan-phpunit": "^2.0.3",
"phpunit/phpunit": "^11.5"
},
"autoload": {
"psr-4": {
Expand Down
48 changes: 6 additions & 42 deletions extension.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,7 @@ includes:

services:
-
class: SaschaEgerer\PhpstanTypo3\Reflection\RepositoryFindMethodsClassReflectionExtension
tags:
- phpstan.broker.methodsClassReflectionExtension
-
class: SaschaEgerer\PhpstanTypo3\Reflection\RepositoryCountByMethodsClassReflectionExtension
tags:
- phpstan.broker.methodsClassReflectionExtension
-
class: SaschaEgerer\PhpstanTypo3\Type\ObjectManagerDynamicReturnTypeExtension
tags:
- phpstan.broker.dynamicMethodReturnTypeExtension
-
class: SaschaEgerer\PhpstanTypo3\Type\QueryInterfaceDynamicReturnTypeExtension
tags:
- phpstan.broker.dynamicMethodReturnTypeExtension
-
class: SaschaEgerer\PhpstanTypo3\Type\QueryResultToArrayDynamicReturnTypeExtension
tags:
- phpstan.broker.dynamicMethodReturnTypeExtension
-
class: SaschaEgerer\PhpstanTypo3\Type\RepositoryDynamicReturnTypeExtension
tags:
- phpstan.broker.dynamicMethodReturnTypeExtension
class: PhpParser\NodeVisitor\NodeConnectingVisitor
-
class: SaschaEgerer\PhpstanTypo3\Type\ValidatorResolverDynamicReturnTypeExtension
tags:
Expand Down Expand Up @@ -54,14 +32,6 @@ services:
siteGetAttributeMapping: %typo3.siteGetAttributeMapping%
tags:
- phpstan.rules.rule
-
class: SaschaEgerer\PhpstanTypo3\Type\RepositoryQueryDynamicReturnTypeExtension
tags:
- phpstan.broker.dynamicMethodReturnTypeExtension
-
class: SaschaEgerer\PhpstanTypo3\Type\RepositoryFindAllDynamicReturnTypeExtension
tags:
- phpstan.broker.dynamicMethodReturnTypeExtension
-
class: SaschaEgerer\PhpstanTypo3\Type\RequestDynamicReturnTypeExtension
arguments:
Expand Down Expand Up @@ -92,10 +62,6 @@ services:
class: SaschaEgerer\PhpstanTypo3\Type\GeneralUtilityGetIndpEnvDynamicReturnTypeExtension
tags:
- phpstan.broker.dynamicStaticMethodReturnTypeExtension
-
class: SaschaEgerer\PhpstanTypo3\Stubs\StubFilesExtensionLoader
tags:
- phpstan.stubFilesExtension
-
class: SaschaEgerer\PhpstanTypo3\Type\UserAspectGetDynamicReturnTypeExtension
tags:
Expand All @@ -105,7 +71,7 @@ services:
tags:
- phpstan.broker.dynamicMethodReturnTypeExtension
-
class: SaschaEgerer\PhpstanTypo3\Service\PrivateServiceAnalyzer
class: SaschaEgerer\PhpstanTypo3\Service\PrivateServiceAnalyzer
-
class: SaschaEgerer\PhpstanTypo3\Service\PrototypeServiceDefinitionChecker
# service map
Expand Down Expand Up @@ -153,16 +119,11 @@ parameters:
websiteTitle: string
stubFiles:
- stubs/DomainObjectInterface.stub
- stubs/EventDispatcher.stub
- stubs/ObjectStorage.stub
- stubs/QueryFactory.stub
- stubs/QueryInterface.stub
- stubs/QueryResultInterface.stub
- stubs/Repository.stub
# See SaschaEgerer\PhpstanTypo3\Stubs\StubFilesExtensionLoader
# GeneralUtility.stub is only used if TYPO3 version is < 12
#- stubs/GeneralUtility.stub
#- stubs/QueryResult.stub
- stubs/RepositoryInterface.stub
dynamicConstantNames:
- TYPO3_MODE
- TYPO3_REQUESTTYPE
Expand Down Expand Up @@ -211,3 +172,6 @@ parametersSchema:
requestGetAttributeMapping: arrayOf(string())
siteGetAttributeMapping: arrayOf(string())
])
conditionalTags:
PhpParser\NodeVisitor\NodeConnectingVisitor:
phpstan.parser.richParserNodeVisitor: true
12 changes: 1 addition & 11 deletions phpstan.bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,4 @@

define('FILE_DENY_PATTERN_DEFAULT', '\\.(php[3-8]?|phpsh|phtml|pht|phar|shtml|cgi)(\\..*)?$|\\.pl$|^\\.htaccess$');

define('TYPO3_REQUESTTYPE', 0);
define('TYPO3_REQUESTTYPE_FE', 1);
define('TYPO3_REQUESTTYPE_BE', 2);
define('TYPO3_REQUESTTYPE_CLI', 4);
define('TYPO3_REQUESTTYPE_AJAX', 8);
define('TYPO3_REQUESTTYPE_INSTALL', 16);

define('TYPO3_MODE', '');
define('TYPO3_mainDir', 'typo3/');
define('TYPO3_version', '');
define('TYPO3_branch', '');
defined('TYPO3') ?: define('TYPO3', true);
12 changes: 10 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,21 @@ parameters:
message: "#^Method SaschaEgerer\\\\PhpstanTypo3\\\\Tests\\\\Unit\\\\Type\\\\QueryResultToArrayDynamicReturnTypeExtension\\\\FrontendUserGroupCustomFindAllWithoutModelTypeRepository\\:\\:findAll\\(\\) return type with generic interface TYPO3\\\\CMS\\\\Extbase\\\\Persistence\\\\QueryResultInterface does not specify its types\\: ModelType$#"
count: 1
path: tests/Unit/Type/QueryResultToArrayDynamicReturnTypeExtension/data/query-result-to-array.php

-
message: "#^PHPDoc tag @var for variable \\$queryResult contains generic class TYPO3\\\\CMS\\\\Extbase\\\\Persistence\\\\Generic\\\\QueryResult but does not specify its types\\: ModelType$#"
count: 2
path: tests/Unit/Type/QueryResultToArrayDynamicReturnTypeExtension/data/query-result-to-array.php

-
message: "#^Return type \\(TYPO3\\\\CMS\\\\Extbase\\\\Persistence\\\\QueryResultInterface\\) of method SaschaEgerer\\\\PhpstanTypo3\\\\Tests\\\\Unit\\\\Type\\\\QueryResultToArrayDynamicReturnTypeExtension\\\\FrontendUserGroupCustomFindAllWithoutModelTypeRepository\\:\\:findAll\\(\\) should be covariant with return type \\(array\\<int, SaschaEgerer\\\\PhpstanTypo3\\\\Tests\\\\Unit\\\\Type\\\\QueryResultToArrayDynamicReturnTypeExtension\\\\FrontendUserGroup\\>\\|TYPO3\\\\CMS\\\\Extbase\\\\Persistence\\\\QueryResultInterface\\<SaschaEgerer\\\\PhpstanTypo3\\\\Tests\\\\Unit\\\\Type\\\\QueryResultToArrayDynamicReturnTypeExtension\\\\FrontendUserGroup\\>\\) of method TYPO3\\\\CMS\\\\Extbase\\\\Persistence\\\\Repository\\<SaschaEgerer\\\\PhpstanTypo3\\\\Tests\\\\Unit\\\\Type\\\\QueryResultToArrayDynamicReturnTypeExtension\\\\FrontendUserGroup\\>\\:\\:findAll\\(\\)$#"
count: 1
path: tests/Unit/Type/QueryResultToArrayDynamicReturnTypeExtension/data/query-result-to-array.php
-
message: '#^Although PHPStan\\Reflection\\Php\\PhpPropertyReflection is covered by backward compatibility promise, this instanceof assumption might break because it''s not guaranteed to always stay the same\.$#'
identifier: phpstanApi.instanceofAssumption
count: 1
path: src/Rule/ValidatorResolverOptionsRule.php
-
message: '#^Node attribute ''parent'' is no longer available\.$#'
identifier: phpParser.nodeConnectingAttribute
count: 2
path: src/Type/MathUtilityTypeSpecifyingExtension.php
33 changes: 0 additions & 33 deletions src/Helpers/Typo3ClassNamingUtilityTrait.php

This file was deleted.

Loading

0 comments on commit 6202776

Please sign in to comment.