open-orchestra/open-orchestra-cms-bundle

View on GitHub
Workflow/Tests/Security/Authorization/Voter/NodeWorkflowVoterTest.php

Summary

Maintainability
F
1 wk
Test Coverage

Method getNotSupportedSubjects has 26 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    protected function getNotSupportedSubjects()
    {
        $content = $this->createPhakeContent();
        $trashItem = $this->createPhakeTrashItem();
        $site = $this->createPhakeSite();

Method testVote has 6 arguments (exceeds 4 allowed). Consider refactoring.
Open

    public function testVote($object, $attribute, array $roles, $inPerimeter, $expectedVote, $inProfile = true)
Severity: Minor
Found in Workflow/Tests/Security/Authorization/Voter/NodeWorkflowVoterTest.php - About 45 mins to fix

The method testVote has a boolean flag argument $inProfile, which is a certain sign of a Single Responsibility Principle violation.
Open

    public function testVote($object, $attribute, array $roles, $inPerimeter, $expectedVote, $inProfile = true)

BooleanArgumentFlag

Since: 1.4.0

A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

Example

class Foo {
    public function bar($flag = true) {
    }
}

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

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

        $profileCollection = Phake::mock('OpenOrchestra\ModelInterface\Model\WorkflowProfileCollectionInterface');

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

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

        Phake::when($this->workflowRepository)->hasTransition(Phake::anyParameters())->thenReturn($inProfile);

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->group)->getWorkflowProfileCollection(Phake::anyParameters())->thenReturn($profileCollection);

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

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

        Phake::when($this->profile)->hasTransition(Phake::anyParameters())->thenReturn($inProfile);

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($profileCollection)->getProfiles()->thenReturn(array($this->profile));

Reference to constant ACCESS_ABSTAIN from undeclared class \Symfony\Component\Security\Core\Authorization\Voter\VoterInterface
Open

            'Bad subject : Trash Item'       => array($trashItem  , $status, array(ContributionRoleInterface::DEVELOPER), true, VoterInterface::ACCESS_ABSTAIN),

Reference to constant ACCESS_ABSTAIN from undeclared class \Symfony\Component\Security\Core\Authorization\Voter\VoterInterface
Open

            'Bad subject : Group'            => array($group      , $status, array(ContributionRoleInterface::DEVELOPER), true, VoterInterface::ACCESS_ABSTAIN),

Reference to constant ACCESS_ABSTAIN from undeclared class \Symfony\Component\Security\Core\Authorization\Voter\VoterInterface
Open

            'Bad subject : Workflow profile' => array($profile    , $status, array(ContributionRoleInterface::DEVELOPER), true, VoterInterface::ACCESS_ABSTAIN),

Reference to constant ACCESS_ABSTAIN from undeclared class \Symfony\Component\Security\Core\Authorization\Voter\VoterInterface
Open

            'Bad attribute : Trash Restore' => array($node, ContributionActionInterface::TRASH_RESTORE, array(ContributionRoleInterface::DEVELOPER), true, VoterInterface::ACCESS_ABSTAIN),

Reference to constant ACCESS_GRANTED from undeclared class \Symfony\Component\Security\Core\Authorization\Voter\VoterInterface
Open

            'Ok : Contributor' => array($node, $status, array(ContributionRoleInterface::NODE_CONTRIBUTOR), true , VoterInterface::ACCESS_GRANTED, true),

Call to method mock from undeclared class \Phake
Open

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

Call to method when from undeclared class \Phake
Open

        Phake::when($this->workflowRepository)->hasTransition(Phake::anyParameters())->thenReturn($inProfile);

Reference to constant ACCESS_ABSTAIN from undeclared class \Symfony\Component\Security\Core\Authorization\Voter\VoterInterface
Open

            'Bad subject : Api client'       => array($client     , $status, array(ContributionRoleInterface::DEVELOPER), true, VoterInterface::ACCESS_ABSTAIN),

Reference to constant ACCESS_ABSTAIN from undeclared class \Symfony\Component\Security\Core\Authorization\Voter\VoterInterface
Open

            'Bad attribute : Read'          => array($node, ContributionActionInterface::READ         , array(ContributionRoleInterface::DEVELOPER), true, VoterInterface::ACCESS_ABSTAIN),

Reference to constant ACCESS_ABSTAIN from undeclared class \Symfony\Component\Security\Core\Authorization\Voter\VoterInterface
Open

            'Bad attribute : Edit'          => array($node, ContributionActionInterface::EDIT         , array(ContributionRoleInterface::DEVELOPER), true, VoterInterface::ACCESS_ABSTAIN),

Reference to constant ACCESS_DENIED from undeclared class \Symfony\Component\Security\Core\Authorization\Voter\VoterInterface
Open

            'Not in perimeter : Contributor' => array($node, $status, array(ContributionRoleInterface::NODE_CONTRIBUTOR), false, VoterInterface::ACCESS_DENIED, false),

Reference to constant ACCESS_ABSTAIN from undeclared class \Symfony\Component\Security\Core\Authorization\Voter\VoterInterface
Open

            'Bad attribute : Delete'        => array($node, ContributionActionInterface::DELETE       , array(ContributionRoleInterface::DEVELOPER), true, VoterInterface::ACCESS_ABSTAIN),

Call to method when from undeclared class \Phake
Open

        Phake::when($this->group)->getWorkflowProfileCollection(Phake::anyParameters())->thenReturn($profileCollection);

Reference to constant ACCESS_ABSTAIN from undeclared class \Symfony\Component\Security\Core\Authorization\Voter\VoterInterface
Open

            'Bad subject : Site'             => array($site       , $status, array(ContributionRoleInterface::DEVELOPER), true, VoterInterface::ACCESS_ABSTAIN),

Reference to constant ACCESS_ABSTAIN from undeclared class \Symfony\Component\Security\Core\Authorization\Voter\VoterInterface
Open

            'Bad subject : Content type'     => array($contentType, $status, array(ContributionRoleInterface::DEVELOPER), true, VoterInterface::ACCESS_ABSTAIN),

Call to method when from undeclared class \Phake
Open

        Phake::when($this->profile)->hasTransition(Phake::anyParameters())->thenReturn($inProfile);

Call to method anyParameters from undeclared class \Phake
Open

        Phake::when($this->workflowRepository)->hasTransition(Phake::anyParameters())->thenReturn($inProfile);

Reference to constant ACCESS_ABSTAIN from undeclared class \Symfony\Component\Security\Core\Authorization\Voter\VoterInterface
Open

            'Bad subject : Log'              => array($log        , $status, array(ContributionRoleInterface::DEVELOPER), true, VoterInterface::ACCESS_ABSTAIN),

Reference to constant ACCESS_ABSTAIN from undeclared class \Symfony\Component\Security\Core\Authorization\Voter\VoterInterface
Open

            'Bad attribute : Create'        => array($node, ContributionActionInterface::CREATE       , array(ContributionRoleInterface::DEVELOPER), true, VoterInterface::ACCESS_ABSTAIN),

Call to method anyParameters from undeclared class \Phake
Open

        Phake::when($this->profile)->hasTransition(Phake::anyParameters())->thenReturn($inProfile);

Reference to constant ACCESS_ABSTAIN from undeclared class \Symfony\Component\Security\Core\Authorization\Voter\VoterInterface
Open

            'Bad subject : Keyword'          => array($keyword    , $status, array(ContributionRoleInterface::DEVELOPER), true, VoterInterface::ACCESS_ABSTAIN),

Reference to constant ACCESS_GRANTED from undeclared class \Symfony\Component\Security\Core\Authorization\Voter\VoterInterface
Open

            'Ok : Developper'  => array($node, $status, array(ContributionRoleInterface::DEVELOPER)       , false, VoterInterface::ACCESS_GRANTED, true),

Call to method mock from undeclared class \Phake
Open

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

Reference to constant ACCESS_ABSTAIN from undeclared class \Symfony\Component\Security\Core\Authorization\Voter\VoterInterface
Open

            'Bad subject : Content'          => array($content    , $status, array(ContributionRoleInterface::DEVELOPER), true, VoterInterface::ACCESS_ABSTAIN),

Call to method mock from undeclared class \Phake
Open

        $profileCollection = Phake::mock('OpenOrchestra\ModelInterface\Model\WorkflowProfileCollectionInterface');

Call to method anyParameters from undeclared class \Phake
Open

        Phake::when($this->group)->getWorkflowProfileCollection(Phake::anyParameters())->thenReturn($profileCollection);

Reference to constant ACCESS_ABSTAIN from undeclared class \Symfony\Component\Security\Core\Authorization\Voter\VoterInterface
Open

            'Bad subject : User'             => array($user       , $status, array(ContributionRoleInterface::DEVELOPER), true, VoterInterface::ACCESS_ABSTAIN),

Reference to constant ACCESS_ABSTAIN from undeclared class \Symfony\Component\Security\Core\Authorization\Voter\VoterInterface
Open

            'Bad subject : Status'           => array($status     , $status, array(ContributionRoleInterface::DEVELOPER), true, VoterInterface::ACCESS_ABSTAIN),

Reference to constant ACCESS_ABSTAIN from undeclared class \Symfony\Component\Security\Core\Authorization\Voter\VoterInterface
Open

            'Bad attribute : Trash Purge'   => array($node, ContributionActionInterface::TRASH_PURGE  , array(ContributionRoleInterface::DEVELOPER), true, VoterInterface::ACCESS_ABSTAIN),

Call to method when from undeclared class \Phake
Open

        Phake::when($node)->getStatus()->thenReturn($status);

Reference to constant ACCESS_ABSTAIN from undeclared class \Symfony\Component\Security\Core\Authorization\Voter\VoterInterface
Open

            'Bad subject : Redirection'      => array($redirection, $status, array(ContributionRoleInterface::DEVELOPER), true, VoterInterface::ACCESS_ABSTAIN),

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

<?php

namespace OpenOrchestra\Workflow\Tests\Security\Authorization\Voter;

use OpenOrchestra\Backoffice\Security\ContributionActionInterface;
Workflow/Tests/Security/Authorization/Voter/ContentWorkflowVoterTest.php on lines 1..141

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

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

Line exceeds 120 characters; contains 126 characters
Open

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

Line exceeds 120 characters; contains 160 characters
Open

            'Bad subject : Content'          => array($content    , $status, array(ContributionRoleInterface::DEVELOPER), true, VoterInterface::ACCESS_ABSTAIN),

Line exceeds 120 characters; contains 187 characters
Open

            'Bad attribute : Create'        => array($node, ContributionActionInterface::CREATE       , array(ContributionRoleInterface::DEVELOPER), true, VoterInterface::ACCESS_ABSTAIN),

Line exceeds 120 characters; contains 160 characters
Open

            'Bad subject : Trash Item'       => array($trashItem  , $status, array(ContributionRoleInterface::DEVELOPER), true, VoterInterface::ACCESS_ABSTAIN),

Line exceeds 120 characters; contains 160 characters
Open

            'Bad subject : Redirection'      => array($redirection, $status, array(ContributionRoleInterface::DEVELOPER), true, VoterInterface::ACCESS_ABSTAIN),

Line exceeds 120 characters; contains 187 characters
Open

            'Bad attribute : Read'          => array($node, ContributionActionInterface::READ         , array(ContributionRoleInterface::DEVELOPER), true, VoterInterface::ACCESS_ABSTAIN),

Line exceeds 120 characters; contains 187 characters
Open

            'Bad attribute : Trash Purge'   => array($node, ContributionActionInterface::TRASH_PURGE  , array(ContributionRoleInterface::DEVELOPER), true, VoterInterface::ACCESS_ABSTAIN),

Line exceeds 120 characters; contains 160 characters
Open

            'Bad subject : Content type'     => array($contentType, $status, array(ContributionRoleInterface::DEVELOPER), true, VoterInterface::ACCESS_ABSTAIN),

Line exceeds 120 characters; contains 187 characters
Open

            'Bad attribute : Delete'        => array($node, ContributionActionInterface::DELETE       , array(ContributionRoleInterface::DEVELOPER), true, VoterInterface::ACCESS_ABSTAIN),

Line exceeds 120 characters; contains 160 characters
Open

            'Bad subject : User'             => array($user       , $status, array(ContributionRoleInterface::DEVELOPER), true, VoterInterface::ACCESS_ABSTAIN),

Line exceeds 120 characters; contains 153 characters
Open

            'Ok : Developper'  => array($node, $status, array(ContributionRoleInterface::DEVELOPER)       , false, VoterInterface::ACCESS_GRANTED, true),

Line exceeds 120 characters; contains 160 characters
Open

            'Bad subject : Site'             => array($site       , $status, array(ContributionRoleInterface::DEVELOPER), true, VoterInterface::ACCESS_ABSTAIN),

Line exceeds 120 characters; contains 153 characters
Open

            'Ok : Contributor' => array($node, $status, array(ContributionRoleInterface::NODE_CONTRIBUTOR), true , VoterInterface::ACCESS_GRANTED, true),

Line exceeds 120 characters; contains 187 characters
Open

            'Bad attribute : Edit'          => array($node, ContributionActionInterface::EDIT         , array(ContributionRoleInterface::DEVELOPER), true, VoterInterface::ACCESS_ABSTAIN),

Line exceeds 120 characters; contains 167 characters
Open

            'Not in perimeter : Contributor' => array($node, $status, array(ContributionRoleInterface::NODE_CONTRIBUTOR), false, VoterInterface::ACCESS_DENIED, false),

Line exceeds 120 characters; contains 160 characters
Open

            'Bad subject : Api client'       => array($client     , $status, array(ContributionRoleInterface::DEVELOPER), true, VoterInterface::ACCESS_ABSTAIN),

Line exceeds 120 characters; contains 160 characters
Open

            'Bad subject : Workflow profile' => array($profile    , $status, array(ContributionRoleInterface::DEVELOPER), true, VoterInterface::ACCESS_ABSTAIN),

Line exceeds 120 characters; contains 127 characters
Open

        $this->voter = new NodeWorkflowVoter($this->accessDecisionManager, $this->perimeterManager, $this->workflowRepository);

Line exceeds 120 characters; contains 160 characters
Open

            'Bad subject : Log'              => array($log        , $status, array(ContributionRoleInterface::DEVELOPER), true, VoterInterface::ACCESS_ABSTAIN),

Line exceeds 120 characters; contains 160 characters
Open

            'Bad subject : Keyword'          => array($keyword    , $status, array(ContributionRoleInterface::DEVELOPER), true, VoterInterface::ACCESS_ABSTAIN),

Line exceeds 120 characters; contains 187 characters
Open

            'Bad attribute : Trash Restore' => array($node, ContributionActionInterface::TRASH_RESTORE, array(ContributionRoleInterface::DEVELOPER), true, VoterInterface::ACCESS_ABSTAIN),

Line exceeds 120 characters; contains 160 characters
Open

            'Bad subject : Group'            => array($group      , $status, array(ContributionRoleInterface::DEVELOPER), true, VoterInterface::ACCESS_ABSTAIN),

Line exceeds 120 characters; contains 160 characters
Open

            'Bad subject : Status'           => array($status     , $status, array(ContributionRoleInterface::DEVELOPER), true, VoterInterface::ACCESS_ABSTAIN),

There are no issues that match your filters.

Category
Status