eugene-matvejev/battleship-game-api

View on GitHub

Showing 153 of 153 total issues

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

    private function chooseStrategy(Cell $cell) : int
    {
        $processor = new PathProcessor($cell->getCoordinate());

        $battlefield = $cell->getBattlefield();
Severity: Minor
Found in src/GameBundle/Service/AI/AIStrategyService.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 addBattlefield has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public function addBattlefield()
    {
        $game = MockFactory::getGameMock();
        $game->getBattlefields()[0]
            ->setPlayer(MockFactory::getAIPlayerMock(''))
Severity: Minor
Found in tests/phpunit/GameBundle/Response/GameInitiationResponseTest.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 processPlayerTurnOnBattlefields has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    protected function processPlayerTurnOnBattlefields(Game $game, Player $attacker, Cell $cell) : bool
    {
        foreach ($game->getBattlefields() as $battlefield) {
            try {
                if ($this->processPlayerTurnOnBattlefield($battlefield, $attacker, $cell)) {
Severity: Minor
Found in src/GameBundle/Service/GameSystem/GameProcessor.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

Avoid assigning values to variables in if clauses and the like (line '85', column '22').
Open

    public function turnAction(int $cellId) : Response
    {
        if (null === $cell = $this->getDoctrine()->getRepository('GameBundle:Cell')->find($cellId)) {
            throw new CellException(Response::HTTP_NOT_FOUND, "cell: {$cellId} do not exist");
        }

IfStatementAssignment

Since: 2.7.0

Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

Example

class Foo
{
    public function bar($flag)
    {
        if ($foo = 'bar') { // possible typo
            // ...
        }
        if ($baz = 0) { // always false
            // ...
        }
    }
}

Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

Avoid using static access to class '\EM\GameBundle\Model\BattlefieldModel' in method 'flagWaterAroundShipOnA1AlreadyDead'.
Open

        BattlefieldModel::flagWaterAroundShip($cell);

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

Source https://phpmd.org/rules/cleancode.html#staticaccess

Avoid using static access to class '\EM\Tests\Environment\Factory\MockFactory' in method 'setCellsOnExternalCall'.
Open

        $response = new GameTurnResponse(MockFactory::getGameMock(), []);

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

Source https://phpmd.org/rules/cleancode.html#staticaccess

Avoid using static access to class '\EM\Tests\Environment\Factory\MockFactory' in method 'AdjacentCellsProvider'.
Open

                MockFactory::getBattlefieldMock(),

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

Source https://phpmd.org/rules/cleancode.html#staticaccess

The method successfulInitAction_XML uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

                } else {
                    $this->assertContains((string)$cell->flags, [CellModel::FLAG_NONE, CellModel::FLAG_SHIP, CellModel::FLAG_DEAD_SHIP]);
                }

ElseExpression

Since: 1.4.0

An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

Example

class Foo
{
    public function bar($flag)
    {
        if ($flag) {
            // one branch
        } else {
            // another branch
        }
    }
}

Source https://phpmd.org/rules/cleancode.html#elseexpression

Avoid using static access to class '\EM\FoundationBundle\Model\PlayerModel' in method 'isAIControlledOnFlagAIControlled'.
Open

        $this->assertTrue(PlayerModel::isAIControlled(MockFactory::getAIPlayerMock('')));

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

Source https://phpmd.org/rules/cleancode.html#staticaccess

Avoid using static access to class '\EM\Tests\Environment\Factory\MockFactory' in method 'setGameResultOnConstruct'.
Open

        $gameResult = MockFactory::getGameResultMock();

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

Source https://phpmd.org/rules/cleancode.html#staticaccess

Avoid using static access to class '\EM\GameBundle\Model\CellModel' in method 'turnAction'.
Open

        return $this->prepareSerializedResponse(new GameTurnResponse($game, CellModel::getChangedCells()));

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

Source https://phpmd.org/rules/cleancode.html#staticaccess

Avoid using static access to class '\EM\GameBundle\Model\BattlefieldModel' in method 'hasUnfinishedShips'.
Open

        $this->assertFalse(BattlefieldModel::hasUnfinishedShips($battlefield));

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

Source https://phpmd.org/rules/cleancode.html#staticaccess

Avoid using static access to class '\EM\Tests\Environment\Factory\MockFactory' in method 'pickCellToAttackExpectedCell'.
Open

        $cell = $this->pickCellToAttack([MockFactory::getCellMock('A1'), MockFactory::getCellMock('A2')]);

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

Source https://phpmd.org/rules/cleancode.html#staticaccess

Avoid using static access to class '\EM\Tests\Environment\Factory\MockFactory' in method 'assertProcessCPUTurnResult'.
Open

        $battlefield = MockFactory::getBattlefieldMock();

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

Source https://phpmd.org/rules/cleancode.html#staticaccess

Avoid using static access to class '\EM\Tests\Environment\Factory\MockFactory' in method 'processPlayerTurnOnBattlefieldToWin'.
Open

            ->setPlayer(MockFactory::getAIPlayerMock(''));

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

Source https://phpmd.org/rules/cleancode.html#staticaccess

Avoid using static access to class '\EM\GameBundle\Model\CellModel' in method 'chooseCells'.
Open

            if (!$cell->hasFlag(CellModel::FLAG_DEAD_SHIP) || CellModel::isShipDead($cell)) {

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

Source https://phpmd.org/rules/cleancode.html#staticaccess

Avoid using static access to class '\EM\GameBundle\Model\BattlefieldModel' in method 'processPlayerTurnOnBattlefield'.
Open

            return !BattlefieldModel::hasUnfinishedShips($battlefield);

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

Source https://phpmd.org/rules/cleancode.html#staticaccess

Avoid using static access to class '\EM\FoundationBundle\Model\PlayerModel' in method 'isAIControlledOnFlagNone'.
Open

        $this->assertFalse(PlayerModel::isAIControlled(MockFactory::getPlayerMock('')));

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

Source https://phpmd.org/rules/cleancode.html#staticaccess

Avoid using static access to class '\EM\Tests\Environment\Factory\MockFactory' in method 'processTurnToNotWin'.
Open

        $aiBattlefield->setPlayer(MockFactory::getAIPlayerMock(''));

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

Source https://phpmd.org/rules/cleancode.html#staticaccess

Avoid using static access to class '\EM\GameBundle\Model\BattlefieldModel' in method 'processCPUTurn'.
Open

            $cells = BattlefieldModel::getLiveCells($battlefield);

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

Source https://phpmd.org/rules/cleancode.html#staticaccess

Severity
Category
Status
Source
Language