onspli/chess

View on GitHub

Showing 24 of 26 total issues

Function set_castling has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
Open

    public function set_castling(string $castling) : void
    {
      if (in_array($castling, ['-', 'KQkq', 'KQk', 'KQq', 'KQ', 'Kkq', 'Kk', 'Kq', 'K', 'Qkq', 'Qk', 'Qq', 'Q', 'kq', 'k', 'q'])) {
        $new_use_shredder_fen = false;
        $new_kings_rook_file = 'h';
Severity: Minor
Found in src/FEN.php - About 3 hrs 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 validate_castling has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

    private function validate_castling(array $castling_rights, $kings_file, $kings_rook_file, $queens_rook_file) : void
    {

      if ($castling_rights['K'] || $castling_rights['Q'])
      {
Severity: Minor
Found in src/FEN.php - About 2 hrs 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

Method set_castling has 55 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function set_castling(string $castling) : void
    {
      if (in_array($castling, ['-', 'KQkq', 'KQk', 'KQq', 'KQ', 'Kkq', 'Kk', 'Kq', 'K', 'Qkq', 'Qk', 'Qq', 'Q', 'kq', 'k', 'q'])) {
        $new_use_shredder_fen = false;
        $new_kings_rook_file = 'h';
Severity: Major
Found in src/FEN.php - About 2 hrs to fix

    Function after_move_update_castling_availability has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

        private function after_move_update_castling_availability(string $piece_type, Square $origin_square, Square $target_square) : void
        {
          $active_color = $this->get_active_color();
          if ($active_color == 'w') {
            $active_first_rank = '1';
    Severity: Minor
    Found in src/FEN.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

    Method validate_castling has 36 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private function validate_castling(array $castling_rights, $kings_file, $kings_rook_file, $queens_rook_file) : void
        {
    
          if ($castling_rights['K'] || $castling_rights['Q'])
          {
    Severity: Minor
    Found in src/FEN.php - About 1 hr to fix

      Function push_piece_pseudolegal_moves_to_specific_target_square_to_array has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          private function push_piece_pseudolegal_moves_to_specific_target_square_to_array(array &$arr, string $piece, array $origin_squares, Square $target_square) : void
          {
      
            $capture = $this->is_capture($target_square) ? 'x' : '';
            $piece_type = Board::get_piece_of_color($piece, 'w');
      Severity: Minor
      Found in src/FEN.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

      Function get_move_origin_candidates has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          private function get_move_origin_candidates(string $piece, Square $target_square, bool $is_capture) : array
          {
            if ($piece == 'P' && !$is_capture) {
              $origin_candidates = [$target_square->get_relative_square(0, -1)];
              if ($target_square->get_rank_index() == 3 && $this->board->is_square_vacant($target_square->get_relative_square(0, -1))) {
      Severity: Minor
      Found in src/FEN.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

      Method get_move_origin has 29 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private function get_move_origin(Move $move) : Square
          {
            $piece = $this->get_active_piece($move->get_piece_type());
            $move_origin = $move->get_origin(true);
      
      
      Severity: Minor
      Found in src/FEN.php - About 1 hr to fix

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

            private function get_new_board(Move $move, Square $origin) : Board
            {
              $new_board = clone $this->board;
              $piece = $this->get_active_piece($move->get_piece_type());
              $target = $move->get_target(true);
        Severity: Minor
        Found in src/FEN.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 set_tag has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

          public function set_tag(string $name, ?string $value) : void
          {
            if ($value !== null) {
              $this->tags[$name] = $value;
              if ($name == 'FEN') {
        Severity: Minor
        Found in src/PGN.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

        Method push_squares_in_direction_to_array has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

          private function push_squares_in_direction_to_array(array &$arr, Square $origin_square, int $north, int $east, bool $as_object, string $excluded_color = '') : void
        Severity: Minor
        Found in src/Board.php - About 45 mins to fix

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

            public function export_movetext() : string
            {
              $pgn = '';
              for ($halfmove_number = $this->get_initial_halfmove_number(); $halfmove_number <= $this->get_last_halfmove_number(); $halfmove_number++) {
                $move_number = ceil($halfmove_number / 2);
          Severity: Minor
          Found in src/PGN.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 get_move_origin has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              private function get_move_origin(Move $move) : Square
              {
                $piece = $this->get_active_piece($move->get_piece_type());
                $move_origin = $move->get_origin(true);
          
          
          Severity: Minor
          Found in src/FEN.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

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

            private function push_squares_defended_by_not_a_pawn_to_array(array &$arr, string $piece, Square $piece_square, bool $as_object, string $excluded_color = '') : void
          Severity: Minor
          Found in src/Board.php - About 35 mins to fix

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

              private function push_square_with_pawn_capture_to_array(array &$arr, Square $target_square, Square $en_passant_square, bool $as_object, string $excluded_color) : void
            Severity: Minor
            Found in src/Board.php - About 35 mins to fix

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

                  private function castle_generic(Move &$move, Square $origin_king, Square $target_king, Square $origin_rook, Square $target_rook)
              Severity: Minor
              Found in src/FEN.php - About 35 mins to fix

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

                    private function are_castling_squares_vacant(Square $origin, Square $target, $allowed_rook_file)
                    {
                      $min_file = min($origin->get_file(), $target->get_file());
                      $max_file = max($origin->get_file(), $target->get_file());
                
                
                Severity: Minor
                Found in src/FEN.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

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

                    private function get_reachable_squares_origins(string $piece) : array
                    {
                      $reachable_squares_origins = [];
                      $origin_candidates = $this->board->find_squares_with_piece($piece, true);
                      foreach ($origin_candidates as $origin_square) {
                Severity: Minor
                Found in src/FEN.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

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

                  private function push_squares_defended_by_not_a_pawn_to_array(array &$arr, string $piece, Square $piece_square, bool $as_object, string $excluded_color = '') : void
                  {
                    switch ($piece) {
                      case 'K':
                      case 'k':
                Severity: Minor
                Found in src/Board.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

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

                  private function fill_rank(string $rank_pieces, int $rank_index) : void
                  {
                    $file_index = 0;
                    $rank_pieces_array = str_split($rank_pieces);
                    foreach ($rank_pieces_array as $piece)
                Severity: Minor
                Found in src/Board.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