├── .gitignore ├── LICENSE.md ├── README.md ├── composer.json ├── phpstan.neon └── stubs ├── BaseYii.stub ├── console └── Application.stub └── web └── Application.stub /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | composer.lock 3 | /.idea 4 | /.DS_Store 5 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Pixel & Tonic, Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PHPStan config for Craft CMS 2 | 3 | This package provides a base [PHPStan](https://github.com/phpstan/phpstan) configuration for Craft CMS plugins and projects. 4 | 5 | To install, run the following commands within your plugin or project: 6 | 7 | ```sh 8 | composer config minimum-stability dev 9 | ``` 10 | 11 | ```sh 12 | composer config prefer-stable true 13 | ``` 14 | 15 | ```sh 16 | composer require craftcms/phpstan:dev-main --dev 17 | ``` 18 | 19 | Then add a `phpstan.neon` config file to the root of your project: 20 | 21 | ```neon 22 | includes: 23 | - vendor/craftcms/phpstan/phpstan.neon 24 | 25 | parameters: 26 | level: 0 27 | paths: 28 | - src 29 | ``` 30 | 31 | Change the `paths` array to whichever directory(s) contain the source code you want PHPStan to inspect. 32 | 33 | (See PHPStan’s [Config Reference](https://phpstan.org/config-reference) for a full list of supported config parameters.) 34 | 35 | With that in place, you can begin running PHPStan with the following command: 36 | 37 | ```sh 38 | vendor/bin/phpstan --memory-limit=1G 39 | ``` 40 | 41 | Or define a `phpstan` script in `composer.json`: 42 | 43 | ```json 44 | { 45 | "...": "...", 46 | "scripts": { 47 | "phpstan": "phpstan --memory-limit=1G" 48 | } 49 | } 50 | ``` 51 | 52 | And then run PHPStan with: 53 | 54 | ```sh 55 | composer run-script phpstan 56 | ``` 57 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "craftcms/phpstan", 3 | "description": "PHPStan configuration for Craft CMS projects", 4 | "require": { 5 | "phpstan/phpstan": "^1.4.6" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /phpstan.neon: -------------------------------------------------------------------------------- 1 | parameters: 2 | excludePaths: 3 | - ../cms/src/test/internal/* 4 | - ../cms/src/config/composer-classes.php 5 | - ../cms/src/config/mimeTypes.php 6 | - ../cms/src/views/debug/* 7 | scanFiles: 8 | - ../cms/src/Craft.php 9 | - ../../yiisoft/yii2/Yii.php 10 | - ../../twig/twig/src/Extension/CoreExtension.php 11 | stubFiles: 12 | - stubs/BaseYii.stub 13 | - stubs/console/Application.stub 14 | - stubs/web/Application.stub 15 | earlyTerminatingMethodCalls: 16 | Craft: 17 | - dd 18 | yii\base\Application: 19 | - end 20 | yii\base\ErrorHandler: 21 | - convertExceptionToError 22 | -------------------------------------------------------------------------------- /stubs/BaseYii.stub: -------------------------------------------------------------------------------- 1 | |array{class: class-string}|callable(): T $type 15 | * @param array $params 16 | * @return T 17 | */ 18 | public static function createObject($type, array $params = []); 19 | } 20 | -------------------------------------------------------------------------------- /stubs/console/Application.stub: -------------------------------------------------------------------------------- 1 |