fileExists(self::INFO_FILENAME)) { return null; } return self::fromString($storage->read(self::INFO_FILENAME)); } catch (FilesystemException|\InvalidArgumentException) { return null; } } public static function fromString(string $content): self { $content = mb_convert_encoding($content, 'UTF-8', 'Windows-1252'); $lines = array_filter(array_map('trim', explode("\n", $content))); if (count($lines) < 3) { throw new \InvalidArgumentException('Invalid uebertragung.info format: expected at least 3 lines'); } $timestamp = \DateTimeImmutable::createFromFormat(self::TIMESTAMP_FORMAT, $lines[0]); if (false === $timestamp) { throw new \InvalidArgumentException(sprintf('Invalid timestamp format in uebertragung.info: expected "%s", got "%s"', self::TIMESTAMP_FORMAT, $lines[0])); } if (1 !== preg_match('/(\d+)/', $lines[2], $matches)) { throw new \InvalidArgumentException(sprintf('Could not extract file count from: "%s"', $lines[2])); } return new self($timestamp, (int) $matches[1]); } public function isNewerThan(self $other): bool { return $this->lastTransfer > $other->lastTransfer; } }