open-orchestra/open-orchestra-cms-bundle

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

Summary

Maintainability
C
1 day
Test Coverage

The class AutoPublishManagerTest has 20 fields. Consider redesigning AutoPublishManagerTest to keep the number of fields under 15.
Open

class AutoPublishManagerTest extends AbstractBaseTestCase
{
    protected $managerNode;
    protected $managerContent;
    protected $statusRepository;

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 setUp has 32 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function setUp()
    {
        $this->site = Phake::mock('OpenOrchestra\ModelInterface\Model\ReadSiteInterface');
        Phake::when($this->site)->getSiteId()->thenReturn($this->siteId);

Severity: Minor
Found in Backoffice/Tests/Manager/AutoPublishManagerTest.php - About 1 hr to fix

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

        $this->fromStatus1 = 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->content1 = 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 '__construct'.
Open

        $this->unpublishedStatus = 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->site = Phake::mock('OpenOrchestra\ModelInterface\Model\ReadSiteInterface');

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

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

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->contentRepository)->findElementToAutoUnpublish(Phake::anyParameters())

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

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

        Phake::verify($this->objectManager, Phake::times(2 * $mustFlush))->flush();

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

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

        Phake::when($this->nodeRepository)->findElementToAutoPublish(Phake::anyParameters())

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

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

        $this->fromStatus2 = 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->objectManager = Phake::mock(ObjectManager::CLASS);

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

        Phake::verify($this->objectManager, Phake::times(2 * $mustFlush))->flush();

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->content2 = 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($this->nodeRepository)->findElementToAutoUnpublish(Phake::anyParameters())

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

        Phake::when($this->contentRepository)->findElementToAutoPublish(Phake::anyParameters())

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

        Phake::when($this->content1)->getLanguage()->thenReturn($this->content1Attributes['language']);

Call to method when from undeclared class \Phake
Open

        Phake::when($this->nodeRepository)->findElementToAutoPublish(Phake::anyParameters())

Call to method when from undeclared class \Phake
Open

        Phake::when($this->statusRepository)->findOneByAutoUnpublishTo()->thenReturn($unpublishedStatus);

Call to method verify from undeclared class \Phake
Open

        Phake::verify($this->objectManager, Phake::times(2 * $mustFlush))->flush();

Call to method when from undeclared class \Phake
Open

        Phake::when($this->contentRepository)->findElementToAutoPublish(Phake::anyParameters())

Call to method when from undeclared class \Phake
Open

        Phake::when($this->contentRepository)->findElementToAutoUnpublish(Phake::anyParameters())

Call to method when from undeclared class \Phake
Open

        Phake::when($this->node1)->getName()->thenReturn($this->node1Attributes['name']);

Call to method mock from undeclared class \Phake
Open

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

Call to method when from undeclared class \Phake
Open

        Phake::when($this->node2)->getLanguage()->thenReturn($this->node2Attributes['language']);

Call to method mock from undeclared class \Phake
Open

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

Call to method anyParameters from undeclared class \Phake
Open

        Phake::when($this->contentRepository)->findElementToAutoPublish(Phake::anyParameters())

Call to method mock from undeclared class \Phake
Open

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

Call to method mock from undeclared class \Phake
Open

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

Call to method when from undeclared class \Phake
Open

        Phake::when($this->content2)->getVersion()->thenReturn($this->content2Attributes['version']);

Call to method when from undeclared class \Phake
Open

        Phake::when($this->statusRepository)->findByAutoPublishFrom()->thenReturn($fromStatus);

Call to method when from undeclared class \Phake
Open

        Phake::when($this->statusRepository)->findOneByPublished()->thenReturn($publishedStatus);

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

        $this->assertSame($returnNode, $expectedReturn);

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

        $this->assertSame($returnContent, $expectedReturn);

Call to method when from undeclared class \Phake
Open

        Phake::when($this->node2)->getName()->thenReturn($this->node2Attributes['name']);

Call to method when from undeclared class \Phake
Open

        Phake::when($this->content1)->getName()->thenReturn($this->content1Attributes['name']);

Call to method times from undeclared class \Phake
Open

        Phake::verify($this->objectManager, Phake::times(2 * $mustFlush))->flush();

Call to method when from undeclared class \Phake
Open

        Phake::when($this->nodeRepository)->findElementToAutoUnpublish(Phake::anyParameters())

Call to method mock from undeclared class \Phake
Open

        $this->objectManager = Phake::mock(ObjectManager::CLASS);

Call to method mock from undeclared class \Phake
Open

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

Call to method mock from undeclared class \Phake
Open

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

Call to method anyParameters from undeclared class \Phake
Open

        Phake::when($this->contentRepository)->findElementToAutoUnpublish(Phake::anyParameters())

Call to method verify from undeclared class \Phake
Open

        Phake::verify($this->objectManager, Phake::times(2 * $mustFlush))->flush();

Reference to undeclared class \OpenOrchestra\BaseBundle\Tests\AbstractTest\AbstractBaseTestCase
Open

        parent::__construct($name, $data, $dataName);

Call to method when from undeclared class \Phake
Open

        Phake::when($this->content2)->getName()->thenReturn($this->content2Attributes['name']);

Call to method anyParameters from undeclared class \Phake
Open

        Phake::when($this->nodeRepository)->findElementToAutoPublish(Phake::anyParameters())

Call to method times from undeclared class \Phake
Open

        Phake::verify($this->objectManager, Phake::times(2 * $mustFlush))->flush();

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

class AutoPublishManagerTest extends AbstractBaseTestCase

Call to method mock from undeclared class \Phake
Open

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

Call to method mock from undeclared class \Phake
Open

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

Call to method mock from undeclared class \Phake
Open

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

Call to method mock from undeclared class \Phake
Open

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

Call to method when from undeclared class \Phake
Open

        Phake::when($this->node1)->getVersion()->thenReturn($this->node1Attributes['version']);

Call to method when from undeclared class \Phake
Open

        Phake::when($this->content1)->getVersion()->thenReturn($this->content1Attributes['version']);

Call to method when from undeclared class \Phake
Open

        Phake::when($this->statusRepository)->findOneByPublished()->thenReturn($publishedStatus);

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

        $this->assertSame($returnContent, $expectedReturn);

Call to method mock from undeclared class \Phake
Open

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

Call to method when from undeclared class \Phake
Open

        Phake::when($this->content2)->getLanguage()->thenReturn($this->content2Attributes['language']);

Call to method anyParameters from undeclared class \Phake
Open

        Phake::when($this->nodeRepository)->findElementToAutoUnpublish(Phake::anyParameters())

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

        $this->assertSame($returnNode, $expectedReturn);

Call to method mock from undeclared class \Phake
Open

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

Call to method when from undeclared class \Phake
Open

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

Reference to constant class from undeclared class \Doctrine\Common\Persistence\ObjectManager
Open

        $this->objectManager = Phake::mock(ObjectManager::CLASS);

Call to method when from undeclared class \Phake
Open

        Phake::when($this->node1)->getLanguage()->thenReturn($this->node1Attributes['language']);

Call to method when from undeclared class \Phake
Open

        Phake::when($this->node2)->getVersion()->thenReturn($this->node2Attributes['version']);

Saw an @param annotation for unpublishedStatus, but it was not found in the param list of function testPublishNodes(array $fromStatus, mixed $publishedStatus, mixed $expectedReturn, int $mustFlush)
Open

     * @param mixed $unpublishedStatus

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

    public function testPublishNodes(array $fromStatus, $publishedStatus, $expectedReturn, $mustFlush)
    {
        Phake::when($this->statusRepository)->findByAutoPublishFrom()->thenReturn($fromStatus);
        Phake::when($this->statusRepository)->findOneByPublished()->thenReturn($publishedStatus);

Severity: Major
Found in Backoffice/Tests/Manager/AutoPublishManagerTest.php and 1 other location - About 3 hrs to fix
Backoffice/Tests/Manager/AutoPublishManagerTest.php on lines 165..176

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 149.

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

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

    public function testUnpublishNodes($publishedStatus, $unpublishedStatus, $expectedReturn, $mustFlush)
    {
        Phake::when($this->statusRepository)->findOneByPublished()->thenReturn($publishedStatus);
        Phake::when($this->statusRepository)->findOneByAutoUnpublishTo()->thenReturn($unpublishedStatus);

Severity: Major
Found in Backoffice/Tests/Manager/AutoPublishManagerTest.php and 1 other location - About 3 hrs to fix
Backoffice/Tests/Manager/AutoPublishManagerTest.php on lines 121..131

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 149.

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

The closing brace for the class must go on the next line after the body
Open

}

Line exceeds 120 characters; contains 122 characters
Open

        $this->managerNode = new AutoPublishManager($this->statusRepository, $this->nodeRepository, $this->objectManager);

Line exceeds 120 characters; contains 128 characters
Open

        $this->managerContent = new AutoPublishManager($this->statusRepository, $this->contentRepository, $this->objectManager);

There are no issues that match your filters.

Category
Status