format('Y-m-d_H-i-s') . '.sql.gz'; } public function parse(string $filename): ?\DateTimeImmutable { if (preg_match(self::PATTERN, $filename, $matches) !== 1) { return null; } $dateTime = \DateTimeImmutable::createFromFormat( 'Y-m-d_H-i-s', $matches[1] . '_' . $matches[2] ); return $dateTime ?: null; } public function isValid(string $filename): bool { return $this->parse($filename) !== null; } }