glhd/ansipants

View on GitHub

Showing 12 of 14 total issues

File AnsiString.php has 294 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace Glhd\AnsiPants;

use Generator;
Severity: Minor
Found in src/AnsiString.php - About 3 hrs to fix

    AnsiString has 22 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class AnsiString implements Stringable
    {
        /** @var \Illuminate\Support\Collection<int,\Glhd\AnsiPants\AnsiChar> */
        protected Collection $chars;
        
    Severity: Minor
    Found in src/AnsiString.php - About 2 hrs to fix

      Function extractMetadata has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function extractMetadata(): void
          {
              preg_match("/^\e\[(\d+(?:;\d+)*)+m$/", $this->value, $matches);
              
              $args = array_map('intval', explode(';', $matches[1]));
      Severity: Minor
      Found in src/Support/Parsing/EscapeSequence.php - About 1 hr 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

      Consider simplifying this complex logical expression.
      Open

              if (
                  ($this->flag >= 30 && $this->flag < 37)
                  || ($this->flag >= 40 && $this->flag < 47)
                  || ($this->flag >= 90 && $this->flag < 97)
                  || ($this->flag >= 100 && $this->flag < 107)
      Severity: Critical
      Found in src/Support/Parsing/EscapeSequence.php - About 1 hr to fix

        Function explode has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            public function explode(AnsiString|string $break, bool $ignore_style = true): Collection
            {
                $break = new AnsiString($break);
                $results = new Collection();
                $buffer = new AnsiString('');
        Severity: Minor
        Found in src/AnsiString.php - About 55 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

        Function overrides has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            public function overrides(Flag $flag): bool
            {
                if ($this === self::Reset) {
                    return true;
                }
        Severity: Minor
        Found in src/Flag.php - About 55 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

        Function words has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            protected function words(?int $max_length): Generator
            {
                $sep = new static('');
                $word = new static('');
                
        Severity: Minor
        Found in src/AnsiString.php - About 55 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

        Function wordwrap has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            public function wordwrap(int $width = 75, AnsiString|string $break = "\e[0m\n", bool $cut_long_words = false): static
            {
                $break = new AnsiString($break);
                $buffer = new AnsiString('');
                $wrapped = new AnsiString('');
        Severity: Minor
        Found in src/AnsiString.php - About 45 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

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

            public function substr(int $start, ?int $length = null): static
            {
                if (0 === $length || $start >= $this->length()) {
                    return new static('');
                }
        Severity: Minor
        Found in src/AnsiString.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

        Avoid too many return statements within this method.
        Open

                        return true;
        Severity: Major
        Found in src/Flag.php - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

                  return false;
          Severity: Major
          Found in src/Flag.php - About 30 mins to fix

            Function diffFlags has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                protected function diffFlags($a, $b): array
                {
                    // Sadly array_diff doesn't work on enums :(
                    $remove = [];
                    $add = [];
            Severity: Minor
            Found in src/AnsiString.php - About 25 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

            Severity
            Category
            Status
            Source
            Language