| Conditions | 4 |
| Paths | 2 |
| Total Lines | 19 |
| Code Lines | 7 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 8 |
| CRAP Score | 4 |
| Changes | 0 | ||
| 1 | <?php |
||
| 34 | 2 | public static function checkAndLoad(string $filename): string |
|
| 35 | { |
||
| 36 | 2 | $includePathFilename = \stream_resolve_include_path($filename); |
|
| 37 | |||
| 38 | // As a fallback, PHP looks in the directory of the file executing the stream_resolve_include_path function. |
||
| 39 | // We don't want to load the Test.php file here, so skip it if it found that. |
||
| 40 | // PHP prioritizes the include_path setting, so if the current directory is in there, it will first look in the |
||
| 41 | // current working directory. |
||
| 42 | 2 | $localFile = __DIR__ . DIRECTORY_SEPARATOR . $filename; |
|
| 43 | |||
| 44 | 2 | $isReadable = @\fopen($includePathFilename, 'r') !== false; |
|
| 45 | |||
| 46 | 2 | if (!$includePathFilename || !$isReadable || $includePathFilename === $localFile) { |
|
| 47 | 1 | throw new \Exception(\sprintf('Cannot open file "%s".' . "\n", $filename)); |
|
| 48 | } |
||
| 49 | |||
| 50 | 1 | require_once $includePathFilename; |
|
| 51 | |||
| 52 | 1 | return $includePathFilename; |
|
| 53 | } |
||
| 55 |