open-orchestra/open-orchestra-cms-bundle

View on GitHub
Backoffice/EventSubscriber/ContentSearchSubscriber.php

Summary

Maintainability
A
1 hr
Test Coverage

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

    protected function addFormType(FormEvent $event)
    {
        $form = $event->getForm();
        $data = $event->getData();
        $event->setData($data);
Severity: Minor
Found in Backoffice/EventSubscriber/ContentSearchSubscriber.php - About 1 hr to fix

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

    protected function addFormType(FormEvent $event)
    {
        $form = $event->getForm();
        $data = $event->getData();
        $event->setData($data);
Severity: Minor
Found in Backoffice/EventSubscriber/ContentSearchSubscriber.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

The method addFormType() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10.
Open

    protected function addFormType(FormEvent $event)
    {
        $form = $event->getForm();
        $data = $event->getData();
        $event->setData($data);

CyclomaticComplexity

Since: 0.1

Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

Example

// Cyclomatic Complexity = 11
class Foo {
1   public function example() {
2       if ($a == $b) {
3           if ($a1 == $b1) {
                fiddle();
4           } elseif ($a2 == $b2) {
                fiddle();
            } else {
                fiddle();
            }
5       } elseif ($c == $d) {
6           while ($c == $d) {
                fiddle();
            }
7        } elseif ($e == $f) {
8           for ($n = 0; $n < $h; $n++) {
                fiddle();
            }
        } else {
            switch ($z) {
9               case 1:
                    fiddle();
                    break;
10              case 2:
                    fiddle();
                    break;
11              case 3:
                    fiddle();
                    break;
                default:
                    fiddle();
                    break;
            }
        }
    }
}

Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

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

    public function postSetData(FormEvent $event)

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

class ContentSearchSubscriber implements EventSubscriberInterface

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

            FormEvents::POST_SET_DATA => 'postSetData',

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

            FormEvents::PRE_SUBMIT => 'preSubmit',

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

        $data = $event->getData();

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

        $event->setData($data);

Reference to constant CHOICE_AND from undeclared class \OpenOrchestra\ModelInterface\Repository\ReadContentRepositoryInterface
Open

                    array_key_exists('choiceType', $data) && $data['choiceType'] != '' ? $data['choiceType']: ReadContentRepositoryInterface::CHOICE_AND,

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

    public function preSubmit(FormEvent $event)

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

        $form = $event->getForm();

Call to method findOneByContentId from undeclared class \OpenOrchestra\ModelInterface\Repository\ContentRepositoryInterface
Open

        $content = $this->contentRepository->findOneByContentId($contentId);

Call to method findByContentTypeAndCondition from undeclared class \OpenOrchestra\ModelInterface\Repository\ContentRepositoryInterface
Open

            $contents = $this->contentRepository->findByContentTypeAndCondition($language, $contentType, $choiceType, $condition, $siteId);

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

    protected function addFormType(FormEvent $event)

Parameter $contentRepository has undeclared type \OpenOrchestra\ModelInterface\Repository\ContentRepositoryInterface
Open

    public function __construct(

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

        $form = $event->getForm();

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

        BooleanConditionValidator $booleanConditionValidator,

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

    protected $booleanConditionValidator;

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 153 characters
Open

                    array_key_exists('choiceType', $data) && $data['choiceType'] != '' ? $data['choiceType']: ReadContentRepositoryInterface::CHOICE_AND,

Line exceeds 120 characters; contains 139 characters
Open

            $contents = $this->contentRepository->findByContentTypeAndCondition($language, $contentType, $choiceType, $condition, $siteId);

Multi-line function call not indented correctly; expected 16 spaces but found 20
Open

                    array_key_exists('keywords', $data) && $data['keywords'] ? $data['keywords']: null));

Opening parenthesis of a multi-line function call must be the last content on the line
Open

                $choices = array_merge($choices, $this->getChoices($data['contentType'],

Closing parenthesis of a multi-line function call must be on a line by itself
Open

                    array_key_exists('keywords', $data) && $data['keywords'] ? $data['keywords']: null));

There are no issues that match your filters.

Category
Status