| Conditions | 4 |
| Paths | 2 |
| Total Lines | 19 |
| Code Lines | 7 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 20 |
| Changes | 0 | ||
| 1 | <?php |
||
| 16 | public static function checkAndLoad($filename) |
||
| 17 | { |
||
| 18 | $includePathFilename = \stream_resolve_include_path($filename); |
||
| 19 | |||
| 20 | // As a fallback, PHP looks in the directory of the file executing the stream_resolve_include_path function. |
||
| 21 | // We don't want to load the Test.php file here, so skip it if it found that. |
||
| 22 | // PHP prioritizes the include_path setting, so if the current directory is in there, it will first look in the |
||
| 23 | // current working directory. |
||
| 24 | $localFile = __DIR__ . DIRECTORY_SEPARATOR . $filename; |
||
| 25 | |||
| 26 | $isReadable = @\fopen($includePathFilename, 'r') !== false; |
||
| 27 | |||
| 28 | if (!$includePathFilename || !$isReadable || $includePathFilename === $localFile) { |
||
| 29 | throw new \Exception(\sprintf('Cannot open file "%s".' . "\n", $filename)); |
||
| 30 | } |
||
| 31 | |||
| 32 | require_once $includePathFilename; |
||
| 33 | |||
| 34 | return $includePathFilename; |
||
| 35 | } |
||
| 37 |