open-orchestra/open-orchestra-cms-bundle

View on GitHub
Backoffice/EventSubscriber/SortableCollectionSubscriber.php

Summary

Maintainability
A
1 hr
Test Coverage

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

    public function preSubmit(FormEvent $event)
    {
        $form = $event->getForm();
        $data = $form->getData();

Severity: Minor
Found in Backoffice/EventSubscriber/SortableCollectionSubscriber.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

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

        if (is_array($event->getData())) {

Method \OpenOrchestra\Backoffice\EventSubscriber\SortableCollectionSubscriber::preSubmit is declared to return \Symfony\Component\Form\FormInterface but has no return value
Open

    public function preSubmit(FormEvent $event)

Return type of preSubmit() is undeclared type \Symfony\Component\Form\FormInterface
Open

    public function preSubmit(FormEvent $event)

Call to method clear from undeclared class \Doctrine\Common\Collections\Collection
Open

                $data->clear();

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

        $form = $event->getForm();

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

class SortableCollectionSubscriber implements EventSubscriberInterface

Checking instanceof against undeclared class \Doctrine\Common\Collections\Collection
Open

            if ($data instanceof Collection) {

Call to method toArray from undeclared class \Doctrine\Common\Collections\Collection
Open

                $dataClone = $data->toArray();

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

            $order = array_flip(array_keys($event->getData()));

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)

Call to method set from undeclared class \Doctrine\Common\Collections\Collection
Open

                    $data->set($key, array_key_exists($key, $dataClone) ? $dataClone[$key] : null);

Blank line found at end of control structure
Open


There are no issues that match your filters.

Category
Status