open-orchestra/open-orchestra-cms-bundle

View on GitHub
UserAdminBundle/Form/Type/UserType.php

Summary

Maintainability
C
1 day
Test Coverage

Method buildForm has 74 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $sitesId = array();
        $disabled = false;
        if (array_key_exists('data', $options) && ($user = $options['data']) instanceof UserInterface) {
Severity: Major
Found in UserAdminBundle/Form/Type/UserType.php - About 2 hrs to fix

Method configureOptions has 47 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => $this->class,
            'edit_groups' => true,
Severity: Minor
Found in UserAdminBundle/Form/Type/UserType.php - About 1 hr to fix

Function buildForm has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $sitesId = array();
        $disabled = false;
        if (array_key_exists('data', $options) && ($user = $options['data']) instanceof UserInterface) {
Severity: Minor
Found in UserAdminBundle/Form/Type/UserType.php - About 55 mins 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 __construct has 6 arguments (exceeds 4 allowed). Consider refactoring.
Open

        $class,
        array $availableLanguages,
        EventSubscriberInterface $userProfilSubscriber,
        EventSubscriberInterface $userGroupSubscriber,
        TranslatorInterface $translator,
Severity: Minor
Found in UserAdminBundle/Form/Type/UserType.php - About 45 mins to fix

Avoid assigning values to variables in if clauses and the like (line '58', column '52').
Open

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $sitesId = array();
        $disabled = false;
        if (array_key_exists('data', $options) && ($user = $options['data']) instanceof UserInterface) {

IfStatementAssignment

Since: 2.7.0

Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

Example

class Foo
{
    public function bar($flag)
    {
        if ($foo = 'bar') { // possible typo
            // ...
        }
        if ($baz = 0) { // always false
            // ...
        }
    }
}

Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

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

        } else {
            $allowedToSetPlatformAdmin = $this->authorizationChecker->isGranted(ContributionRoleInterface::PLATFORM_ADMIN);
            $allowedToSetDeveloper = $this->authorizationChecker->isGranted(ContributionRoleInterface::DEVELOPER);
            $this
                ->addPlainPasswordField($builder, $options)

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 add from undeclared class \Symfony\Component\Form\FormBuilderInterface
Open

        return $builder->add('plainPassword', 'repeated', array(
Severity: Critical
Found in UserAdminBundle/Form/Type/UserType.php by phan

Parameter $builder has undeclared type \Symfony\Component\Form\FormBuilderInterface
Open

    protected function addPlainPasswordField(FormBuilderInterface $builder, array $options)
Severity: Minor
Found in UserAdminBundle/Form/Type/UserType.php by phan

Call to method add from undeclared class \Symfony\Component\Form\FormBuilderInterface
Open

            $builder
Severity: Critical
Found in UserAdminBundle/Form/Type/UserType.php by phan

Call to method add from undeclared class \Symfony\Component\Form\FormBuilderInterface
Open

        $builder
Severity: Critical
Found in UserAdminBundle/Form/Type/UserType.php by phan

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

            $allowedToSetDeveloper = $this->authorizationChecker->isGranted(ContributionRoleInterface::DEVELOPER);
Severity: Critical
Found in UserAdminBundle/Form/Type/UserType.php by phan

Call to method add from undeclared class \Symfony\Component\Form\FormBuilderInterface
Open

            $this
Severity: Critical
Found in UserAdminBundle/Form/Type/UserType.php by phan

Call to method addEventSubscriber from undeclared class \Symfony\Component\Form\FormBuilderInterface
Open

            $builder->addEventSubscriber($this->userGroupSubscriber);
Severity: Critical
Found in UserAdminBundle/Form/Type/UserType.php by phan

Parameter $resolver has undeclared type \Symfony\Component\OptionsResolver\OptionsResolver
Open

    public function configureOptions(OptionsResolver $resolver)
Severity: Minor
Found in UserAdminBundle/Form/Type/UserType.php by phan

Call to method addEventSubscriber from undeclared class \Symfony\Component\Form\FormBuilderInterface
Open

            $builder->addEventSubscriber($this->userProfileSubscriber);
Severity: Critical
Found in UserAdminBundle/Form/Type/UserType.php by phan

Parameter $builder has undeclared type \Symfony\Component\Form\FormBuilderInterface
Open

    public function buildForm(FormBuilderInterface $builder, array $options)
Severity: Minor
Found in UserAdminBundle/Form/Type/UserType.php by phan

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

            $allowedToSetPlatformAdmin = $this->authorizationChecker->isGranted(ContributionRoleInterface::PLATFORM_ADMIN);
Severity: Critical
Found in UserAdminBundle/Form/Type/UserType.php by phan

Return type of addPlainPasswordField() is undeclared type \Symfony\Component\Form\FormBuilderInterface
Open

    protected function addPlainPasswordField(FormBuilderInterface $builder, array $options)
Severity: Minor
Found in UserAdminBundle/Form/Type/UserType.php by phan

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

        if (array_key_exists('data', $options) && ($user = $options['data']) instanceof UserInterface) {
Severity: Critical
Found in UserAdminBundle/Form/Type/UserType.php by phan

Call to method trans from undeclared class \Symfony\Component\Translation\TranslatorInterface
Open

                            'help_text' => $this->translator->trans('open_orchestra_user.form.registration_user.complex_user_password', array(), 'validators'),
Severity: Critical
Found in UserAdminBundle/Form/Type/UserType.php by phan

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

    public function __construct(
Severity: Minor
Found in UserAdminBundle/Form/Type/UserType.php by phan

Parameter $userGroupSubscriber has undeclared type \Symfony\Component\EventDispatcher\EventSubscriberInterface
Open

    public function __construct(
Severity: Minor
Found in UserAdminBundle/Form/Type/UserType.php by phan

Call to method add from undeclared class \Symfony\Component\Form\FormBuilderInterface
Open

                $builder->add('accountLocked', 'checkbox', array(
Severity: Critical
Found in UserAdminBundle/Form/Type/UserType.php by phan

Call to method setAttribute from undeclared class \Symfony\Component\Form\FormBuilderInterface
Open

            $builder->setAttribute('disabled', $options['disabled']);
Severity: Critical
Found in UserAdminBundle/Form/Type/UserType.php by phan

Class extends undeclared class \Symfony\Component\Form\AbstractType
Open

class UserType extends AbstractType
Severity: Critical
Found in UserAdminBundle/Form/Type/UserType.php by phan

Call to method add from undeclared class \Symfony\Component\Form\FormBuilderInterface
Open

            $this
Severity: Critical
Found in UserAdminBundle/Form/Type/UserType.php by phan

Call to method setDefaults from undeclared class \Symfony\Component\OptionsResolver\OptionsResolver
Open

        $resolver->setDefaults(array(
Severity: Critical
Found in UserAdminBundle/Form/Type/UserType.php by phan

Parameter $translator has undeclared type \Symfony\Component\Translation\TranslatorInterface
Open

    public function __construct(
Severity: Minor
Found in UserAdminBundle/Form/Type/UserType.php by phan

Parameter $userProfilSubscriber has undeclared type \Symfony\Component\EventDispatcher\EventSubscriberInterface
Open

    public function __construct(
Severity: Minor
Found in UserAdminBundle/Form/Type/UserType.php by phan

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

        $resolver->setDefaults(array(
            'data_class' => $this->class,
            'edit_groups' => true,
            'self_editing' => false,
            'group_enabled' => true,
Severity: Major
Found in UserAdminBundle/Form/Type/UserType.php and 1 other location - About 5 hrs to fix
UserAdminBundle/Tests/Form/Type/UserTypeTest.php on lines 87..133

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

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

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

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

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

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

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

    protected $userProfileSubscriber;

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

Line exceeds 120 characters; contains 159 characters
Open

                            'help_text' => $this->translator->trans('open_orchestra_user.form.registration_user.complex_user_password', array(), 'validators'),

Line exceeds 120 characters; contains 123 characters
Open

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

Expected 1 space after FOREACH keyword; 0 found
Open

        foreach($this->availableLanguages as $language) {

Expected 0 spaces before closing bracket; newline found
Open

        return $builder->add('plainPassword', 'repeated', array(

There are no issues that match your filters.

Category
Status