diff --git a/src/ConditionsScript.php b/src/ConditionsScript.php index 8d47f72..db7a5c0 100644 --- a/src/ConditionsScript.php +++ b/src/ConditionsScript.php @@ -7,7 +7,7 @@ trait ConditionsScript /** * If this Preloader should run * - * @var callable + * @var callable|null */ protected $condition; diff --git a/src/Opcache.php b/src/Opcache.php index 9cd30b9..9ddb310 100644 --- a/src/Opcache.php +++ b/src/Opcache.php @@ -27,7 +27,7 @@ class Opcache */ public function getStatus() : array { - if ($this->status ??= opcache_get_status(true)) { + if ($this->status = $this->status ?: opcache_get_status(true)) { return $this->status; } diff --git a/src/Preloader.php b/src/Preloader.php index 03d1a0a..35a4064 100644 --- a/src/Preloader.php +++ b/src/Preloader.php @@ -135,7 +135,7 @@ protected function canGenerate(string $path, bool $overwrite) : bool } // If there is a condition, call it. - if ($this->condition) { + if (is_callable($this->condition)) { return (bool) call_user_func($this->condition); } @@ -146,17 +146,17 @@ protected function canGenerate(string $path, bool $overwrite) : bool * Writes the preloader script file into the specified path. * * @param string $path - * @return false|int + * @return true * * @codeCoverageIgnore */ protected function performWrite(string $path) { - if (file_put_contents($path, $this->prepareCompiler($path)->compile(), LOCK_EX)) { - return true; + if (file_put_contents($path, $this->prepareCompiler($path)->compile(), LOCK_EX) === false) { + throw new RuntimeException("Preloader couldn't write the script to [$path]."); } - throw new RuntimeException("Preloader couldn't write the script to [$path]."); + return true; } /** diff --git a/src/PreloaderCompiler.php b/src/PreloaderCompiler.php index 1688ab7..48e8ee8 100644 --- a/src/PreloaderCompiler.php +++ b/src/PreloaderCompiler.php @@ -11,7 +11,7 @@ class PreloaderCompiler * * @var false|string */ - public string $contents; + public $contents; /** * Configuration array. @@ -67,7 +67,7 @@ class PreloaderCompiler * * @return string|string[] */ - public function compile() : string + public function compile() { $replacing = array_merge($this->preloaderConfig, $this->opcacheConfig, [ '@output' => $this->scriptRealPath(), @@ -80,7 +80,7 @@ public function compile() : string ? 'require_once $file' : 'opcache_compile_file($file)', ]); - return str_replace(array_keys($replacing), $replacing, $this->contents); + return str_replace(array_keys($replacing), $replacing, $this->contents ?: []); } /**