open-orchestra/open-orchestra-cms-bundle

View on GitHub
BackofficeBundle/Controller/BlockController.php

Summary

Maintainability
A
2 hrs
Test Coverage

Method newAction has 7 arguments (exceeds 4 allowed). Consider refactoring.
Open

    public function newAction(Request $request, $nodeId, $language, $version, $areaId, $position, $component)
Severity: Major
Found in BackofficeBundle/Controller/BlockController.php - About 50 mins to fix

The class BlockController has a coupling between objects value of 15. Consider to reduce the number of dependencies under 13.
Open

class BlockController extends AbstractAdminController
{
    /**
     * @param Request $request
     * @param string  $component

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

The method formAction has a boolean flag argument $read, which is a certain sign of a Single Responsibility Principle violation.
Open

    public function formAction(Request $request, $blockId, $read = false)

BooleanArgumentFlag

Since: 1.4.0

A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

Example

class Foo {
    public function bar($flag = true) {
    }
}

Source https://phpmd.org/rules/cleancode.html#booleanargumentflag

Missing class import via use statement (line '135', column '23').
Open

            throw new \UnexpectedValueException();

MissingImport

Since: 2.7.0

Importing all external classes in a file through use statements makes them clearly visible.

Example

function make() {
    return new \stdClass();
}

Source http://phpmd.org/rules/cleancode.html#MissingImport

Call to method handleRequest from undeclared class \Symfony\Component\Form\Form
Open

        $form->handleRequest($request);

Call to undeclared method \OpenOrchestra\BackofficeBundle\Controller\BlockController::get
Open

        $block = $this->get('open_orchestra_backoffice.manager.block')->initializeBlock($component, $siteId, $language, false);

Call to method getConfig from undeclared class \Symfony\Component\Form\Form
Open

        return $this->renderAdminForm($form, array(), null, $form->getConfig()->getAttribute('template'));

Possibly zero references to use statement for classlike/namespace Config (\Sensio\Bundle\FrameworkExtraBundle\Configuration)
Open

use Sensio\Bundle\FrameworkExtraBundle\Configuration as Config;

Call to method handleRequest from undeclared class \Symfony\Component\Form\Form
Open

        $form->handleRequest($request);

Reference to constant ENTITY_TYPE from undeclared class \OpenOrchestra\ModelInterface\Model\BlockInterface
Open

        $this->denyAccessUnlessGranted(ContributionActionInterface::CREATE, BlockInterface::ENTITY_TYPE);

Call to undeclared method \OpenOrchestra\BackofficeBundle\Controller\BlockController::get
Open

            $node = $this->get('open_orchestra_model.repository.node')->findVersionNotDeleted($nodeId, $language, $siteId, $version);

Reference to constant HTTP_CREATED from undeclared class \Symfony\Component\HttpFoundation\Response
Open

            return new Response('', Response::HTTP_CREATED, array('Content-type' => 'text/html; charset=utf-8'));

Call to undeclared method \OpenOrchestra\BackofficeBundle\Controller\BlockController::get
Open

        $documentManager = $this->get('object_manager');

Argument 2 (option) is array{action:mixed,new_button:true} but \OpenOrchestra\BackofficeBundle\Controller\BlockController::createBlockForm() takes string defined at /code/BackofficeBundle/Controller/BlockController.php:183
Open

            "action" => $this->generateUrl('open_orchestra_backoffice_shared_block_new', array(

Call to method __construct from undeclared class \Symfony\Component\HttpFoundation\Response
Open

            $response = new Response(

Argument 2 (option) is array{action:mixed,delete_button:bool,disabled:mixed} but \OpenOrchestra\BackofficeBundle\Controller\BlockController::createBlockForm() takes string defined at /code/BackofficeBundle/Controller/BlockController.php:183
Open

            "action" => $this->generateUrl('open_orchestra_backoffice_block_form', array(

Reference to constant POST_BLOCK_UPDATE from undeclared class \OpenOrchestra\ModelInterface\BlockEvents
Open

            $this->dispatchEvent(BlockEvents::POST_BLOCK_UPDATE, new BlockEvent($block));

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

        $this->dispatchEvent(BlockEvents::POST_BLOCK_CREATE, new BlockEvent($block));

Call to undeclared method \OpenOrchestra\BackofficeBundle\Controller\BlockController::get
Open

        $siteId = $this->get('open_orchestra_backoffice.context_backoffice_manager')->getSiteId();

Argument 2 (event) is \OpenOrchestra\ModelInterface\Event\BlockEvent but \OpenOrchestra\BackofficeBundle\Controller\BlockController::dispatchEvent() takes \Symfony\Component\EventDispatcher\Event defined at /code/BackofficeBundle/Controller/AbstractAdminController.php:81
Open

            $this->dispatchEvent(BlockEvents::POST_BLOCK_CREATE, new BlockEvent($block));

Call to method isValid from undeclared class \Symfony\Component\Form\Form
Open

        if ('PATCH' !== $request->getMethod() && $form->isValid()) {

Parameter $request has undeclared type \Symfony\Component\HttpFoundation\Request
Open

    public function newSharedBlockAction(Request $request, $component, $language)

@throws type of newSharedBlockAction has undeclared type \OpenOrchestra\BaseApi\Exceptions\HttpException\ClientAccessDeniedHttpException
Open

    public function newSharedBlockAction(Request $request, $component, $language)

Call to undeclared method \OpenOrchestra\BackofficeBundle\Controller\BlockController::denyAccessUnlessGranted
Open

        $this->denyAccessUnlessGranted(ContributionActionInterface::CREATE, BlockInterface::ENTITY_TYPE);

@throws annotation of newAction has suspicious class type \OpenOrchestra\ApiBundle\Exceptions\HttpException\NodeNotFoundHttpException, which does not extend Error/Exception
Open

    public function newAction(Request $request, $nodeId, $language, $version, $areaId, $position, $component)

Call to undeclared method \OpenOrchestra\BackofficeBundle\Controller\BlockController::get
Open

        $siteId = $this->get('open_orchestra_backoffice.context_backoffice_manager')->getSiteId();

Call to undeclared method \OpenOrchestra\BackofficeBundle\Controller\BlockController::get
Open

        $message =  $this->get('translator')->trans('open_orchestra_backoffice.form.block.success');

Argument 1 (form) is \Symfony\Component\Form\Form but \OpenOrchestra\BackofficeBundle\Controller\BlockController::handleForm() takes \Symfony\Component\Form\FormInterface defined at /code/BackofficeBundle/Controller/AbstractAdminController.php:29
Open

        if ('PATCH' !== $request->getMethod() && $this->handleForm($form, $message)) {

Call to method getConfig from undeclared class \Symfony\Component\Form\Form
Open

        return $this->renderAdminForm($form, array(), null, $form->getConfig()->getAttribute('template'));

Argument 2 (event) is \OpenOrchestra\ModelInterface\Event\BlockNodeEvent but \OpenOrchestra\BackofficeBundle\Controller\BlockController::dispatchEvent() takes \Symfony\Component\EventDispatcher\Event defined at /code/BackofficeBundle/Controller/AbstractAdminController.php:81
Open

        $this->dispatchEvent(BlockNodeEvents::ADD_BLOCK_TO_NODE, new BlockNodeEvent($node, $block));

Call to undeclared method \OpenOrchestra\BackofficeBundle\Controller\BlockController::get
Open

        $block = $this->get('open_orchestra_backoffice.manager.block')->initializeBlock($component, $siteId, $language, true);

Call to undeclared method \OpenOrchestra\BackofficeBundle\Controller\BlockController::generateUrl
Open

            "action" => $this->generateUrl('open_orchestra_backoffice_block_new_in_node', array(

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

        if (!$block instanceof BlockInterface) {

Argument 2 (event) is \OpenOrchestra\ModelInterface\Event\BlockEvent but \OpenOrchestra\BackofficeBundle\Controller\BlockController::dispatchEvent() takes \Symfony\Component\EventDispatcher\Event defined at /code/BackofficeBundle/Controller/AbstractAdminController.php:81
Open

            $this->dispatchEvent(BlockEvents::POST_BLOCK_UPDATE, new BlockEvent($block));

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

            $this->dispatchEvent(BlockEvents::POST_BLOCK_UPDATE, new BlockEvent($block));

Call to undeclared method \OpenOrchestra\BackofficeBundle\Controller\BlockController::generateUrl
Open

            "action" => $this->generateUrl('open_orchestra_backoffice_shared_block_new', array(

Call to undeclared method \OpenOrchestra\BackofficeBundle\Controller\BlockController::get
Open

            $message = $this->get('translator')->trans('open_orchestra_backoffice.form.block.creation');

Call to undeclared method \OpenOrchestra\BackofficeBundle\Controller\BlockController::denyAccessUnlessGranted
Open

        $this->denyAccessUnlessGranted(ContributionActionInterface::EDIT, $block);

Argument 2 (event) is \OpenOrchestra\ModelInterface\Event\BlockEvent but \OpenOrchestra\BackofficeBundle\Controller\BlockController::dispatchEvent() takes \Symfony\Component\EventDispatcher\Event defined at /code/BackofficeBundle/Controller/AbstractAdminController.php:81
Open

        $this->dispatchEvent(BlockEvents::POST_BLOCK_CREATE, new BlockEvent($block));

Reference to constant ADD_BLOCK_TO_NODE from undeclared class \OpenOrchestra\ModelInterface\BlockNodeEvents
Open

        $this->dispatchEvent(BlockNodeEvents::ADD_BLOCK_TO_NODE, new BlockNodeEvent($node, $block));

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

        $this->dispatchEvent(BlockNodeEvents::ADD_BLOCK_TO_NODE, new BlockNodeEvent($node, $block));

Call to undeclared method \OpenOrchestra\BackofficeBundle\Controller\BlockController::get
Open

        $formType = $this->get('open_orchestra_backoffice.generate_form_manager')->getFormType($block);

Call to method getMethod from undeclared class \Symfony\Component\HttpFoundation\Request
Open

        if ('PATCH' !== $request->getMethod() && $form->isValid()) {

Argument 2 (option) is array{action:mixed} but \OpenOrchestra\BackofficeBundle\Controller\BlockController::createBlockForm() takes string defined at /code/BackofficeBundle/Controller/BlockController.php:183
Open

            "action" => $this->generateUrl('open_orchestra_backoffice_block_new_in_node', array(

Call to method getMethod from undeclared class \Symfony\Component\HttpFoundation\Request
Open

        if ('PATCH' !== $request->getMethod() && $form->isValid()) {

Parameter $request has undeclared type \Symfony\Component\HttpFoundation\Request
Open

    public function formAction(Request $request, $blockId, $read = false)

Reference to constant POST_BLOCK_CREATE from undeclared class \OpenOrchestra\ModelInterface\BlockEvents
Open

            $this->dispatchEvent(BlockEvents::POST_BLOCK_CREATE, new BlockEvent($block));

Reference to constant HTTP_CREATED from undeclared class \Symfony\Component\HttpFoundation\Response
Open

                Response::HTTP_CREATED,

Argument 1 (form) is \Symfony\Component\Form\Form but \OpenOrchestra\BackofficeBundle\Controller\BlockController::renderAdminForm() takes \Symfony\Component\Form\FormInterface defined at /code/BackofficeBundle/Controller/AbstractAdminController.php:58
Open

        return $this->renderAdminForm($form, array(), null, $form->getConfig()->getAttribute('template'));

Parameter $request has undeclared type \Symfony\Component\HttpFoundation\Request
Open

    public function newAction(Request $request, $nodeId, $language, $version, $areaId, $position, $component)

Return type of newAction() is undeclared type \Symfony\Component\HttpFoundation\Response
Open

    public function newAction(Request $request, $nodeId, $language, $version, $areaId, $position, $component)

Reference to constant ENTITY_TYPE from undeclared class \OpenOrchestra\ModelInterface\Model\BlockInterface
Open

        $this->denyAccessUnlessGranted(ContributionActionInterface::CREATE, BlockInterface::ENTITY_TYPE);

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

            if (!$node instanceof NodeInterface) {

Call to method getMethod from undeclared class \Symfony\Component\HttpFoundation\Request
Open

        if ('PATCH' !== $request->getMethod() && $this->handleForm($form, $message)) {

Argument 1 (form) is \Symfony\Component\Form\Form but \OpenOrchestra\BackofficeBundle\Controller\BlockController::renderAdminForm() takes \Symfony\Component\Form\FormInterface defined at /code/BackofficeBundle/Controller/AbstractAdminController.php:58
Open

        return $this->renderAdminForm($form, array(), null, $form->getConfig()->getAttribute('template'));

Parameter $request has undeclared type \Symfony\Component\HttpFoundation\Request
Open

    protected function createBlockForm(Request $request, $option, BlockInterface $block)

Return type of newSharedBlockAction() is undeclared type \Symfony\Component\HttpFoundation\Response
Open

    public function newSharedBlockAction(Request $request, $component, $language)

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

            $this->dispatchEvent(BlockEvents::POST_BLOCK_CREATE, new BlockEvent($block));

Call to undeclared method \OpenOrchestra\BackofficeBundle\Controller\BlockController::denyAccessUnlessGranted
Open

        $this->denyAccessUnlessGranted(ContributionActionInterface::CREATE, BlockInterface::ENTITY_TYPE);

Call to undeclared method \OpenOrchestra\BackofficeBundle\Controller\BlockController::get
Open

            "delete_button" => $this->get('open_orchestra_backoffice.business_rules_manager')->isGranted(BusinessActionInterface::DELETE, $block) && !$read,

Parameter $node has undeclared type \OpenOrchestra\ModelInterface\Model\NodeInterface
Open

    protected function addBlockToNode(BlockInterface $block, NodeInterface $node, $areaId, $position)

Call to method getArea from undeclared class \OpenOrchestra\ModelInterface\Model\NodeInterface
Open

        $area = $node->getArea($areaId);

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

    protected function createBlockForm(Request $request, $option, BlockInterface $block)

Call to undeclared method \OpenOrchestra\BackofficeBundle\Controller\BlockController::get
Open

            $documentManager = $this->get('object_manager');

Call to method getConfig from undeclared class \Symfony\Component\Form\Form
Open

        return $this->renderAdminForm($form, array(), null, $form->getConfig()->getAttribute('template'));

Call to undeclared method \OpenOrchestra\BackofficeBundle\Controller\BlockController::get
Open

        $block = $this->get('open_orchestra_model.repository.block')->findById($blockId);

Parameter $block has undeclared type \OpenOrchestra\ModelInterface\Model\BlockInterface
Open

    protected function addBlockToNode(BlockInterface $block, NodeInterface $node, $areaId, $position)

Parameter $block has undeclared type \OpenOrchestra\ModelInterface\Model\BlockInterface
Open

    protected function createBlockForm(Request $request, $option, BlockInterface $block)

Call to method getMethod from undeclared class \Symfony\Component\HttpFoundation\Request
Open

        if ("PATCH" === $request->getMethod()) {

Possibly zero references to use statement for classlike/namespace ContributionRoleInterface (\OpenOrchestra\Backoffice\Security\ContributionRoleInterface)
Open

use OpenOrchestra\Backoffice\Security\ContributionRoleInterface;

Call to undeclared method \OpenOrchestra\BackofficeBundle\Controller\BlockController::denyAccessUnlessGranted
Open

            $this->denyAccessUnlessGranted(ContributionActionInterface::EDIT, $node);

Call to method __construct from undeclared class \Symfony\Component\HttpFoundation\Response
Open

            return new Response('', Response::HTTP_CREATED, array('Content-type' => 'text/html; charset=utf-8'));

Argument 1 (form) is \Symfony\Component\Form\Form but \OpenOrchestra\BackofficeBundle\Controller\BlockController::renderAdminForm() takes \Symfony\Component\Form\FormInterface defined at /code/BackofficeBundle/Controller/AbstractAdminController.php:58
Open

        return $this->renderAdminForm($form, array(), null, $form->getConfig()->getAttribute('template'));

Return type of formAction() is undeclared type \Symfony\Component\HttpFoundation\Response
Open

    public function formAction(Request $request, $blockId, $read = false)

Call to undeclared method \OpenOrchestra\BackofficeBundle\Controller\BlockController::generateUrl
Open

            "action" => $this->generateUrl('open_orchestra_backoffice_block_form', array(

Reference to constant POST_BLOCK_CREATE from undeclared class \OpenOrchestra\ModelInterface\BlockEvents
Open

        $this->dispatchEvent(BlockEvents::POST_BLOCK_CREATE, new BlockEvent($block));

When appending to a value of type string, found an array access index of type 'validation_groups', but expected the index to be of type int
Open

            $option["validation_groups"] = false;

Call to method isValid from undeclared class \Symfony\Component\Form\Form
Open

        if ('PATCH' !== $request->getMethod() && $form->isValid()) {

Call to method handleRequest from undeclared class \Symfony\Component\Form\Form
Open

        $form->handleRequest($request);

Argument 2 (data) is \OpenOrchestra\ModelInterface\Model\BlockInterface but \OpenOrchestra\BackofficeBundle\Controller\BlockController::createForm() takes null defined at /code/BackofficeBundle/Controller/AbstractAdminController.php:94
Open

        return $this->createForm($formType, $block, $option);

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

        if ('PATCH' !== $request->getMethod() && $form->isValid()) {
            $documentManager = $this->get('object_manager');
            $documentManager->persist($block);
            $documentManager->flush();
            $message = $this->get('translator')->trans('open_orchestra_backoffice.form.block.creation');
Severity: Major
Found in BackofficeBundle/Controller/BlockController.php and 1 other location - About 1 hr to fix
UserAdminBundle/Controller/Admin/UserController.php on lines 52..66

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

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

Line exceeds 120 characters; contains 133 characters
Open

            $node = $this->get('open_orchestra_model.repository.node')->findVersionNotDeleted($nodeId, $language, $siteId, $version);

Line exceeds 120 characters; contains 127 characters
Open

        $block = $this->get('open_orchestra_backoffice.manager.block')->initializeBlock($component, $siteId, $language, false);

Line exceeds 120 characters; contains 156 characters
Open

            "delete_button" => $this->get('open_orchestra_backoffice.business_rules_manager')->isGranted(BusinessActionInterface::DELETE, $block) && !$read,

Line exceeds 120 characters; contains 126 characters
Open

        $block = $this->get('open_orchestra_backoffice.manager.block')->initializeBlock($component, $siteId, $language, true);

There are no issues that match your filters.

Category
Status