open-orchestra/open-orchestra-cms-bundle

View on GitHub
WorkflowAdminBundle/Tests/Tranformer/StatusTransformerTest.php

Summary

Maintainability
A
1 hr
Test Coverage

Method setUp has 28 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function setUp()
    {
        $this->authorizationChecker = Phake::mock('Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface');
        $this->groupContext = Phake::mock('OpenOrchestra\BaseApi\Context\GroupContext');
        $multiLanguagesChoiceManager = Phake::mock('OpenOrchestra\ModelInterface\Manager\MultiLanguagesChoiceManagerInterface');
Severity: Minor
Found in WorkflowAdminBundle/Tests/Tranformer/StatusTransformerTest.php - About 1 hr to fix

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

        $this->usageFinder = Phake::mock('OpenOrchestra\Backoffice\UsageFinder\StatusUsageFinder');

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 'testReverseTransform'.
Open

        $facade = Phake::mock('OpenOrchestra\BaseApi\Facade\FacadeInterface');

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

        $router = Phake::mock('Symfony\Component\Routing\RouterInterface');

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 'testTransform'.
Open

        $content = Phake::mock('OpenOrchestra\ModelInterface\Model\ContentInterface');

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($groupContext)->hasGroup(Phake::anyParameters())->thenReturn(true);

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 'testTransform'.
Open

        Phake::when($this->groupContext)->hasGroup(Phake::anyParameters())->thenReturn($hasGroup);

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->statusRepository)->find(Phake::anyParameters())->thenReturn($this->status);

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->usageFinder)->hasUsage(Phake::anyParameters())->thenReturn(false);

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

        $multiLanguagesChoiceManager = Phake::mock('OpenOrchestra\ModelInterface\Manager\MultiLanguagesChoiceManagerInterface');

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->statusRepository = Phake::mock('OpenOrchestra\ModelInterface\Repository\StatusRepositoryInterface');

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 'testTransform'.
Open

        $attribute = Phake::mock('OpenOrchestra\ModelInterface\Model\ContentAttributeInterface');

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

        $transformerManager = Phake::mock('OpenOrchestra\BaseApi\Transformer\TransformerManager');

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

        $groupContext = Phake::mock('OpenOrchestra\BaseApi\Context\GroupContext');

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 'testExceptionTransform'.
Open

        $this->transformer->transform(Phake::mock('stdClass'));

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->groupContext = Phake::mock('OpenOrchestra\BaseApi\Context\GroupContext');

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->status = Phake::mock('OpenOrchestra\ModelInterface\Model\StatusInterface');

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 testReverseTransform uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            $this->assertSame($this->status, $status);
        }

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

        $this->translator = Phake::mock('Symfony\Component\Translation\TranslatorInterface');

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 'testTransform'.
Open

        Phake::when($this->translator)->trans(Phake::anyParameters())->thenReturn('trans_display_color');

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->authorizationChecker = Phake::mock('Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface');

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 testTransform uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            $this->isEmpty($facade->getRights());
        }

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

        Phake::when($router)->generateRoute(Phake::anyParameters())->thenReturn('route');

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 mock from undeclared class \Phake
Open

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

Call to method mock from undeclared class \Phake
Open

        $router = Phake::mock('Symfony\Component\Routing\RouterInterface');

Call to method mock from undeclared class \Phake
Open

        $content = Phake::mock('OpenOrchestra\ModelInterface\Model\ContentInterface');

Call to method when from undeclared class \Phake
Open

        Phake::when($this->status)->isPublishedState()->thenReturn($publishedState);

Call to method when from undeclared class \Phake
Open

        Phake::when($content)->getAttributes()->thenReturn(array($attribute, $attribute));

Call to method when from undeclared class \Phake
Open

        Phake::when($transformerManager)->getGroupContext()->thenReturn($this->groupContext);

Call to method when from undeclared class \Phake
Open

        Phake::when($groupContext)->hasGroup(Phake::anyParameters())->thenReturn(true);

Call to method when from undeclared class \Phake
Open

        Phake::when($this->authorizationChecker)->isGranted(ContributionActionInterface::EDIT, $this->status)->thenReturn($isGranted);

Call to method when from undeclared class \Phake
Open

        Phake::when($this->translator)->trans(Phake::anyParameters())->thenReturn('trans_display_color');

Call to method getRights from undeclared class \OpenOrchestra\BaseApi\Facade\FacadeInterface
Open

            $this->assertArrayHasKey('can_delete', $facade->getRights());

Call to undeclared method \OpenOrchestra\WorkflowAdminBundle\Tests\Transformer\StatusTransformerTest::isEmpty
Open

            $this->isEmpty($facade->getRights());

Call to undeclared method \OpenOrchestra\WorkflowAdminBundle\Tests\Transformer\StatusTransformerTest::expectException
Open

        $this->expectException('OpenOrchestra\BaseApi\Exceptions\TransformerParameterTypeException');

Call to method mock from undeclared class \Phake
Open

        $multiLanguagesChoiceManager = Phake::mock('OpenOrchestra\ModelInterface\Manager\MultiLanguagesChoiceManagerInterface');

Call to method mock from undeclared class \Phake
Open

        $this->status = Phake::mock('OpenOrchestra\ModelInterface\Model\StatusInterface');

Call to method when from undeclared class \Phake
Open

        Phake::when($this->status)->getId()->thenReturn($statusId);

Call to method when from undeclared class \Phake
Open

        Phake::when($this->usageFinder)->hasUsage(Phake::anyParameters())->thenReturn(false);

Call to method when from undeclared class \Phake
Open

        Phake::when($this->status)->getDisplayColor()->thenReturn('display_color');

Call to method when from undeclared class \Phake
Open

        Phake::when($this->status)->isInitialState()->thenReturn($initialState);

Possibly zero references to use statement for classlike/namespace StatusInterface (\OpenOrchestra\ModelInterface\Model\StatusInterface)
Open

use OpenOrchestra\ModelInterface\Model\StatusInterface;

Call to method mock from undeclared class \Phake
Open

        $this->translator = Phake::mock('Symfony\Component\Translation\TranslatorInterface');

Call to method mock from undeclared class \Phake
Open

        $groupContext = Phake::mock('OpenOrchestra\BaseApi\Context\GroupContext');

Call to method getRights from undeclared class \OpenOrchestra\BaseApi\Facade\FacadeInterface
Open

            $this->isEmpty($facade->getRights());

Call to undeclared method \OpenOrchestra\WorkflowAdminBundle\Tests\Transformer\StatusTransformerTest::assertSame
Open

            $this->assertSame(null, $status);

Call to undeclared method \OpenOrchestra\WorkflowAdminBundle\Tests\Transformer\StatusTransformerTest::assertSame
Open

        $this->assertSame('status', $this->transformer->getName());

Call to undeclared method \OpenOrchestra\WorkflowAdminBundle\Transformer\StatusTransformer::setContext
Open

        $this->transformer->setContext($transformerManager);

Reference to instance property initialState from undeclared class \OpenOrchestra\BaseApi\Facade\FacadeInterface
Open

        $this->assertSame($initialState, $facade->initialState);

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

class StatusTransformerTest extends AbstractBaseTestCase

Call to method anyParameters from undeclared class \Phake
Open

        Phake::when($this->translator)->trans(Phake::anyParameters())->thenReturn('trans_display_color');

Call to method mock from undeclared class \Phake
Open

        $facade = Phake::mock('OpenOrchestra\BaseApi\Facade\FacadeInterface');

Call to method anyParameters from undeclared class \Phake
Open

        Phake::when($this->usageFinder)->hasUsage(Phake::anyParameters())->thenReturn(false);

Call to method anyParameters from undeclared class \Phake
Open

        Phake::when($this->groupContext)->hasGroup(Phake::anyParameters())->thenReturn($hasGroup);

Call to undeclared method \OpenOrchestra\WorkflowAdminBundle\Tests\Transformer\StatusTransformerTest::assertInstanceOf
Open

        $this->assertInstanceOf('OpenOrchestra\BaseApi\Facade\FacadeInterface', $facade);

Call to undeclared method \OpenOrchestra\WorkflowAdminBundle\Tests\Transformer\StatusTransformerTest::assertSame
Open

        $this->assertSame($publishedState, $facade->publishedState);

Call to undeclared method \OpenOrchestra\WorkflowAdminBundle\Tests\Transformer\StatusTransformerTest::assertSame
Open

            $this->assertSame($this->status, $status);

Call to method mock from undeclared class \Phake
Open

        $transformerManager = Phake::mock('OpenOrchestra\BaseApi\Transformer\TransformerManager');

Call to method when from undeclared class \Phake
Open

        Phake::when($router)->generateRoute(Phake::anyParameters())->thenReturn('route');

Call to method anyParameters from undeclared class \Phake
Open

        Phake::when($this->statusRepository)->find(Phake::anyParameters())->thenReturn($this->status);

Call to method when from undeclared class \Phake
Open

        Phake::when($transformerManager)->getGroupContext()->thenReturn($groupContext);

Call to method mock from undeclared class \Phake
Open

        $attribute = Phake::mock('OpenOrchestra\ModelInterface\Model\ContentAttributeInterface');

Call to method when from undeclared class \Phake
Open

        Phake::when($this->groupContext)->hasGroup(Phake::anyParameters())->thenReturn($hasGroup);

Call to method mock from undeclared class \Phake
Open

        $this->groupContext = Phake::mock('OpenOrchestra\BaseApi\Context\GroupContext');

Call to method anyParameters from undeclared class \Phake
Open

        Phake::when($router)->generateRoute(Phake::anyParameters())->thenReturn('route');

Call to method when from undeclared class \Phake
Open

        Phake::when($this->statusRepository)->find(Phake::anyParameters())->thenReturn($this->status);

Call to method mock from undeclared class \Phake
Open

        $this->usageFinder = Phake::mock('OpenOrchestra\Backoffice\UsageFinder\StatusUsageFinder');

Call to method when from undeclared class \Phake
Open

        Phake::when($this->status)->getLabels()->thenReturn(array());

Call to undeclared method \OpenOrchestra\WorkflowAdminBundle\Tests\Transformer\StatusTransformerTest::assertSame
Open

        $this->assertSame($initialState, $facade->initialState);

Call to method mock from undeclared class \Phake
Open

        $this->transformer->transform(Phake::mock('stdClass'));

Call to method when from undeclared class \Phake
Open

        Phake::when($transformerManager)->getRouter()->thenReturn($router);

Reference to instance property publishedState from undeclared class \OpenOrchestra\BaseApi\Facade\FacadeInterface
Open

        $this->assertSame($publishedState, $facade->publishedState);

Call to undeclared method \OpenOrchestra\WorkflowAdminBundle\Tests\Transformer\StatusTransformerTest::assertArrayHasKey
Open

            $this->assertArrayHasKey('can_delete', $facade->getRights());

Call to method mock from undeclared class \Phake
Open

        $this->authorizationChecker = Phake::mock('Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface');

Call to method anyParameters from undeclared class \Phake
Open

        Phake::when($groupContext)->hasGroup(Phake::anyParameters())->thenReturn(true);

Call to method when from undeclared class \Phake
Open

        Phake::when($this->authorizationChecker)->isGranted(ContributionActionInterface::DELETE, $this->status)->thenReturn($isGranted);

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

        $multiLanguagesChoiceManager = Phake::mock('OpenOrchestra\ModelInterface\Manager\MultiLanguagesChoiceManagerInterface');

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

Avoid variables with short names like $id. Configured minimum length is 3.
Open

    public function testReverseTransform($id)

ShortVariable

Since: 0.2

Detects when a field, local, or parameter has a very short name.

Example

class Something {
    private $q = 15; // VIOLATION - Field
    public static function main( array $as ) { // VIOLATION - Formal
        $r = 20 + $this->q; // VIOLATION - Local
        for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
            $r += $this->q;
        }
    }
}

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

Line exceeds 120 characters; contains 129 characters
Open

        $this->authorizationChecker = Phake::mock('Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface');

Line exceeds 120 characters; contains 136 characters
Open

        Phake::when($this->authorizationChecker)->isGranted(ContributionActionInterface::DELETE, $this->status)->thenReturn($isGranted);

Line exceeds 120 characters; contains 128 characters
Open

        $multiLanguagesChoiceManager = Phake::mock('OpenOrchestra\ModelInterface\Manager\MultiLanguagesChoiceManagerInterface');

Line exceeds 120 characters; contains 134 characters
Open

        Phake::when($this->authorizationChecker)->isGranted(ContributionActionInterface::EDIT, $this->status)->thenReturn($isGranted);

There are no issues that match your filters.

Category
Status