open-orchestra/open-orchestra-cms-bundle

View on GitHub
Backoffice/EventSubscriber/NodeTemplateSelectionSubscriber.php

Summary

Maintainability
A
1 hr
Test Coverage

Method preSetData has 29 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function preSetData(FormEvent $event)
    {
        $form = $event->getForm();
        $data = $event->getData();
        if (null === $data->getId()) {
Severity: Minor
Found in Backoffice/EventSubscriber/NodeTemplateSelectionSubscriber.php - About 1 hr to fix

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

        } else {
            $form->add('template', 'choice', array(
                'choices' => $this->getTemplateChoices(),
                'required' => true,
                'label' => 'open_orchestra_backoffice.form.node.template',

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

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

class NodeTemplateSelectionSubscriber implements EventSubscriberInterface

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

        $data = $event->getData();

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

            FormEvents::PRE_SET_DATA => 'preSetData'

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

        $form = $event->getForm();

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

        $data = $event->getData();

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

    public function preSubmit(FormEvent $event)

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

            $event->setData($data);

Parameter $siteRepository has undeclared type \OpenOrchestra\ModelInterface\Repository\SiteRepositoryInterface
Open

    public function __construct(

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

            FormEvents::PRE_SUBMIT => 'preSubmit',

Call to method findOneBySiteId from undeclared class \OpenOrchestra\ModelInterface\Repository\SiteRepositoryInterface
Open

        $site = $this->siteRepository->findOneBySiteId($siteId);

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

        $form = $event->getForm();

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

    public function preSetData(FormEvent $event)

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

        $templateSetParameters = $this->templateManager->getTemplateSetParameters();

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 0 spaces after opening bracket; newline found
Open

        if (

There are no issues that match your filters.

Category
Status