Files
ik-codex/src/Detective/MultiPatternDetector.php
indifferentketchup 66a2fcc5f3 Rename namespace Aternos\Codex to IndifferentKetchup\Codex
Bulk substitution across all PHP files in src/ and test/. Covers
namespace declarations, use statements, fully-qualified class
references, and @package PHPDoc tags. No logic changes.
2026-04-30 15:13:52 +00:00

41 lines
921 B
PHP

<?php
namespace IndifferentKetchup\Codex\Detective;
/**
* MultiPatternDetector can detect multiple patterns in a log and return true if all patterns are found
*/
class MultiPatternDetector extends Detector
{
protected array $patterns = [];
/**
* Add a pattern to the list of patterns to detect
*
* @param string $pattern
* @return $this
*/
public function addPattern(string $pattern): static
{
$this->patterns[] = $pattern;
return $this;
}
/**
* Detects if the log matches all patterns
*
* Returns true if all patterns are found, false otherwise
*
* @return bool|float
*/
public function detect(): bool|float
{
foreach ($this->patterns as $pattern) {
if (preg_match($pattern, $this->getLogContent()) !== 1) {
return false;
}
}
return true;
}
}