diff --git a/src/RobotLoader/RobotLoader.php b/src/RobotLoader/RobotLoader.php index 8fb3145..88bcf31 100644 --- a/src/RobotLoader/RobotLoader.php +++ b/src/RobotLoader/RobotLoader.php @@ -88,28 +88,40 @@ public function register(bool $prepend = false): self public function tryLoad(string $type): void { $this->loadCache(); + + $missing = $this->missing[$type] ?? null; + if ($missing >= self::RETRY_LIMIT) { + return; + } + $info = $this->classes[$type] ?? null; if ($this->autoRebuild) { - if (!$info || !is_file($info['file'])) { - $missing = &$this->missing[$type]; - $missing++; - if (!$this->refreshed && $missing <= self::RETRY_LIMIT) { + $save = false; + + if (!$this->refreshed) { + if (!$info || !is_file($info['file'])) { $this->refreshClasses(); - $this->saveCache(); - } elseif ($info) { - unset($this->classes[$type]); - $this->saveCache(); - } + $info = $this->classes[$type] ?? null; + $save = true; - } elseif (!$this->refreshed && filemtime($info['file']) !== $info['time']) { - $this->updateFile($info['file']); - if (empty($this->classes[$type])) { - $this->missing[$type] = 0; + } elseif (filemtime($info['file']) !== $info['time']) { + $this->updateFile($info['file']); + $info = $this->classes[$type] ?? null; + $save = true; } + } + + if (!$info || !is_file($info['file'])) { + $this->missing[$type] = ++$missing; + $save = $save || $info || ($missing <= self::RETRY_LIMIT); + unset($this->classes[$type]); + $info = null; + } + + if ($save) { $this->saveCache(); } - $info = $this->classes[$type] ?? null; } if ($info) {