open-orchestra/open-orchestra-cms-bundle

View on GitHub
Backoffice/EventSubscriber/ContentTypeSubscriber.php

Summary

Maintainability
A
1 hr
Test Coverage

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

        ContentTypeRepositoryInterface $contentTypeRepository,
        StatusRepositoryInterface $statusRepository,
        $contentAttributeClass,
        MultiLanguagesChoiceManagerInterface $multiLanguagesChoiceManager,
        $fieldTypesConfiguration,
Severity: Major
Found in Backoffice/EventSubscriber/ContentTypeSubscriber.php - About 1 hr to fix

Function postSetData has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

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

Severity: Minor
Found in Backoffice/EventSubscriber/ContentTypeSubscriber.php - About 25 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

Function postSubmit has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public function postSubmit(FormEvent $event)
    {
        $form = $event->getForm();
        $content = $form->getData();
        $contentType = $this->contentTypeRepository->findOneByContentTypeIdInLastVersion($content->getContentType());
Severity: Minor
Found in Backoffice/EventSubscriber/ContentTypeSubscriber.php - About 25 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 class ContentTypeSubscriber has a coupling between objects value of 18. Consider to reduce the number of dependencies under 13.
Open

class ContentTypeSubscriber implements EventSubscriberInterface
{
    protected $multiLanguagesChoiceManager;
    protected $contentTypeRepository;
    protected $contentAttributeClass;

CouplingBetweenObjects

Since: 1.1.0

A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability

Example

class Foo {
    /**
     * @var \foo\bar\X
     */
    private $x = null;

    /**
     * @var \foo\bar\Y
     */
    private $y = null;

    /**
     * @var \foo\bar\Z
     */
    private $z = null;

    public function setFoo(\Foo $foo) {}
    public function setBar(\Bar $bar) {}
    public function setBaz(\Baz $baz) {}

    /**
     * @return \SplObjectStorage
     * @throws \OutOfRangeException
     * @throws \InvalidArgumentException
     * @throws \ErrorException
     */
    public function process(\Iterator $it) {}

    // ...
}

Source https://phpmd.org/rules/design.html#couplingbetweenobjects

Parameter $translator has undeclared type \Symfony\Component\Translation\TranslatorInterface
Open

    public function __construct(

Call to method trans from undeclared class \Symfony\Component\Translation\TranslatorInterface
Open

                    $message = $this->translator->trans("open_orchestra_backoffice.form.content.transformation_error");

Call to method dispatch from undeclared class \Symfony\Component\EventDispatcher\EventDispatcherInterface
Open

                $this->eventDispatcher->dispatch(StatusEvents::STATUS_CHANGE, $event);

Parameter $multiLanguagesChoiceManager has undeclared type \OpenOrchestra\ModelInterface\Manager\MultiLanguagesChoiceManagerInterface
Open

    public function __construct(

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

            FormEvents::POST_SET_DATA => 'postSetData',

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

            FormEvents::POST_SUBMIT => 'postSubmit',

Call to method findOneByContentTypeIdInLastVersion from undeclared class \OpenOrchestra\ModelInterface\Repository\ContentTypeRepositoryInterface
Open

        $contentType = $this->contentTypeRepository->findOneByContentTypeIdInLastVersion($data->getContentType());

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

    public function postSubmit(FormEvent $event)

Checking instanceof against undeclared class \OpenOrchestra\ModelInterface\Model\ContentTypeInterface
Open

        if ($contentType instanceof ContentTypeInterface) {

Parameter $contentTypeField has undeclared type \OpenOrchestra\ModelInterface\Model\FieldTypeInterface
Open

    protected function getFieldOptions(FieldTypeInterface $contentTypeField)

Call to method getStatus from undeclared class \OpenOrchestra\ModelInterface\Model\ContentInterface
Open

        if ($content instanceof ContentInterface && $statusId && $content->getStatus()->getId() != $statusId) {

Call to method findOneByContentTypeIdInLastVersion from undeclared class \OpenOrchestra\ModelInterface\Repository\ContentTypeRepositoryInterface
Open

        $contentType = $this->contentTypeRepository->findOneByContentTypeIdInLastVersion($content->getContentType());

Checking instanceof against undeclared class \OpenOrchestra\ModelInterface\Model\ContentInterface
Open

        if ($content instanceof ContentInterface && $statusId && $content->getStatus()->getId() != $statusId) {

Call to method choose from undeclared class \OpenOrchestra\ModelInterface\Manager\MultiLanguagesChoiceManagerInterface
Open

                'label' => $this->multiLanguagesChoiceManager->choose($contentTypeField->getLabels()),

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

    public function preSetData(FormEvent $event)

Checking instanceof against undeclared class \OpenOrchestra\ModelInterface\Model\ContentTypeInterface
Open

        if ($contentType instanceof ContentTypeInterface) {

Reference to constant STATUS_CHANGE from undeclared class \OpenOrchestra\ModelInterface\StatusEvents
Open

                $this->eventDispatcher->dispatch(StatusEvents::STATUS_CHANGE, $event);

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

            FormEvents::PRE_SET_DATA => 'preSetData',

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

class ContentTypeSubscriber implements EventSubscriberInterface

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

        $data = $event->getData();

Call to method __construct from undeclared class \Symfony\Component\Form\FormError
Open

                    $error = new FormError($message);

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

    protected function addFieldToForm(FieldTypeInterface $contentTypeField, FormInterface $form)

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

        $content = $event->getForm()->getData();

Call to method getFieldId from undeclared class \OpenOrchestra\ModelInterface\Model\FieldTypeInterface
Open

            $contentTypeField->getFieldId(),

Possibly zero references to use statement for classlike/namespace ContentAttributeInterface (\OpenOrchestra\ModelInterface\Model\ContentAttributeInterface)
Open

use OpenOrchestra\ModelInterface\Model\ContentAttributeInterface;

Call to method getType from undeclared class \OpenOrchestra\ModelInterface\Model\FieldTypeInterface
Open

        $fieldTypeConfiguration = $this->fieldTypesConfiguration[$contentTypeField->getType()];

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

        $form->add(

Catching undeclared class \Symfony\Component\Form\Exception\TransformationFailedException
Open

                } catch (TransformationFailedException $e) {

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

        $data = $event->getData();

Call to method __construct from undeclared class \OpenOrchestra\ModelInterface\Event\StatusableEvent
Open

            $event = new StatusableEvent($content, $toStatus);

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

            FormEvents::PRE_SUBMIT => 'preSubmit',

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 postSetData(FormEvent $event)

Call to method getType from undeclared class \OpenOrchestra\ModelInterface\Model\FieldTypeInterface
Open

        $field = $this->fieldTypesConfiguration[$contentTypeField->getType()];

Call to method findOneByContentTypeIdInLastVersion from undeclared class \OpenOrchestra\ModelInterface\Repository\ContentTypeRepositoryInterface
Open

        $contentType = $this->contentTypeRepository->findOneByContentTypeIdInLastVersion($content->getContentType());

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

        $form = $event->getForm();

Parameter $contentTypeFields has undeclared type \OpenOrchestra\ModelInterface\Model\FieldTypeInterface[]
Open

    protected function addContentTypeFieldsToForm($contentTypeFields, FormInterface $form)

Parameter $contentTypeField has undeclared type \OpenOrchestra\ModelInterface\Model\FieldTypeInterface
Open

    protected function addFieldToForm(FieldTypeInterface $contentTypeField, FormInterface $form)

Parameter $statusRepository has undeclared type \OpenOrchestra\ModelInterface\Repository\StatusRepositoryInterface
Open

    public function __construct(

Call to method getFields from undeclared class \OpenOrchestra\ModelInterface\Model\ContentTypeInterface
Open

            $this->addContentTypeFieldsToForm($contentType->getFields(), $form);

Parameter $eventDispatcher has undeclared type \Symfony\Component\EventDispatcher\EventDispatcherInterface
Open

    public function __construct(

Call to method getType from undeclared class \OpenOrchestra\ModelInterface\Model\FieldTypeInterface
Open

            if (isset($this->fieldTypesConfiguration[$contentTypeField->getType()])) {

Call to method __construct from undeclared class \Symfony\Component\Validator\Constraints\NotBlank
Open

            $fieldParameters['constraints'] = new NotBlank();

Call to method getFormOptions from undeclared class \OpenOrchestra\ModelInterface\Model\FieldTypeInterface
Open

        $contentTypeOptions = $contentTypeField->getFormOptions();

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

        $content = $event->getData();

Call to method getFields from undeclared class \OpenOrchestra\ModelInterface\Model\ContentTypeInterface
Open

            foreach ($contentType->getFields() as $contentTypeField) {

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

    public function preSubmit(FormEvent $event)

Call to method find from undeclared class \OpenOrchestra\ModelInterface\Repository\StatusRepositoryInterface
Open

            $toStatus = $this->statusRepository->find($statusId);

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

    protected function addContentTypeFieldsToForm($contentTypeFields, FormInterface $form)

Call to method getLabels from undeclared class \OpenOrchestra\ModelInterface\Model\FieldTypeInterface
Open

                'label' => $this->multiLanguagesChoiceManager->choose($contentTypeField->getLabels()),

Parameter $contentTypeRepository has undeclared type \OpenOrchestra\ModelInterface\Repository\ContentTypeRepositoryInterface
Open

    public function __construct(

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

        $form = $event->getForm();

Checking instanceof against undeclared class \OpenOrchestra\ModelInterface\Model\ContentTypeInterface
Open

        if ($contentType instanceof ContentTypeInterface) {

Call to method getFields from undeclared class \OpenOrchestra\ModelInterface\Model\ContentTypeInterface
Open

            foreach ($contentType->getFields() as $contentTypeField) {

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

    protected $fieldTypesConfiguration;

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

    protected $multiLanguagesChoiceManager;

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

        $contentAttributeClass,

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

    protected $contentAttributeClass;

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

        $fieldTypeConfiguration = $this->fieldTypesConfiguration[$contentTypeField->getType()];

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

    protected $contentTypeRepository;

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

        $fieldTypesConfiguration,

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

        ValueTransformerManager $valueTransformerManager,

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

        MultiLanguagesChoiceManagerInterface $multiLanguagesChoiceManager,

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

    protected $valueTransformerManager;

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

        ContentTypeRepositoryInterface $contentTypeRepository,

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

Blank line found at start of control structure
Open

        foreach ($contentTypeFields as $contentTypeField) {

Line exceeds 120 characters; contains 157 characters
Open

                $options[$optionName] = (isset($contentTypeOptions[$optionName])) ? $contentTypeOptions[$optionName] : $optionConfiguration['default_value'];

There are no issues that match your filters.

Category
Status