open-orchestra/open-orchestra-cms-bundle

View on GitHub
Workflow/Security/Authorization/Voter/AbstractWorkflowVoter.php

Summary

Maintainability
A
1 hr
Test Coverage

Function userCanUpdateToStatus has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    protected function userCanUpdateToStatus(UserInterface $user, StatusInterface $status, $subject)
    {
        /** @var GroupInterface $group */
        foreach ($user->getGroups() as $group) {
            $entityType = $this->getSubjectEntityType($subject);
Severity: Minor
Found in Workflow/Security/Authorization/Voter/AbstractWorkflowVoter.php - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Parameter $subject has undeclared type \OpenOrchestra\ModelInterface\Model\StatusableInterface
Open

    abstract protected function isInPerimeter($subject, UserInterface $user);

Parameter $fromStatus has undeclared type \OpenOrchestra\ModelInterface\Model\StatusInterface
Open

    protected function voteForSuperAdmin(StatusInterface $fromStatus, StatusInterface $toStatus) {

Parameter $subject has undeclared type \OpenOrchestra\ModelInterface\Model\StatusableInterface
Open

    protected function getSubjectEntityType($subject)

Call to undeclared method \OpenOrchestra\Workflow\Security\Authorization\Voter\AbstractWorkflowVoter::getSupportedClasses
Open

        foreach ($this->getSupportedClasses() as $supportedClass) {

Parameter $subject has undeclared type \OpenOrchestra\ModelInterface\Model\StatusableInterface
Open

    protected function userCanUpdateToStatus(UserInterface $user, StatusInterface $status, $subject)

Checking instanceof against undeclared class \OpenOrchestra\ModelInterface\Model\StatusableInterface
Open

            if ($subject instanceof StatusableInterface && $subject instanceof $supportedClass) {

Expected @param annotation for decisionManager to be before the @param annotation for perimeterManager
Open

     * @param PerimeterManager                   $perimeterManager

Call to method hasTransition from undeclared class \OpenOrchestra\ModelInterface\Repository\WorkflowProfileRepositoryInterface
Open

        return $this->workflowRepository->hasTransition($fromStatus, $toStatus);

Parameter $user has undeclared type \OpenOrchestra\UserBundle\Model\UserInterface
Open

    protected function userCanUpdateToStatus(UserInterface $user, StatusInterface $status, $subject)

Parameter $decisionManager has undeclared type \Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface
Open

    public function __construct(

Argument 2 (toStatus) is string but \OpenOrchestra\Workflow\Security\Authorization\Voter\AbstractWorkflowVoter::voteForSuperAdmin() takes \OpenOrchestra\ModelInterface\Model\StatusInterface defined at /code/Workflow/Security/Authorization/Voter/AbstractWorkflowVoter.php:119
Open

            return $this->voteForSuperAdmin($subject->getStatus(), $attribute);

Argument 2 (status) is string but \OpenOrchestra\Workflow\Security\Authorization\Voter\AbstractWorkflowVoter::userCanUpdateToStatus() takes \OpenOrchestra\ModelInterface\Model\StatusInterface defined at /code/Workflow/Security/Authorization/Voter/AbstractWorkflowVoter.php:142
Open

        return $this->userCanUpdateToStatus($user, $attribute, $subject);

Reference to constant ENTITY_TYPE from undeclared class \OpenOrchestra\ModelInterface\Model\StatusableInterface
Open

        return $subject::ENTITY_TYPE;

Parameter $status has undeclared type \OpenOrchestra\ModelInterface\Model\StatusInterface
Open

    protected function userCanUpdateToStatus(UserInterface $user, StatusInterface $status, $subject)

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

                    if ($profile->hasTransition($subject->getStatus(), $status)) {

Parameter $user has undeclared type \OpenOrchestra\UserBundle\Model\UserInterface
Open

    abstract protected function isInPerimeter($subject, UserInterface $user);

Parameter $toStatus has undeclared type \OpenOrchestra\ModelInterface\Model\StatusInterface
Open

    protected function voteForSuperAdmin(StatusInterface $fromStatus, StatusInterface $toStatus) {

Call to method getUser from undeclared class \Symfony\Component\Security\Core\Authentication\Token\TokenInterface
Open

        $user = $token->getUser();

Saw possibly unextractable annotation for a fragment of comment '* @param StatusInterface StatusInterface $toStatus': after StatusInterface, did not see an element name (will guess based on comment order)
Open

     * @param StatusInterface StatusInterface $toStatus

Call to method getGroups from undeclared class \OpenOrchestra\UserBundle\Model\UserInterface
Open

        foreach ($user->getGroups() as $group) {

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

use OpenOrchestra\Backoffice\Model\GroupInterface;

Parameter $workflowRepository has undeclared type \OpenOrchestra\ModelInterface\Repository\WorkflowProfileRepositoryInterface
Open

    public function __construct(

Parameter $token has undeclared type \Symfony\Component\Security\Core\Authentication\Token\TokenInterface
Open

    protected function voteOnAttribute($attribute, $subject, TokenInterface $token)

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

        foreach ($this->getSupportedAttributes() as $supportedAttributeClass) {

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

Blank line found at start of control structure
Open

                    if ($profile->hasTransition($subject->getStatus(), $status)) {

Opening brace should be on a new line
Open

    protected function voteForSuperAdmin(StatusInterface $fromStatus, StatusInterface $toStatus) {

No space found after comma in function call
Open

        parent::__construct($decisionManager,$perimeterManager);

There are no issues that match your filters.

Category
Status