This repository was archived by the owner on Sep 1, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +31
-1
lines changed Expand file tree Collapse file tree 1 file changed +31
-1
lines changed Original file line number Diff line number Diff line change 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.
You can’t perform that action at this time.
0 commit comments