Skip to content
This repository was archived by the owner on Sep 1, 2024. It is now read-only.

Commit 910f6fb

Browse files
committed
Explain process
1 parent 35ae45d commit 910f6fb

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,31 @@
1-
# phpstan-require-file-exists
1+
# phpstan-require-file-exists
2+
Weirdly enough, PHPStan does not check if a file exists when used in a
3+
`require` or `include` statement. This is a PHPStan rule that tries to do
4+
exactly that.
5+
6+
## Installation
7+
```bash
8+
composer require --dev bellangelo/phpstan-require-file-exists
9+
```
10+
11+
## Configuration
12+
Add the following to your `phpstan.neon`:
13+
```neon
14+
services:
15+
-
16+
class: Bellangelo\PHPStanRequireFileExists\RequireFileExistsRule
17+
arguments:
18+
- @reflectionProvider
19+
tags: [phpstan.rules.rule]
20+
```
21+
22+
You can find a `phpstan.neon` example in the `tests` directory, here: [tests/phpstan.neon](tests/phpstan-testing.neon).
23+
24+
## Supported cases
25+
- `require 'file.php';` - might not find it since the path is relative.
26+
- `require __DIR__ . '/file.php';` - can find it, if it exists.
27+
- `require __DIR__ . '/' . MyClass::MY_CONST;` - can find it if the const has the correct value from the start.
28+
29+
## Unsupported cases
30+
- `require $file;` - won't throw an error since it cannot read variables.
31+
- `require (new MyClass())->file;` - won't throw an error since it cannot read class properties.

0 commit comments

Comments
 (0)