open-orchestra/open-orchestra-cms-bundle

View on GitHub
ApiBundle/Controller/ContentTypeController.php

Summary

Maintainability
A
55 mins
Test Coverage

Function deleteAction has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    public function deleteAction($contentTypeId)
    {
        if (0 == $this->get('open_orchestra_model.repository.content')->countByContentType($contentTypeId)) {
            $contentTypes = $this->get('open_orchestra_model.repository.content_type')->findBy(array('contentTypeId' => $contentTypeId));
            if (count($contentTypes) > 0) {
Severity: Minor
Found in ApiBundle/Controller/ContentTypeController.php - About 55 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

Avoid using static access to class '\OpenOrchestra\Pagination\Configuration\PaginateFinderConfiguration' in method 'listAction'.
Open

        $configuration = PaginateFinderConfiguration::generateFromRequest($request, $mapping);

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

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

Call to undeclared method \OpenOrchestra\ApiBundle\Controller\ContentTypeController::get
Open

        return $this->get('open_orchestra_api.transformer_manager')->transform('content_type', $contentType);

Call to undeclared method \OpenOrchestra\ApiBundle\Controller\ContentTypeController::get
Open

        $contentTypes = $this->get('open_orchestra_api.transformer_manager')->reverseTransform('content_type_collection', $facade);

Call to undeclared method \OpenOrchestra\ApiBundle\Controller\ContentTypeController::get
Open

        if (0 == $this->get('open_orchestra_model.repository.content')->countByContentType($contentTypeId)) {

Call to undeclared method \OpenOrchestra\ApiBundle\Controller\ContentTypeController::get
Open

                if (!$this->get('open_orchestra_backoffice.business_rules_manager')->isGranted(BusinessActionInterface::DELETE, $contentTypes[0])) {

Class extends undeclared class \OpenOrchestra\BaseApiBundle\Controller\BaseController
Open

class ContentTypeController extends BaseController

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

    public function listAction(Request $request)

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

    public function deleteAction($contentTypeId)

Possibly zero references to use statement for classlike/namespace Api (\OpenOrchestra\BaseApiBundle\Controller\Annotation)
Open

use OpenOrchestra\BaseApiBundle\Controller\Annotation as Api;

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

            $request->getContent(),

Call to undeclared method \OpenOrchestra\ApiBundle\Controller\ContentTypeController::getParameter
Open

            $this->getParameter('open_orchestra_api.facade.content_type_collection.class'),

Call to undeclared method \OpenOrchestra\ApiBundle\Controller\ContentTypeController::isGranted
Open

            if ($this->isGranted(ContributionActionInterface::DELETE, $contentType) &&

Returning type array{} but deleteContentTypesAction() is declared to return \Symfony\Component\HttpFoundation\Response
Open

        return array();

Call to undeclared method \OpenOrchestra\ApiBundle\Controller\ContentTypeController::get
Open

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

Call to undeclared method \OpenOrchestra\ApiBundle\Controller\ContentTypeController::dispatchEvent
Open

                $this->dispatchEvent(ContentTypeEvents::CONTENT_TYPE_DELETE, new ContentTypeEvent($contentType));

Call to undeclared method \OpenOrchestra\ApiBundle\Controller\ContentTypeController::createAccessDeniedException
Open

                    $this->createAccessDeniedException();

Call to undeclared method \OpenOrchestra\ApiBundle\Controller\ContentTypeController::get
Open

                $this->get('open_orchestra_backoffice.manager.content_type')->delete($contentTypes);

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

        $format = $request->get('_format', 'json');

Call to undeclared method \OpenOrchestra\ApiBundle\Controller\ContentTypeController::get
Open

        $facade = $this->get('open_orchestra_api.transformer_manager')->transform('content_type_collection', $collection);

Call to undeclared method \OpenOrchestra\ApiBundle\Controller\ContentTypeController::dispatchEvent
Open

                $this->dispatchEvent(ContentTypeEvents::CONTENT_TYPE_DELETE, new ContentTypeEvent($contentTypes[0]));

Return type of listForContentAction() is undeclared type \OpenOrchestra\BaseApi\Facade\FacadeInterface
Open

    public function listForContentAction()

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

    public function deleteContentTypesAction(Request $request)

Call to undeclared method \OpenOrchestra\ApiBundle\Controller\ContentTypeController::get
Open

                $this->get('open_orchestra_backoffice.business_rules_manager')->isGranted(BusinessActionInterface::DELETE, $contentType)

Reference to constant CONTENT_TYPE_DELETE from undeclared class \OpenOrchestra\ModelInterface\ContentTypeEvents
Open

                $this->dispatchEvent(ContentTypeEvents::CONTENT_TYPE_DELETE, new ContentTypeEvent($contentType));

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

                $this->dispatchEvent(ContentTypeEvents::CONTENT_TYPE_DELETE, new ContentTypeEvent($contentType));

@throws type of deleteAction has undeclared type \OpenOrchestra\ApiBundle\Controller\ContentTypeNotAllowedException
Open

    public function deleteAction($contentTypeId)

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

use Sensio\Bundle\FrameworkExtraBundle\Configuration as Config;

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

        $this->denyAccessUnlessGranted(ContributionActionInterface::READ, ContentTypeInterface::ENTITY_TYPE);

Call to undeclared method \OpenOrchestra\ApiBundle\Controller\ContentTypeController::denyAccessUnlessGranted
Open

        $this->denyAccessUnlessGranted(ContributionActionInterface::READ, ContentTypeInterface::ENTITY_TYPE);

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

    public function deleteContentTypesAction(Request $request)

Returning type array{} but deleteAction() is declared to return \Symfony\Component\HttpFoundation\Response
Open

        return array();

Call to undeclared method \OpenOrchestra\ApiBundle\Controller\ContentTypeController::get
Open

        $facade = $this->get('open_orchestra_api.transformer_manager')->transform('content_type_collection', $collection);

Call to undeclared method \OpenOrchestra\ApiBundle\Controller\ContentTypeController::get
Open

        $repository = $this->get('open_orchestra_model.repository.content_type');

Call to undeclared method \OpenOrchestra\ApiBundle\Controller\ContentTypeController::get
Open

            $contentTypes = $this->get('open_orchestra_model.repository.content_type')->findBy(array('contentTypeId' => $contentTypeId));

Call to undeclared method \OpenOrchestra\ApiBundle\Controller\ContentTypeController::get
Open

                $this->get('object_manager')->flush();

Call to undeclared method \OpenOrchestra\ApiBundle\Controller\ContentTypeController::get
Open

        $facade = $this->get('jms_serializer')->deserialize(

Call to undeclared method \OpenOrchestra\ApiBundle\Controller\ContentTypeController::get
Open

        $site = $this->get('open_orchestra_model.repository.site')->findOneBySiteId($siteId);

Return type of showAction() is undeclared type \OpenOrchestra\BaseApi\Facade\FacadeInterface
Open

    public function showAction($contentTypeId)

Call to undeclared method \OpenOrchestra\ApiBundle\Controller\ContentTypeController::get
Open

        $contentType = $this->get('open_orchestra_model.repository.content_type')->findOneByContentTypeIdInLastVersion($contentTypeId);

Call to undeclared method \OpenOrchestra\ApiBundle\Controller\ContentTypeController::get
Open

        $contentTypeRepository = $this->get('open_orchestra_model.repository.content_type');

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

                $this->dispatchEvent(ContentTypeEvents::CONTENT_TYPE_DELETE, new ContentTypeEvent($contentTypes[0]));

Return type of listAction() is undeclared type \OpenOrchestra\BaseApi\Facade\FacadeInterface
Open

    public function listAction(Request $request)

Call to method generateFromRequest from undeclared class \OpenOrchestra\Pagination\Configuration\PaginateFinderConfiguration
Open

        $configuration = PaginateFinderConfiguration::generateFromRequest($request, $mapping);

Call to undeclared method \OpenOrchestra\ApiBundle\Controller\ContentTypeController::get
Open

        $repository = $this->get('open_orchestra_model.repository.content_type');

Call to undeclared method \OpenOrchestra\ApiBundle\Controller\ContentTypeController::denyAccessUnlessGranted
Open

                    $this->denyAccessUnlessGranted(ContributionActionInterface::DELETE, $contentType);

Reference to constant CONTENT_TYPE_DELETE from undeclared class \OpenOrchestra\ModelInterface\ContentTypeEvents
Open

                $this->dispatchEvent(ContentTypeEvents::CONTENT_TYPE_DELETE, new ContentTypeEvent($contentTypes[0]));

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

        $contentTypeRepository = $this->get('open_orchestra_model.repository.content_type');

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

        $contentTypes = $this->get('open_orchestra_api.transformer_manager')->reverseTransform('content_type_collection', $facade);

Line exceeds 120 characters; contains 122 characters
Open

        $facade = $this->get('open_orchestra_api.transformer_manager')->transform('content_type_collection', $collection);

Line exceeds 120 characters; contains 122 characters
Open

        $facade = $this->get('open_orchestra_api.transformer_manager')->transform('content_type_collection', $collection);

Line exceeds 120 characters; contains 137 characters
Open

            $contentTypes = $this->get('open_orchestra_model.repository.content_type')->findBy(array('contentTypeId' => $contentTypeId));

Line exceeds 120 characters; contains 136 characters
Open

                $this->get('open_orchestra_backoffice.business_rules_manager')->isGranted(BusinessActionInterface::DELETE, $contentType)

Line exceeds 120 characters; contains 148 characters
Open

                if (!$this->get('open_orchestra_backoffice.business_rules_manager')->isGranted(BusinessActionInterface::DELETE, $contentTypes[0])) {

Line exceeds 120 characters; contains 135 characters
Open

        $contentType = $this->get('open_orchestra_model.repository.content_type')->findOneByContentTypeIdInLastVersion($contentTypeId);

There are no issues that match your filters.

Category
Status