open-orchestra/open-orchestra-cms-bundle

View on GitHub
Backoffice/Form/Type/Extension/FormTypeGroupExtension.php

Summary

Maintainability
A
55 mins
Test Coverage

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

    public function buildView(FormView $view, FormInterface $form, array $options)
    {
        if ($form->getConfig()->getAttribute('group_enabled')) {
            $view->vars['group'] = array();
            $groupRender = $form->getConfig()->getAttribute('group_render');
Severity: Minor
Found in Backoffice/Form/Type/Extension/FormTypeGroupExtension.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

Avoid unused parameters such as '$options'.
Open

    public function buildView(FormView $view, FormInterface $form, array $options)

UnusedFormalParameter

Since: 0.2

Avoid passing parameters to methods or constructors and then not using those parameters.

Example

class Foo
{
    private function bar($howdy)
    {
        // $howdy is not used
    }
}

Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

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

        $builder->setAttribute('sub_group_id', $options['sub_group_id']);

Reference to instance property vars from undeclared class \Symfony\Component\Form\FormView
Open

            $view->vars['group'] = $this->ksortRecursive($view->vars['group']);

Parameter $form has undeclared type \Symfony\Component\Form\FormInterface
Open

    public function buildView(FormView $view, FormInterface $form, array $options)

Argument 2 (search) is string but \array_key_exists() takes array
Open

        if (array_key_exists($id, $reference)) {

Reference to instance property vars from undeclared class \Symfony\Component\Form\FormView
Open

                if (!array_key_exists($groupKey, $view->vars['group'])) {

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

        $builder->setAttribute('group_id', $options['group_id']);

Call to method getConfig from undeclared class \Symfony\Component\Form\FormInterface
Open

            $groupRender = $form->getConfig()->getAttribute('group_render');

Reference to instance property vars from undeclared class \Symfony\Component\Form\FormView
Open

                array_push($view->vars['group'][$groupKey][$subGroupKey]['children'], $child->getName());

Call to method getConfig from undeclared class \Symfony\Component\Form\FormInterface
Open

        $id = $form->getConfig()->getAttribute($id);

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

    public function buildForm(FormBuilderInterface $builder, array $options)

Parameter $view has undeclared type \Symfony\Component\Form\FormView
Open

    public function buildView(FormView $view, FormInterface $form, array $options)

Call to method getConfig from undeclared class \Symfony\Component\Form\FormInterface
Open

        $view->vars['group_enabled'] = $form->getConfig()->getAttribute('group_enabled');

Parameter $form has undeclared type \Symfony\Component\Form\FormInterface
Open

    protected function generateKeyLabel(FormInterface $form, $id, $default, $reference)

When fetching an array index from a value of type string, found an array index of type 'label', but expected the index to be of type int
Open

            $label = array_key_exists('label', $reference[$id]) ? $reference[$id]['label'] : $id;

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

        $builder->setAttribute('group_render', $options['group_render']);

Reference to instance property vars from undeclared class \Symfony\Component\Form\FormView
Open

                if (!array_key_exists($subGroupKey, $view->vars['group'][$groupKey])) {

Reference to instance property vars from undeclared class \Symfony\Component\Form\FormView
Open

        $view->vars['group_enabled'] = $form->getConfig()->getAttribute('group_enabled');

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

        $builder->setAttribute('group_enabled', $options['group_enabled']);

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

        $builder->setAttribute('sub_group_render', $options['sub_group_render']);

Call to method all from undeclared class \Symfony\Component\Form\FormInterface
Open

            foreach ($form->all() as $child) {

Argument 2 (search) is string but \array_key_exists() takes array
Open

            $label = array_key_exists('label', $reference[$id]) ? $reference[$id]['label'] : $id;

Call to method getConfig from undeclared class \Symfony\Component\Form\FormInterface
Open

            $subGroupRender = $form->getConfig()->getAttribute('sub_group_render');

Reference to instance property vars from undeclared class \Symfony\Component\Form\FormView
Open

                    $view->vars['group'][$groupKey] = array();

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

        $resolver->setDefaults(array(

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

class FormTypeGroupExtension extends AbstractTypeExtension

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

    public function configureOptions(OptionsResolver $resolver)

Argument 2 (search) is string but \array_key_exists() takes array
Open

            $key = array_key_exists('rank', $reference[$id]) ? $reference[$id]['rank'] : $id;

When fetching an array index from a value of type string, found an array index of type 'rank', but expected the index to be of type int
Open

            $key = array_key_exists('rank', $reference[$id]) ? $reference[$id]['rank'] : $id;

Call to method getConfig from undeclared class \Symfony\Component\Form\FormInterface
Open

        if ($form->getConfig()->getAttribute('group_enabled')) {

Reference to instance property vars from undeclared class \Symfony\Component\Form\FormView
Open

                    $view->vars['group'][$groupKey][$subGroupKey] = array(

Reference to instance property vars from undeclared class \Symfony\Component\Form\FormView
Open

            $view->vars['group'] = array();

Avoid variables with short names like $id. Configured minimum length is 3.
Open

    protected function generateKeyLabel(FormInterface $form, $id, $default, $reference)

ShortVariable

Since: 0.2

Detects when a field, local, or parameter has a very short name.

Example

class Something {
    private $q = 15; // VIOLATION - Field
    public static function main( array $as ) { // VIOLATION - Formal
        $r = 20 + $this->q; // VIOLATION - Local
        for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
            $r += $this->q;
        }
    }
}

Source https://phpmd.org/rules/naming.html#shortvariable

PHP keywords must be lowercase; expected "const" but found "CONST"
Open

    CONST DEFAULT_GROUP = '_default_group';

PHP keywords must be lowercase; expected "const" but found "CONST"
Open

    CONST DEFAULT_SUB_GROUP = '_default_sub_group';

Line exceeds 120 characters; contains 143 characters
Open

                list($subGroupKey, $subGroupLabel) = $this->generateKeyLabel($child, 'sub_group_id', self::DEFAULT_SUB_GROUP, $subGroupRender);

Line exceeds 120 characters; contains 139 characters
Open

                list($groupKey, $groupLabel, $group_name) = $this->generateKeyLabel($child, 'group_id', self::DEFAULT_GROUP, $groupRender);

Line indented incorrectly; expected 12 spaces, found 11
Open

           if (is_array($value)) {

Line indented incorrectly; expected at least 8 spaces, found 7
Open

       ksort($array, SORT_NATURAL);

Line indented incorrectly; expected 8 spaces, found 7
Open

       foreach ($array as &$value) {

Line indented incorrectly; expected at least 16 spaces, found 15
Open

               $this->ksortRecursive($value);

Line indented incorrectly; expected 12 spaces, found 11
Open

           }

Line indented incorrectly; expected 8 spaces, found 7
Open

       }

Line indented incorrectly; expected at least 8 spaces, found 7
Open

       return $array;

The variable $group_name is not named in camelCase.
Open

    public function buildView(FormView $view, FormInterface $form, array $options)
    {
        if ($form->getConfig()->getAttribute('group_enabled')) {
            $view->vars['group'] = array();
            $groupRender = $form->getConfig()->getAttribute('group_render');

CamelCaseVariableName

Since: 0.2

It is considered best practice to use the camelCase notation to name variables.

Example

class ClassName {
    public function doSomething() {
        $data_module = new DataModule();
    }
}

Source

The variable $group_name is not named in camelCase.
Open

    public function buildView(FormView $view, FormInterface $form, array $options)
    {
        if ($form->getConfig()->getAttribute('group_enabled')) {
            $view->vars['group'] = array();
            $groupRender = $form->getConfig()->getAttribute('group_render');

CamelCaseVariableName

Since: 0.2

It is considered best practice to use the camelCase notation to name variables.

Example

class ClassName {
    public function doSomething() {
        $data_module = new DataModule();
    }
}

Source

There are no issues that match your filters.

Category
Status