PHPackages                             saschaegerer/phpstan-typo3 - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. saschaegerer/phpstan-typo3

ActivePhpstan-extension[Testing &amp; Quality](/categories/testing)

saschaegerer/phpstan-typo3
==========================

TYPO3 CMS class reflection extension for PHPStan

3.0.1(3mo ago)503.6M↑21%24[8 issues](https://github.com/sascha-egerer/phpstan-typo3/issues)20MITPHPPHP ^8.2CI passing

Since Nov 29Pushed 3mo ago6 watchersCompare

[ Source](https://github.com/sascha-egerer/phpstan-typo3)[ Packagist](https://packagist.org/packages/saschaegerer/phpstan-typo3)[ GitHub Sponsors](https://github.com/sascha-egerer)[ Fund](https://liberapay.com/sascha.egerer)[ RSS](/packages/saschaegerer-phpstan-typo3/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (13)Versions (37)Used By (20)

PHPStan TYPO3 extensions and rules
==================================

[](#phpstan-typo3-extensions-and-rules)

TYPO3 CMS class reflection extension for PHPStan &amp; framework-specific rules.

---

[![Build](https://github.com/sascha-egerer/phpstan-typo3/workflows/Tests/badge.svg)](https://github.com/sascha-egerer/phpstan-typo3/actions)

- [PHPStan](https://phpstan.org/)

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\Context\DateTimeAspect->get()`.
- Provides correct return type for `\TYPO3\CMS\Core\Context\UserAspect->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\Core\Utility\GeneralUtility::getIndpEnv()`.
- Provides correct return type for `\TYPO3\CMS\Extbase\Persistence\QueryInterface->execute()`.
- Provides correct return type for `\TYPO3\CMS\Extbase\Persistence\ObjectStorage` methods.
- Provides correct return type for `\TYPO3\CMS\Core\Site\Entity\Site->getAttribute()`.
- Provides correct return type for `\Psr\Http\Message\ServerRequestInterface->getAttribute()`.
- Provides correct return type for `\TYPO3\CMS\Extbase\Validation\ValidatorResolver->createValidator()`.
- Uses under the hood [bnf/phpstan-psr-container](https://github.com/bnf/phpstan-psr-container)

All these dynamic return type extensions are necessary to teach PHPStan what type will be returned by the specific method call.

Show me a practical use case.For example PHPStan cannot know innately what type will be returned if you call `\\TYPO3\\CMS\\Core\\Utility\\MathUtility-&gt;forceIntegerInRange(1000, 1, 10)`. It will be an int&lt;10&gt;. With the help of this library PHPStan also knows what´s going up. Imagine the following situation in your code:

```
use TYPO3\CMS\Core\Utility\MathUtility;

$integer = MathUtility::forceIntegerInRange(100, 1, 10);

if($integer > 10) {
    throw new \UnexpectedValueException('The integer is too big')
}
```

PHPStan will tell you that the if condition is superfluous, because the variable $integer will never be higher than 10. Right?

**Framework specific rules**

- Validates `\TYPO3\CMS\Core\Context\Context->getAspect()` aspect names.
- Validates `\Psr\Http\Message\ServerRequestInterface->getAttribute()` attribute names.
- Validates `\TYPO3\CMS\Core\Site\Entity\Site->getAttribute()` attribute names.
- Validates `\TYPO3\CMS\Extbase\Validation\ValidatorResolver->createValidator()` required options.
- Detects private service access via `\Psr\Container\ContainerInterface->get()`.
- Detects private service access via `\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance()`.

Show me a practical use case.For example PHPStan cannot know innately that calling `ValidatorResolver->createValidator(RegularExpressionValidator::class)` is invalid, because we miss to pass the required option `regularExpression`. With the help of this library PHPStan now complaints that we have missed to pass the required option. So go ahead and find bugs in your code without running it.

Installation &amp; Configuration
--------------------------------

[](#installation--configuration)

To use this extension, require it in [Composer](https://getcomposer.org/):

```
composer require --dev saschaegerer/phpstan-typo3
```

If you also install [phpstan/extension-installer](https://github.com/phpstan/extension-installer) then you're all set!

 Manual installationIf you don't want to use `phpstan/extension-installer`, put this into your phpstan.neon config:

```
includes:
    - vendor/saschaegerer/phpstan-typo3/extension.neon
```

### Custom Context API Aspects

[](#custom-context-api-aspects)

If you use custom aspects for the TYPO3 Context API you can add a mapping so PHPStan knows what type of aspect class is returned by the context API

```
parameters:
    typo3:
        contextApiGetAspectMapping:
            myCustomAspect: FlowdGmbh\MyProject\Context\MyCustomAspect
```

```
// PHPStan will now know that $myCustomAspect is of type FlowdGmbh\MyProject\Context\MyCustomAspect
$myCustomAspect = GeneralUtility::makeInstance(Context::class)->getAspect('myCustomAspect');
```

### Custom Request Attribute

[](#custom-request-attribute)

If you use custom PSR-7 request attribute you can add a mapping so PHPStan knows what type of class is returned by Request::getAttribute()

```
parameters:
    typo3:
        requestGetAttributeMapping:
            myAttribute: FlowdGmbh\MyProject\Http\MyAttribute
            myNullableAttribute: FlowdGmbh\MyProject\Http\MyAttribute|null
```

```
// PHPStan will now know that $myAttribute is of type FlowdGmbh\MyProject\Http\MyAttribute
$myAttribute = $request->getAttribute('myAttribute');
```

### Custom Site Attribute

[](#custom-site-attribute)

If you use custom attributes for the TYPO3 Site API you can add a mapping so PHPStan knows what type is returned by the site API

```
parameters:
    typo3:
        siteGetAttributeMapping:
            myArrayAttribute: array
            myIntAttribute: int
            myStringAttribute: string
```

```
$site = $this->request->getAttribute('site');

// PHPStan will now know that $myArrayAttribute is of type array
$myArrayAttribute = $site->getAttribute('myArrayAttribute');

// PHPStan will now know that $myIntAttribute is of type int
$myIntAttribute = $site->getAttribute('myIntAttribute');

// PHPStan will now know that $myStringAttribute is of type string
$myStringAttribute = $site->getAttribute('myStringAttribute');
```

### Check for private Services

[](#check-for-private-services)

You have to provide a path to App\_KernelDevelopmentDebugContainer.xml or similar XML file describing your container. This is generated by [ssch/typo3-debug-dump-pass](https://github.com/sabbelasichon/typo3-debug-dump-pass) in your /var/cache/{TYPO3\_CONTEXT}/ folder.

```
parameters:
    typo3:
        containerXmlPath: var/cache/development/App_KernelDevelopmentDebugContainer.xml
```

Development
-----------

[](#development)

### Running Tests and Quality Checks

[](#running-tests-and-quality-checks)

The following composer scripts are available for development:

CommandDescription`composer test`Run all quality checks (lint, cs, phpstan, phpunit)`composer test:php-lint`Run PHP syntax linting using parallel-lint`composer test:php-cs`Run code style checks using PHP\_CodeSniffer`composer test:phpstan`Run static analysis using PHPStan`composer test:phpunit`Run PHPUnit tests`composer fix:php-cs`Fix code style issues using PHP Code Beautifier

###  Health Score

69

—

FairBetter than 100% of packages

Maintenance78

Regular maintenance activity

Popularity57

Moderate usage in the ecosystem

Community45

Growing community involvement

Maturity85

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 60.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~82 days

Total

33

Last Release

94d ago

Major Versions

0.13.3 → 1.0.02021-10-26

v1.x-dev → 2.0.02025-01-27

2.1.1 → 3.0.02025-12-23

v2.x-dev → 3.0.12026-02-13

PHP version history (6 changes)0.10.0PHP ~7.0

0.10.1PHP ~7.1

0.12.3PHP ^7.2 || ^8.0

1.0.0PHP ^7.1 || ^8.0

1.8.5PHP ^7.4 || ^8.0

2.0.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/8cab5b9422e572cf6a157fd040d217f3a8137bff045a8eae6fe42af51f13104d?d=identicon)[sascha.egerer](/maintainers/sascha.egerer)

---

Top Contributors

[![sascha-egerer](https://avatars.githubusercontent.com/u/1651414?v=4)](https://github.com/sascha-egerer "sascha-egerer (215 commits)")[![sabbelasichon](https://avatars.githubusercontent.com/u/13050560?v=4)](https://github.com/sabbelasichon "sabbelasichon (51 commits)")[![oliverklee](https://avatars.githubusercontent.com/u/765746?v=4)](https://github.com/oliverklee "oliverklee (42 commits)")[![tlueder](https://avatars.githubusercontent.com/u/5957131?v=4)](https://github.com/tlueder "tlueder (16 commits)")[![KamiYang](https://avatars.githubusercontent.com/u/16732079?v=4)](https://github.com/KamiYang "KamiYang (9 commits)")[![derhansen](https://avatars.githubusercontent.com/u/2629896?v=4)](https://github.com/derhansen "derhansen (7 commits)")[![alexanderschnitzler](https://avatars.githubusercontent.com/u/711459?v=4)](https://github.com/alexanderschnitzler "alexanderschnitzler (3 commits)")[![tmotyl](https://avatars.githubusercontent.com/u/515397?v=4)](https://github.com/tmotyl "tmotyl (2 commits)")[![andreaswolf](https://avatars.githubusercontent.com/u/159919?v=4)](https://github.com/andreaswolf "andreaswolf (2 commits)")[![chrissonntag](https://avatars.githubusercontent.com/u/39337016?v=4)](https://github.com/chrissonntag "chrissonntag (2 commits)")[![MK-42](https://avatars.githubusercontent.com/u/5477999?v=4)](https://github.com/MK-42 "MK-42 (1 commits)")[![Kanti](https://avatars.githubusercontent.com/u/471387?v=4)](https://github.com/Kanti "Kanti (1 commits)")[![eliashaeussler](https://avatars.githubusercontent.com/u/16313625?v=4)](https://github.com/eliashaeussler "eliashaeussler (1 commits)")[![tillhoerner](https://avatars.githubusercontent.com/u/31031406?v=4)](https://github.com/tillhoerner "tillhoerner (1 commits)")[![d-s-codappix](https://avatars.githubusercontent.com/u/179449418?v=4)](https://github.com/d-s-codappix "d-s-codappix (1 commits)")[![Baachi](https://avatars.githubusercontent.com/u/833645?v=4)](https://github.com/Baachi "Baachi (1 commits)")

---

Tags

static analysis

###  Code Quality

TestsPHPUnit

Static AnalysisRector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/saschaegerer-phpstan-typo3/health.svg)

```
[![Health](https://phpackages.com/badges/saschaegerer-phpstan-typo3/health.svg)](https://phpackages.com/packages/saschaegerer-phpstan-typo3)
```

###  Alternatives

[vimeo/psalm

A static analysis tool for finding errors in PHP applications

5.8k77.5M6.7k](/packages/vimeo-psalm)[phan/phan

A static analyzer for PHP

5.6k11.2M1.1k](/packages/phan-phan)[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k43.5M5.2k](/packages/larastan-larastan)[phpstan/phpstan-symfony

Symfony Framework extensions and rules for PHPStan

78768.9M1.5k](/packages/phpstan-phpstan-symfony)[phpstan/phpstan-doctrine

Doctrine extensions for PHPStan

66766.6M1.1k](/packages/phpstan-phpstan-doctrine)[phpstan/phpstan-strict-rules

Extra strict and opinionated rules for PHPStan

69661.6M3.9k](/packages/phpstan-phpstan-strict-rules)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
