for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace BrowscapPHP\Util\Logfile;
use BrowscapPHP\Exception\ReaderException;
/**
* abstract parent class for all readers
*/
abstract class AbstractReader implements ReaderInterface
{
* @param string $line
*
* @return bool
public function test(string $line) : bool
$matches = $this->match($line);
return isset($matches['userAgentString']);
}
* @throws \BrowscapPHP\Exception\ReaderException
* @return string
public function read(string $line) : string
if (!isset($matches['userAgentString'])) {
throw ReaderException::userAgentParserError($line);
return $matches['userAgentString'];
* @return array
protected function match(string $line) : array
$matches = [];
if (preg_match($this->getRegex(), $line, $matches)) {
return $matches;
return [];
abstract protected function getRegex() : string;