Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ConditionsScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ trait ConditionsScript
/**
* If this Preloader should run
*
* @var callable
* @var callable|null
Copy link
Author

@szepeviktor szepeviktor Aug 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$condition property could be uninitialized.

*/
protected $condition;

Expand Down
2 changes: 1 addition & 1 deletion src/Opcache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

status is not nullable.

return $this->status;
}

Expand Down
10 changes: 5 additions & 5 deletions src/Preloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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].");
}
Comment on lines 155 to 157
Copy link
Author

@szepeviktor szepeviktor Aug 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put the unhappy path in the conditional.

source


throw new RuntimeException("Preloader couldn't write the script to [$path].");
return true;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/PreloaderCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class PreloaderCompiler
*
* @var false|string
*/
public string $contents;
public $contents;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$contents could be false.


/**
* Configuration array.
Expand Down Expand Up @@ -67,7 +67,7 @@ class PreloaderCompiler
*
* @return string|string[]
*/
public function compile() : string
public function compile()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compile() can return an array.

{
$replacing = array_merge($this->preloaderConfig, $this->opcacheConfig, [
'@output' => $this->scriptRealPath(),
Expand All @@ -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 ?: []);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$contents could be false.

}

/**
Expand Down