Skip to content

Commit

Permalink
PHPStan: Add docs and infrastructure for local configuration (#4494)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjansenDatabay authored Jun 14, 2022
1 parent 4f660e5 commit ed4a317
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ captainhook.config.json
captainhook.local.json
.phpunit.result.cache
.php-cs-fixer.cache
phpstan.local.neon
phpstan-baseline.neon

# File Delivery
override.php
39 changes: 39 additions & 0 deletions docs/development/static_code_analysis.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,45 @@ You can overwrite the rule level by passing a `--level` argument:
./CI/PHPStan/run_check.sh Services/Mail --level 3
```

### Custom Configuration File

A custom configuration file could be provided by adding a file named `phpstan.local.neon` to the ILIAS root directory.
The filename is ignored by the `.gitignore` file and ILIAS `\RootFolderTest`, which ensures no new files are added
to the root level of ILIAS.

Example:

```yaml
includes:
- CI/PHPStan/phpstan.neon
parameters:
level: 9
```
In this example the shared `PHPStan` configuration is extended by the local configuration, where we defined `stricter`
rule level.

### Baseline

A [baseline file](https://phpstan.org/user-guide/baseline) can be generated by using the `--generate-baseline` option.

```bash
/CI/PHPStan/run_check.sh -c phpstan.local.neon Services/Mail --generate-baseline
```

The generated baseline file `phpstan-baseline.neon` will be stored in the ILIAS root folder and must be included in the
local `phpstan.local.neon` configuration.

```yaml
includes:
- CI/PHPStan/phpstan.neon
- phpstan-baseline.neon
parameters:
level: 9
```

If you analyse different components/folders with `PHPStan`, you will need to generate a new baseline file.

### IDE Integration

#### PHPStorm
Expand Down
2 changes: 2 additions & 0 deletions tests/App/RootFolderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ final class RootFolderTest extends TestCase
'.htaccess',
'.phpunit.result.cache',
'captainhook.local.json',
'phpstan.local.neon',
'phpstan-baseline.neon',
'.php_cs.cache',
'calendar.php',
'captainhook.json',
Expand Down

0 comments on commit ed4a317

Please sign in to comment.