source/Parser/TreeBuilder.php
Method processDirective
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
protected function processDirective(string $directive, string $line, &$tree, string &$userAgent, string $prevLine = '') {
Function build
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
Open
public function build(): array {
$currentUserAgent = '*';
$tree = [];
$prevLine = '';
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Opening brace of a class must be on the line after the definition Open
Open
class TreeBuilder implements TreeBuilderInterface {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$this->processors[$processor->getDirectiveName()] = $processor;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
if (!isset($this->processors[$directive])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$processor->getDirectiveName(),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
protected array $processors;
- Exclude checks
Line exceeds 120 characters; contains 125 characters Open
Open
protected function processDirective(string $directive, string $line, &$tree, string &$userAgent, string $prevLine = '') {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$currentUserAgent = '*';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$prevLine = '';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$currentUserAgent,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @param LoggerInterface|null $logger
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$prevLine
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
protected function processDirective(string $directive, string $line, &$tree, string &$userAgent, string $prevLine = '') {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$this->log(strtr('{directive} met, but no processor found for it. Skipping.', [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
if ($processor->matches($line)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
// override
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
'{directive}' => $directive,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
public function getContent(): \Iterator {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
return $this->content;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
if (empty($processors)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
// reformat processors
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$this->processors[$directive]->process($line, $tree, $userAgent, $prevLine);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @param \Iterator $content
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$tree = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @var DirectiveProcessorInterface[]
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
public function build(): array {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
foreach ($this->content as $line) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$this->processDirective(
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @param DirectiveProcessorInterface[] $processors
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
public function __construct(array $processors, ?LoggerInterface $logger) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$this->log("Seems like you've passed an empty processors array.", [], LogLevel::WARNING);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$line,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
protected \Iterator $content;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @return array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$tree,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
]));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @return \Iterator
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* Wrapper to check that processor is available
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$this->logger = $logger;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
public function setContent(\Iterator $content): void {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$this->content = $content;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
foreach ($this->processors as $processor) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
return $tree;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
return;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @todo check for multibyte support?
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$prevLine = $line;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
use LogsIfAvailableTrait;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$this->log('Building directives tree...');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
foreach ($processors as $processor) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Opening brace should be on a new line Open
Open
public function __construct(array $processors, ?LoggerInterface $logger) {
- Exclude checks
Opening brace should be on a new line Open
Open
protected function processDirective(string $directive, string $line, &$tree, string &$userAgent, string $prevLine = '') {
- Exclude checks
Opening brace should be on a new line Open
Open
public function build(): array {
- Exclude checks
Opening brace should be on a new line Open
Open
public function setContent(\Iterator $content): void {
- Exclude checks
Opening brace should be on a new line Open
Open
public function getContent(): \Iterator {
- Exclude checks