Skip to content

Commit 9861cdc

Browse files
Merge pull request #116 from sascha-egerer/feauture/114
Load TYPO3 version specific stubs
2 parents a70de9c + be9976b commit 9861cdc

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"nikic/php-parser": "^4.15.1",
1414
"typo3/cms-core": "^10.4 || ^11.5 || ^12.2",
1515
"typo3/cms-extbase": "^10.4 || ^11.5 || ^12.2",
16-
"bnf/phpstan-psr-container": "^1.0"
16+
"bnf/phpstan-psr-container": "^1.0",
17+
"composer/semver": "^3.3"
1718
},
1819
"require-dev": {
1920
"consistence-community/coding-standard": "^3.10.1",

extension.neon

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ services:
8989
class: SaschaEgerer\PhpstanTypo3\Type\MathUtilityTypeSpecifyingExtension
9090
tags:
9191
- phpstan.typeSpecifier.staticMethodTypeSpecifyingExtension
92+
-
93+
class: SaschaEgerer\PhpstanTypo3\Stubs\StubFilesExtensionLoader
94+
tags:
95+
- phpstan.stubFilesExtension
9296
parameters:
9397
bootstrapFiles:
9498
- phpstan.bootstrap.php
@@ -121,13 +125,15 @@ parameters:
121125
websiteTitle: string
122126
stubFiles:
123127
- stubs/DomainObjectInterface.stub
124-
- stubs/GeneralUtility.stub
125128
- stubs/ObjectStorage.stub
126129
- stubs/QueryFactory.stub
127130
- stubs/QueryInterface.stub
128131
- stubs/QueryResultInterface.stub
129-
- stubs/QueryResult.stub
130132
- stubs/Repository.stub
133+
# See SaschaEgerer\PhpstanTypo3\Stubs\StubFilesExtensionLoader
134+
# GeneralUtility.stub is only used if TYPO3 version is < 12
135+
#- stubs/GeneralUtility.stub
136+
#- stubs/QueryResult.stub
131137
dynamicConstantNames:
132138
- TYPO3_MODE
133139
- TYPO3_REQUESTTYPE
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace SaschaEgerer\PhpstanTypo3\Stubs;
4+
5+
use Composer\Semver\VersionParser;
6+
use TYPO3\CMS\Core\Information\Typo3Version;
7+
8+
class StubFilesExtensionLoader implements \PHPStan\PhpDoc\StubFilesExtension
9+
{
10+
11+
public function getFiles(): array
12+
{
13+
$stubsDir = dirname(__DIR__, 2) . '/stubs';
14+
$files = [];
15+
$typo3Version = new Typo3Version();
16+
$versionParser = new VersionParser();
17+
18+
if ($versionParser->parseConstraints($typo3Version->getVersion())->matches($versionParser->parseConstraints('< 12'))) {
19+
$files[] = $stubsDir . '/GeneralUtility.stub';
20+
}
21+
if ($versionParser->parseConstraints($typo3Version->getVersion())->matches($versionParser->parseConstraints('<= 12.2.0'))) {
22+
$files[] = $stubsDir . '/QueryResult.stub';
23+
}
24+
25+
return $files;
26+
}
27+
28+
}

0 commit comments

Comments
 (0)