t1gor/Robots.txt-Parser-Class

View on GitHub
source/Parser/TreeBuilder.php

Summary

Maintainability
A
1 hr
Test Coverage

Method processDirective has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

    protected function processDirective(string $directive, string $line, &$tree, string &$userAgent, string $prevLine = '') {
Severity: Minor
Found in source/Parser/TreeBuilder.php - About 35 mins to fix

    Function build has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        public function build(): array {
            $currentUserAgent = '*';
            $tree             = [];
            $prevLine         = '';
    
    
    Severity: Minor
    Found in source/Parser/TreeBuilder.php - About 35 mins to fix

    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

    class TreeBuilder implements TreeBuilderInterface {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $this->processors[$processor->getDirectiveName()] = $processor;

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /**

    Spaces must be used to indent lines; tabs are not allowed
    Open

         */

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /**

    Spaces must be used to indent lines; tabs are not allowed
    Open

            if (!isset($this->processors[$directive])) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                            $processor->getDirectiveName(),

    Spaces must be used to indent lines; tabs are not allowed
    Open

        protected array     $processors;

    Line exceeds 120 characters; contains 125 characters
    Open

        protected function processDirective(string $directive, string $line, &$tree, string &$userAgent, string $prevLine = '') {

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $currentUserAgent = '*';

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $prevLine         = '';

    Spaces must be used to indent lines; tabs are not allowed
    Open

                            $currentUserAgent,

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @param LoggerInterface|null          $logger

    Spaces must be used to indent lines; tabs are not allowed
    Open

            }

    Spaces must be used to indent lines; tabs are not allowed
    Open

        }

    Spaces must be used to indent lines; tabs are not allowed
    Open

                            $prevLine

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        break;

    Spaces must be used to indent lines; tabs are not allowed
    Open

         */

    Spaces must be used to indent lines; tabs are not allowed
    Open

        protected function processDirective(string $directive, string $line, &$tree, string &$userAgent, string $prevLine = '') {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $this->log(strtr('{directive} met, but no processor found for it. Skipping.', [

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /**

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    if ($processor->matches($line)) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        );

    Spaces must be used to indent lines; tabs are not allowed
    Open

                // override

    Spaces must be used to indent lines; tabs are not allowed
    Open

            }

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    '{directive}' => $directive,

    Spaces must be used to indent lines; tabs are not allowed
    Open

        public function getContent(): \Iterator {

    Spaces must be used to indent lines; tabs are not allowed
    Open

            return $this->content;

    Spaces must be used to indent lines; tabs are not allowed
    Open

            if (empty($processors)) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

            // reformat processors

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $this->processors[$directive]->process($line, $tree, $userAgent, $prevLine);

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /**

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @param \Iterator $content

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $tree             = [];

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /**

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @var DirectiveProcessorInterface[]

    Spaces must be used to indent lines; tabs are not allowed
    Open

         */

    Spaces must be used to indent lines; tabs are not allowed
    Open

        }

    Spaces must be used to indent lines; tabs are not allowed
    Open

         */

    Spaces must be used to indent lines; tabs are not allowed
    Open

        public function build(): array {

    Spaces must be used to indent lines; tabs are not allowed
    Open

            foreach ($this->content as $line) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        $this->processDirective(

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @param DirectiveProcessorInterface[] $processors

    Spaces must be used to indent lines; tabs are not allowed
    Open

        public function __construct(array $processors, ?LoggerInterface $logger) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $this->log("Seems like you've passed an empty processors array.", [], LogLevel::WARNING);

    Spaces must be used to indent lines; tabs are not allowed
    Open

                            $line,

    Spaces must be used to indent lines; tabs are not allowed
    Open

        protected \Iterator $content;

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @return array

    Spaces must be used to indent lines; tabs are not allowed
    Open

                            $tree,

    Spaces must be used to indent lines; tabs are not allowed
    Open

            }

    Spaces must be used to indent lines; tabs are not allowed
    Open

                ]));

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @return \Iterator

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /**

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * Wrapper to check that processor is available

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    }

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $this->logger = $logger;

    Spaces must be used to indent lines; tabs are not allowed
    Open

        }

    Spaces must be used to indent lines; tabs are not allowed
    Open

         */

    Spaces must be used to indent lines; tabs are not allowed
    Open

        public function setContent(\Iterator $content): void {

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $this->content = $content;

    Spaces must be used to indent lines; tabs are not allowed
    Open

                foreach ($this->processors as $processor) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

            return $tree;

    Spaces must be used to indent lines; tabs are not allowed
    Open

                return;

    Spaces must be used to indent lines; tabs are not allowed
    Open

         */

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @todo check for multibyte support?

    Spaces must be used to indent lines; tabs are not allowed
    Open

                }

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $prevLine = $line;

    Spaces must be used to indent lines; tabs are not allowed
    Open

        use LogsIfAvailableTrait;

    Spaces must be used to indent lines; tabs are not allowed
    Open

        }

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $this->log('Building directives tree...');

    Spaces must be used to indent lines; tabs are not allowed
    Open

        }

    Spaces must be used to indent lines; tabs are not allowed
    Open

            foreach ($processors as $processor) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

            }

    Opening brace should be on a new line
    Open

        public function __construct(array $processors, ?LoggerInterface $logger) {

    Opening brace should be on a new line
    Open

        protected function processDirective(string $directive, string $line, &$tree, string &$userAgent, string $prevLine = '') {

    Opening brace should be on a new line
    Open

        public function build(): array {

    Opening brace should be on a new line
    Open

        public function setContent(\Iterator $content): void {

    Opening brace should be on a new line
    Open

        public function getContent(): \Iterator {

    There are no issues that match your filters.

    Category
    Status