@@ -8,7 +8,7 @@ TYPO3 CMS class reflection extension for PHPStan & framework-specific rules
88
99To use this extension, require it in [ Composer] ( https://getcomposer.org/ ) :
1010
11- ```
11+ ``` Shell
1212composer require --dev saschaegerer/phpstan-typo3
1313```
1414
@@ -19,25 +19,26 @@ If you also install [phpstan/extension-installer](https://github.com/phpstan/ext
1919
2020If you don't want to use ` phpstan/extension-installer ` , put this into your phpstan.neon config:
2121
22- ```
22+ ``` NEON
2323includes:
2424 - vendor/saschaegerer/phpstan-typo3/extension.neon
2525```
26+
2627</details >
2728
2829### Custom Context API Aspects
2930
3031If you use custom aspects for the TYPO3 Context API you can add a mapping so PHPStan knows
3132what type of aspect class is returned by the context API
3233
33- ```
34+ ``` NEON
3435parameters:
3536 typo3:
3637 contextApiGetAspectMapping:
3738 myCustomAspect: FlowdGmbh\MyProject\Context\MyCustomAspect
3839```
3940
40- ```
41+ ``` PHP
4142// PHPStan will now know that $myCustomAspect is of type FlowdGmbh\MyProject\Context\MyCustomAspect
4243$myCustomAspect = GeneralUtility::makeInstance(Context::class)->getAspect('myCustomAspect');
4344```
@@ -47,15 +48,42 @@ $myCustomAspect = GeneralUtility::makeInstance(Context::class)->getAspect('myCus
4748If you use custom PSR-7 request attribute you can add a mapping so PHPStan knows
4849what type of class is returned by Request::getAttribute()
4950
50- ```
51+ ``` NEON
5152parameters:
5253 typo3:
5354 requestGetAttributeMapping:
5455 myAttribute: FlowdGmbh\MyProject\Http\MyAttribute
5556 myNullableAttribute: FlowdGmbh\MyProject\Http\MyAttribute|null
5657```
5758
58- ```
59+ ``` PHP
5960// PHPStan will now know that $myAttribute is of type FlowdGmbh\MyProject\Http\MyAttribute
6061$myAttribute = $request->getAttribute('myAttribute');
6162```
63+
64+ ### Custom Site Attribute
65+
66+ If you use custom attributes for the TYPO3 Site API you can add a mapping so PHPStan knows
67+ what type is returned by the site API
68+
69+ ``` NEON
70+ parameters:
71+ typo3:
72+ siteGetAttributeMapping:
73+ myArrayAttribute: array
74+ myIntAttribute: int
75+ myStringAttribute: string
76+ ```
77+
78+ ``` PHP
79+ $site = $this->request->getAttribute('site');
80+
81+ // PHPStan will now know that $myArrayAttribute is of type array<mixed , mixed >
82+ $myArrayAttribute = $site->getAttribute('myArrayAttribute');
83+
84+ // PHPStan will now know that $myIntAttribute is of type int
85+ $myIntAttribute = $site->getAttribute('myIntAttribute');
86+
87+ // PHPStan will now know that $myStringAttribute is of type string
88+ $myStringAttribute = $site->getAttribute('myStringAttribute');
89+ ```
0 commit comments