Skip to content

Commit 592fe0f

Browse files
committed
Load TYPO3 version specific stubs
The TYPO3 core is going to fix and extend some of its types and annocations. We have to react at some places and must not load some stubs anymore in newer TYPO3 versions. Issue: #114
1 parent 822afd2 commit 592fe0f

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace SaschaEgerer\PhpstanTypo3\Stubs;
4+
5+
use Composer\InstalledVersions;
6+
use Composer\Semver\VersionParser;
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+
if (InstalledVersions::satisfies(new VersionParser(), 'typo3/cms-core', '< 12')) {
16+
$files[] = $stubsDir . '/GeneralUtility.stub';
17+
}
18+
if (InstalledVersions::satisfies(new VersionParser(), 'typo3/cms-core', '<= 12.2.0')) {
19+
$files[] = $stubsDir . '/QueryResult.stub';
20+
}
21+
22+
return $files;
23+
}
24+
25+
}

0 commit comments

Comments
 (0)