open-orchestra/open-orchestra-cms-bundle

View on GitHub
UserAdminBundle/EventSubscriber/UserProfilSubscriber.php

Summary

Maintainability
A
2 hrs
Test Coverage

Function preSubmit has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

    public function preSubmit(FormEvent $event)
    {
        $data = $event->getData();
        $user = $event->getForm()->getData();
        if ($user instanceof UserInterface) {
Severity: Minor
Found in UserAdminBundle/EventSubscriber/UserProfilSubscriber.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

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

    public function preSetData(FormEvent $event)
    {
        $form = $event->getForm();
        $user = $event->getData();

Severity: Minor
Found in UserAdminBundle/EventSubscriber/UserProfilSubscriber.php - About 1 hr to fix

The method preSubmit uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

                } else {
                    $user->removeRole(ContributionRoleInterface::DEVELOPER);
                }

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

The method preSubmit uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

                } else {
                    $user->removeRole(ContributionRoleInterface::PLATFORM_ADMIN);
                }

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

Checking instanceof against undeclared class \OpenOrchestra\UserBundle\Model\UserInterface
Open

        if ($user instanceof UserInterface) {

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

                    $user->removeRole(ContributionRoleInterface::DEVELOPER);

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

                    $user->addRole(ContributionRoleInterface::PLATFORM_ADMIN);

Parameter $authorizationChecker has undeclared type \Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface
Open

    public function __construct(AuthorizationCheckerInterface $authorizationChecker)

Call to method isGranted from undeclared class \Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface
Open

        $this->allowedToSetPlatformAdmin = $authorizationChecker->isGranted(ContributionRoleInterface::PLATFORM_ADMIN);

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

                    'data' => $user->hasRole(ContributionRoleInterface::PLATFORM_ADMIN),

Class implements undeclared interface \Symfony\Component\EventDispatcher\EventSubscriberInterface
Open

class UserProfilSubscriber implements EventSubscriberInterface

Parameter $event has undeclared type \Symfony\Component\Form\FormEvent
Open

    public function preSetData(FormEvent $event)

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

                    $user->addRole(ContributionRoleInterface::DEVELOPER);

Reference to constant PRE_SET_DATA from undeclared class \Symfony\Component\Form\FormEvents
Open

            FormEvents::PRE_SET_DATA => 'preSetData',

Call to method getData from undeclared class \Symfony\Component\Form\FormEvent
Open

        $data = $event->getData();

Call to method getData from undeclared class \Symfony\Component\Form\FormEvent
Open

        $user = $event->getData();

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

                    'data' => $user->hasRole(ContributionRoleInterface::DEVELOPER),

Call to method isGranted from undeclared class \Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface
Open

        $this->allowedToSetDeveloper = $authorizationChecker->isGranted(ContributionRoleInterface::DEVELOPER);

Checking instanceof against undeclared class \OpenOrchestra\UserBundle\Model\UserInterface
Open

        if ($user instanceof UserInterface) {

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

                    $user->removeRole(ContributionRoleInterface::PLATFORM_ADMIN);

Call to method getForm from undeclared class \Symfony\Component\Form\FormEvent
Open

        $user = $event->getForm()->getData();

Call to method getForm from undeclared class \Symfony\Component\Form\FormEvent
Open

        $form = $event->getForm();

Reference to constant PRE_SUBMIT from undeclared class \Symfony\Component\Form\FormEvents
Open

            FormEvents::PRE_SUBMIT => 'preSubmit',

Parameter $event has undeclared type \Symfony\Component\Form\FormEvent
Open

    public function preSubmit(FormEvent $event)

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

    protected $allowedToSetPlatformAdmin;

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 $allowedToSetDeveloper. Keep variable name length under 20.
Open

    protected $allowedToSetDeveloper;

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

Closing brace indented incorrectly; expected 11 spaces, found 12
Open

            }

Line indented incorrectly; expected 20 spaces, found 16
Open

                }

Line indented incorrectly; expected 12 spaces, found 11
Open

           if ($this->allowedToSetPlatformAdmin) {

There are no issues that match your filters.

Category
Status