open-orchestra/open-orchestra-cms-bundle

View on GitHub
Backoffice/Tests/Manager/ContentManagerTest.php

Summary

Maintainability
A
2 hrs
Test Coverage

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

    public function setUp()
    {
        $this->statusInitial = Phake::mock('OpenOrchestra\ModelInterface\Model\StatusInterface');
        Phake::when($this->statusInitial)->getLabels()->thenReturn(array());
        Phake::when($this->statusInitial)->getName()->thenReturn($this->statusInitialLabel);
Severity: Minor
Found in Backoffice/Tests/Manager/ContentManagerTest.php - About 1 hr to fix

The class ContentManagerTest has 16 fields. Consider redesigning ContentManagerTest to keep the number of fields under 15.
Open

class ContentManagerTest extends AbstractBaseTestCase
{
    /**
     * @var ContentManager
     */

TooManyFields

Since: 0.1

Classes that have too many fields could be redesigned to have fewer fields, possibly through some nested object grouping of some of the information. For example, a class with city/state/zip fields could instead have one Address field.

Example

class Person {
   protected $one;
   private $two;
   private $three;
   [... many more fields ...]
}

Source https://phpmd.org/rules/codesize.html#toomanyfields

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

    public function testInitializeNewContent($contentType, $language, $linkedToSite, $siteId, $isStatusable)
Severity: Minor
Found in Backoffice/Tests/Manager/ContentManagerTest.php - About 35 mins to fix

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

        $this->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

        $tokenStorage = Phake::mock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage');

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->contextManager = Phake::mock('OpenOrchestra\Backoffice\Context\ContextBackOfficeInterface');

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

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->statusTranslationState = 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

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

        $this->statusOutofWorkflow = 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

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

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

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->uniqueIdGenerator = Phake::mock('OpenOrchestra\Backoffice\Util\UniqueIdGenerator');

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->statusInitial = 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

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

        $this->contentAttribute = 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

        $token = Phake::mock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');

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->user = Phake::mock('OpenOrchestra\UserBundle\Model\UserInterface');

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

        } else {
            $this->assertEquals($this->statusOutofWorkflow->isOutOfWorkflow(), true);
        }

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

Call to method when from undeclared class \Phake
Open

        Phake::when($this->statusRepository)->findOneByInitial()->thenReturn($this->statusInitial);

Call to method getLanguage from undeclared class \OpenOrchestra\ModelInterface\Model\ContentInterface
Open

        $this->assertSame($language, $content->getLanguage());

Call to method mock from undeclared class \Phake
Open

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

Call to method when from undeclared class \Phake
Open

        Phake::when($this->uniqueIdGenerator)->generateUniqueId()->thenReturn($this->fakeVersion);

Call to method verify from undeclared class \Phake
Open

        Phake::verify($newContent)->addKeyword($this->keyword);

Call to method when from undeclared class \Phake
Open

        Phake::when($this->statusInitial)->getName()->thenReturn($this->statusInitialLabel);

Call to method when from undeclared class \Phake
Open

        Phake::when($this->statusTranslationState)->getName()->thenReturn($this->statusTranslationStateLabel);

Call to method mock from undeclared class \Phake
Open

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

Call to method when from undeclared class \Phake
Open

        Phake::when($this->content)->getStatus()->thenReturn($this->statusInitial);

Call to method mock from undeclared class \Phake
Open

        $token = Phake::mock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');

Call to method when from undeclared class \Phake
Open

        Phake::when($tokenStorage)->getToken()->thenReturn($token);

Call to method verify from undeclared class \Phake
Open

        Phake::verify($newContent)->addKeyword($this->keyword);

Call to method mock from undeclared class \Phake
Open

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

Call to method verify from undeclared class \Phake
Open

        Phake::verify($newContent)->setContentId($contentId);

Call to undeclared method \OpenOrchestra\Backoffice\Tests\Manager\ContentManagerTest::assertInstanceOf
Open

        $this->assertInstanceOf('OpenOrchestra\ModelInterface\Model\ContentInterface', $content);

Call to method when from undeclared class \Phake
Open

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

Call to method when from undeclared class \Phake
Open

        Phake::when($this->statusTranslationState)->isOutOfWorkflow()->thenReturn(false);

Call to method when from undeclared class \Phake
Open

        Phake::when($this->content)->getAttributes()->thenReturn(array($this->contentAttribute));

Call to method mock from undeclared class \Phake
Open

        $this->uniqueIdGenerator = Phake::mock('OpenOrchestra\Backoffice\Util\UniqueIdGenerator');

Call to method getContentType from undeclared class \OpenOrchestra\ModelInterface\Model\ContentInterface
Open

        $this->assertSame($contentType, $content->getContentType());

Call to method getSiteId from undeclared class \OpenOrchestra\ModelInterface\Model\ContentInterface
Open

        $this->assertSame($siteId, $content->getSiteId());

Call to method getStatus from undeclared class \OpenOrchestra\ModelInterface\Model\ContentInterface
Open

            $this->assertEquals($this->statusInitialLabel, $content->getStatus()->getName());

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

class ContentManagerTest extends AbstractBaseTestCase

Call to method when from undeclared class \Phake
Open

        Phake::when($this->contextManager)->getBackOfficeLanguage()->thenReturn('fakeLanguage');

Call to undeclared method \OpenOrchestra\Backoffice\Tests\Manager\ContentManagerTest::assertSame
Open

        $this->assertSame($contentType, $content->getContentType());

Call to method mock from undeclared class \Phake
Open

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

Call to method mock from undeclared class \Phake
Open

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

Call to method mock from undeclared class \Phake
Open

        $this->user = Phake::mock('OpenOrchestra\UserBundle\Model\UserInterface');

Call to method verify from undeclared class \Phake
Open

        Phake::verify($newContent)->setStatus($this->statusInitial);

Call to method when from undeclared class \Phake
Open

        Phake::when($this->user)->getUsername()->thenReturn($userName);

Call to undeclared method \OpenOrchestra\Backoffice\Tests\Manager\ContentManagerTest::assertSame
Open

        $this->assertSame($siteId, $content->getSiteId());

Call to method verify from undeclared class \Phake
Open

        Phake::verify($newContent)->addAttribute($this->contentAttribute);

Call to method verify from undeclared class \Phake
Open

        Phake::verify($newContent)->setVersion($this->fakeVersion);

Call to method when from undeclared class \Phake
Open

        Phake::when($this->statusInitial)->isOutOfWorkflow()->thenReturn(false);

Call to method mock from undeclared class \Phake
Open

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

Call to method when from undeclared class \Phake
Open

        Phake::when($this->statusRepository)->findOneByTranslationState()->thenReturn($this->statusTranslationState);

Call to method when from undeclared class \Phake
Open

        Phake::when($this->content)->getKeywords()->thenReturn(array($this->keyword));

Call to method when from undeclared class \Phake
Open

        Phake::when($token)->getUser()->thenReturn($this->user);

Call to method getCreatedBy from undeclared class \OpenOrchestra\ModelInterface\Model\ContentInterface
Open

        $this->assertSame($userName, $content->getCreatedBy());

Call to undeclared method \OpenOrchestra\Backoffice\Tests\Manager\ContentManagerTest::assertEquals
Open

            $this->assertEquals($this->statusInitialLabel, $content->getStatus()->getName());

Call to method mock from undeclared class \Phake
Open

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

Call to method mock from undeclared class \Phake
Open

        $tokenStorage = Phake::mock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage');

Call to undeclared method \OpenOrchestra\Backoffice\Tests\Manager\ContentManagerTest::assertSame
Open

        $this->assertSame($linkedToSite, $content->isLinkedToSite());

Call to method when from undeclared class \Phake
Open

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

Argument 2 (versionName) is int but \OpenOrchestra\Backoffice\Manager\ContentManager::newVersionContent() takes string defined at /code/Backoffice/Manager/ContentManager.php:116
Open

        $newContent = $this->manager->newVersionContent($this->content, $versionName);

Call to method when from undeclared class \Phake
Open

        Phake::when($this->contextManager)->getSiteId()->thenReturn($siteId);

Call to method when from undeclared class \Phake
Open

        Phake::when($this->statusRepository)->findOneByOutOfWorkflow()->thenReturn($this->statusOutofWorkflow);

Call to method mock from undeclared class \Phake
Open

        $this->contextManager = Phake::mock('OpenOrchestra\Backoffice\Context\ContextBackOfficeInterface');

Call to method verify from undeclared class \Phake
Open

        Phake::verify($newContent)->setLanguage($language);

Call to method verify from undeclared class \Phake
Open

        Phake::verify($newContent)->setStatus($this->statusInitial);

Call to method isLinkedToSite from undeclared class \OpenOrchestra\ModelInterface\Model\ContentInterface
Open

        $this->assertSame($linkedToSite, $content->isLinkedToSite());

Call to method mock from undeclared class \Phake
Open

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

Call to method when from undeclared class \Phake
Open

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

Call to method when from undeclared class \Phake
Open

        Phake::when($this->statusOutofWorkflow)->isOutOfWorkflow()->thenReturn(true);

Call to method verify from undeclared class \Phake
Open

        Phake::verify($newContent)->setStatus($this->statusTranslationState);

Call to method verify from undeclared class \Phake
Open

        Phake::verify($newContent)->setVersion($this->fakeVersion);

Call to method verify from undeclared class \Phake
Open

        Phake::verify($newContent)->addAttribute($this->contentAttribute);

Call to undeclared method \OpenOrchestra\Backoffice\Tests\Manager\ContentManagerTest::assertSame
Open

        $this->assertSame($language, $content->getLanguage());

Call to undeclared method \OpenOrchestra\Backoffice\Tests\Manager\ContentManagerTest::assertEquals
Open

            $this->assertEquals($this->statusOutofWorkflow->isOutOfWorkflow(), true);

Call to undeclared method \OpenOrchestra\Backoffice\Tests\Manager\ContentManagerTest::assertSame
Open

        $this->assertSame($userName, $content->getCreatedBy());

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

    protected $statusTranslationState;

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 excessively long variable names like $statusTranslationStateLabel. Keep variable name length under 20.
Open

    protected $statusTranslationStateLabel = 'statusTranslationStateLabel';

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

There are no issues that match your filters.

Category
Status