open-orchestra/open-orchestra-cms-bundle

View on GitHub
Backoffice/Tests/Validator/Constraints/UniqueBlockCodeValidatorTest.php

Summary

Maintainability
A
3 hrs
Test Coverage

Avoid using static access to class '\Phake' in method 'setUp'.
Open

        Phake::when($this->context)->buildViolation(Phake::anyParameters())->thenReturn($this->constraintViolationBuilder);

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 '\Phake' in method 'setUp'.
Open

        $this->context = Phake::mock('Symfony\Component\Validator\Context\ExecutionContext');

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 '\Phake' in method 'testValidate'.
Open

        Phake::when($this->repository)->findOneTransverseBlockByCode(Phake::anyParameters())->thenReturn($blockCode);

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 '\Phake' in method 'setUp'.
Open

        Phake::when($this->constraintViolationBuilder)->atPath(Phake::anyParameters())->thenReturn($this->constraintViolationBuilder);

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 '\Phake' in method 'provideBlockCode'.
Open

        $block = Phake::mock('OpenOrchestra\ModelInterface\Model\BlockInterface');

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 '\Phake' in method 'provideBlockCode'.
Open

        $blockCode = Phake::mock('OpenOrchestra\ModelInterface\Model\BlockInterface');

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 '\Phake' in method 'testValidate'.
Open

        $constraint = Phake::mock('OpenOrchestra\Backoffice\Validator\Constraints\UniqueBlockCode');

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 '\Phake' in method 'setUp'.
Open

        $this->constraintViolationBuilder = Phake::mock('Symfony\Component\Validator\Violation\ConstraintViolationBuilder');

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 '\Phake' in method 'setUp'.
Open

        $this->repository = Phake::mock('OpenOrchestra\ModelInterface\Repository\BlockRepositoryInterface');

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 '\Phake' in method 'testValidate'.
Open

        Phake::verify($this->constraintViolationBuilder, Phake::times($violationCount))->addViolation();

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

Call to method anyParameters from undeclared class \Phake
Open

        Phake::when($this->constraintViolationBuilder)->atPath(Phake::anyParameters())->thenReturn($this->constraintViolationBuilder);

Call to method when from undeclared class \Phake
Open

        Phake::when($block)->getId()->thenReturn('fakeId');

Class extends undeclared class \OpenOrchestra\BaseBundle\Tests\AbstractTest\AbstractBaseTestCase
Open

class UniqueBlockCodeValidatorTest extends AbstractBaseTestCase

Call to method when from undeclared class \Phake
Open

        Phake::when($block)->getLanguage()->thenReturn('fakeLanguage');

Call to method when from undeclared class \Phake
Open

        Phake::when($this->repository)->findOneTransverseBlockByCode(Phake::anyParameters())->thenReturn($blockCode);

Call to method times from undeclared class \Phake
Open

        Phake::verify($this->constraintViolationBuilder, Phake::times($violationCount))->addViolation();

Call to method when from undeclared class \Phake
Open

        Phake::when($blockCode)->getId()->thenReturn('blockCodeFakeId');

Call to method mock from undeclared class \Phake
Open

        $this->context = Phake::mock('Symfony\Component\Validator\Context\ExecutionContext');

Call to undeclared method \OpenOrchestra\Backoffice\Tests\Validator\Constraints\UniqueBlockCodeValidatorTest::assertInstanceOf
Open

        $this->assertInstanceOf('Symfony\Component\Validator\ConstraintValidator', $this->validator);

Call to method mock from undeclared class \Phake
Open

        $block = Phake::mock('OpenOrchestra\ModelInterface\Model\BlockInterface');

Call to method when from undeclared class \Phake
Open

        Phake::when($this->constraintViolationBuilder)->atPath(Phake::anyParameters())->thenReturn($this->constraintViolationBuilder);

Call to method when from undeclared class \Phake
Open

        Phake::when($this->context)->buildViolation(Phake::anyParameters())->thenReturn($this->constraintViolationBuilder);

Call to method verify from undeclared class \Phake
Open

        Phake::verify($this->constraintViolationBuilder, Phake::times($violationCount))->addViolation();

Call to method mock from undeclared class \Phake
Open

        $this->repository = Phake::mock('OpenOrchestra\ModelInterface\Repository\BlockRepositoryInterface');

Parameter $blockCode has undeclared type \OpenOrchestra\ModelInterface\Model\BlockInterface
Open

    public function testValidate($code, $block, $blockCode, $violationCount)

Call to method when from undeclared class \Phake
Open

        Phake::when($block)->isTransverse()->thenReturn(true);

Call to method when from undeclared class \Phake
Open

        Phake::when($blockCode)->getCode()->thenReturn('fakeCode');

Call to undeclared method \OpenOrchestra\Backoffice\Validator\Constraints\UniqueBlockCodeValidator::initialize
Open

        $this->validator->initialize($this->context);

Call to method mock from undeclared class \Phake
Open

        $this->constraintViolationBuilder = Phake::mock('Symfony\Component\Validator\Violation\ConstraintViolationBuilder');

Parameter $block has undeclared type \OpenOrchestra\ModelInterface\Model\BlockInterface
Open

    public function testValidate($code, $block, $blockCode, $violationCount)

Call to method mock from undeclared class \Phake
Open

        $blockCode = Phake::mock('OpenOrchestra\ModelInterface\Model\BlockInterface');

Call to method anyParameters from undeclared class \Phake
Open

        Phake::when($this->context)->buildViolation(Phake::anyParameters())->thenReturn($this->constraintViolationBuilder);

Call to method mock from undeclared class \Phake
Open

        $constraint = Phake::mock('OpenOrchestra\Backoffice\Validator\Constraints\UniqueBlockCode');

Call to method anyParameters from undeclared class \Phake
Open

        Phake::when($this->repository)->findOneTransverseBlockByCode(Phake::anyParameters())->thenReturn($blockCode);

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    public function setUp()
    {
        $this->constraintViolationBuilder = Phake::mock('Symfony\Component\Validator\Violation\ConstraintViolationBuilder');
        Phake::when($this->constraintViolationBuilder)->atPath(Phake::anyParameters())->thenReturn($this->constraintViolationBuilder);

Backoffice/Tests/Validator/Constraints/UniqueRedirectionValidatorTest.php on lines 24..35

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 143.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Avoid excessively long variable names like $constraintViolationBuilder. Keep variable name length under 20.
Open

    protected $constraintViolationBuilder;

LongVariable

Since: 0.2

Detects when a field, formal or local variable is declared with a long name.

Example

class Something {
    protected $reallyLongIntName = -3; // VIOLATION - Field
    public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
        $otherReallyLongName = -5; // VIOLATION - Local
        for ($interestingIntIndex = 0; // VIOLATION - For
             $interestingIntIndex < 10;
             $interestingIntIndex++ ) {
        }
    }
}

Source https://phpmd.org/rules/naming.html#longvariable

Line exceeds 120 characters; contains 123 characters
Open

        Phake::when($this->context)->buildViolation(Phake::anyParameters())->thenReturn($this->constraintViolationBuilder);

Line exceeds 120 characters; contains 124 characters
Open

        $this->constraintViolationBuilder = Phake::mock('Symfony\Component\Validator\Violation\ConstraintViolationBuilder');

Line exceeds 120 characters; contains 134 characters
Open

        Phake::when($this->constraintViolationBuilder)->atPath(Phake::anyParameters())->thenReturn($this->constraintViolationBuilder);

There are no issues that match your filters.

Category
Status