Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Dec 14, 2022
1 parent 66c08e3 commit 970c8f8
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/RobotLoader/RobotLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class RobotLoader
{
use Nette\SmartObject;

private const RETRY_LIMIT = 3;
private const RetryLimit = 3;

/** @var string[] */
public $ignoreDirs = ['.*', '*.old', '*.bak', '*.tmp', 'temp'];
Expand Down Expand Up @@ -104,7 +104,7 @@ public function tryLoad(string $type): void
$this->loadCache();

$missing = $this->missingClasses[$type] ?? null;
if ($missing >= self::RETRY_LIMIT) {
if ($missing >= self::RetryLimit) {
return;
}

Expand All @@ -126,7 +126,7 @@ public function tryLoad(string $type): void

if (!$file || !is_file($file)) {
$this->missingClasses[$type] = ++$missing;
$this->needSave = $this->needSave || $file || ($missing <= self::RETRY_LIMIT);
$this->needSave = $this->needSave || $file || ($missing <= self::RetryLimit);
unset($this->classes[$type]);
$file = null;
}
Expand Down Expand Up @@ -479,7 +479,7 @@ private function loadCache(): void

$this->cacheLoaded = true;

$file = $this->getCacheFile();
$file = $this->generateCacheFileName();

// Solving atomicity to work everywhere is really pain in the ass.
// 1) We want to do as little as possible IO calls on production and also directory and file can be not writable (#19)
Expand Down Expand Up @@ -525,7 +525,7 @@ private function saveCache($lock = null): void
// we have to acquire a lock to be able safely rename file
// on Linux: that another thread does not rename the same named file earlier
// on Windows: that the file is not read by another thread
$file = $this->getCacheFile();
$file = $this->generateCacheFileName();
$lock = $lock ?: $this->acquireLock("$file.lock", LOCK_EX);
$code = "<?php\nreturn " . var_export([$this->classes, $this->missingClasses, $this->emptyFiles], true) . ";\n";

Expand Down Expand Up @@ -559,7 +559,7 @@ private function acquireLock(string $file, int $mode)
}


private function getCacheFile(): string
private function generateCacheFileName(): string
{
if (!$this->tempDirectory) {
throw new \LogicException('Set path to temporary directory using setTempDirectory().');
Expand Down

0 comments on commit 970c8f8

Please sign in to comment.