open-orchestra/open-orchestra-cms-bundle

View on GitHub
Backoffice/Form/Type/FieldTypeType.php

Summary

Maintainability
B
6 hrs
Test Coverage

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

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        if (array_key_exists('property_path', $options) && is_null($options['property_path'])){
            $builder->setData($options['prototype_data']());
        }
Severity: Major
Found in Backoffice/Form/Type/FieldTypeType.php - About 2 hrs to fix

Method __construct has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

        ContextBackOfficeInterface $contextManager,
        EventSubscriberInterface $fieldTypeTypeSubscriber,
        array $backOfficeLanguages,
        array $fieldTypeParameters,
        $fieldTypeClass
Severity: Minor
Found in Backoffice/Form/Type/FieldTypeType.php - About 35 mins to fix

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

    public function buildView(FormView $view, FormInterface $form, array $options)
    {
        $data = $view->vars['columns']['labels']['data'];

        $language = $this->contextManager->getBackOfficeLanguage();
Severity: Minor
Found in Backoffice/Form/Type/FieldTypeType.php - About 35 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

Avoid unused parameters such as '$form'.
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

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

        if (array_key_exists('options', $view->vars['columns'])) {
Severity: Minor
Found in Backoffice/Form/Type/FieldTypeType.php by phan

Invalid offset "key" of array type array{0:int|string,1:mixed}|false
Open

                $fieldType->setType($default['key']);
Severity: Minor
Found in Backoffice/Form/Type/FieldTypeType.php by phan

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

        $data = $view->vars['columns']['type']['data'];
Severity: Minor
Found in Backoffice/Form/Type/FieldTypeType.php by phan

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

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

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

    public function buildView(FormView $view, FormInterface $form, array $options)
Severity: Minor
Found in Backoffice/Form/Type/FieldTypeType.php by phan

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

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

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

        $view->vars['columns']['labels']['data'] = (is_array($data) && array_key_exists($language, $data)) ? $data[$language] : '';
Severity: Minor
Found in Backoffice/Form/Type/FieldTypeType.php by phan

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

        $view->vars['columns']['options'] = array(
Severity: Minor
Found in Backoffice/Form/Type/FieldTypeType.php by phan

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

            $builder->setData($options['prototype_data']());
Severity: Critical
Found in Backoffice/Form/Type/FieldTypeType.php by phan

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

class FieldTypeType extends AbstractType
Severity: Critical
Found in Backoffice/Form/Type/FieldTypeType.php by phan

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

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

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

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

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

        $builder
Severity: Critical
Found in Backoffice/Form/Type/FieldTypeType.php by phan

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

        $view->vars['columns']['type']['data'] = (array_key_exists($data, $types)) ? $types[$data] : '';
Severity: Minor
Found in Backoffice/Form/Type/FieldTypeType.php by phan

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

        $builder->addEventSubscriber($this->fieldTypeTypeSubscriber);
Severity: Critical
Found in Backoffice/Form/Type/FieldTypeType.php by phan

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

        $data = $view->vars['columns']['labels']['data'];
Severity: Minor
Found in Backoffice/Form/Type/FieldTypeType.php by phan

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

            foreach ($view->vars['columns']['options']['data'] as $data) {
Severity: Minor
Found in Backoffice/Form/Type/FieldTypeType.php by phan

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

    public function buildView(FormView $view, FormInterface $form, array $options)
Severity: Minor
Found in Backoffice/Form/Type/FieldTypeType.php by phan

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

        $resolver->setDefaults(array(
            'data_class' => $this->fieldTypeClass,
            'attr' => array('class' => 'form-to-patch'),
            'group_enabled' => true,
            'sub_group_render' => array(
Severity: Major
Found in Backoffice/Form/Type/FieldTypeType.php and 1 other location - About 3 hrs to fix
Backoffice/Tests/Form/Type/FieldTypeTypeTest.php on lines 71..96

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

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

        EventSubscriberInterface $fieldTypeTypeSubscriber,

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

    protected $fieldTypeTypeSubscriber;

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

Expected 1 space after FUNCTION keyword; 0 found
Open

            'prototype_data' => function(){

Expected 1 space before opening brace; found 0
Open

            'prototype_data' => function(){

The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line
Open

    {

Line exceeds 120 characters; contains 131 characters
Open

        $view->vars['columns']['labels']['data'] = (is_array($data) && array_key_exists($language, $data)) ? $data[$language] : '';

Line exceeds 120 characters; contains 140 characters
Open

                    $value = $data->getValue() ? 'open_orchestra_backoffice.form.swchoff.on' : 'open_orchestra_backoffice.form.swchoff.off';

Line indented incorrectly; expected 16 spaces, found 15
Open

               }

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

       return array(

Expected 1 space after closing parenthesis; found 0
Open

        if (array_key_exists('property_path', $options) && is_null($options['property_path'])){

Closing brace indented incorrectly; expected 16 spaces, found 15
Open

               }

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

       );

There are no issues that match your filters.

Category
Status