open-orchestra/open-orchestra-cms-bundle

View on GitHub
BackofficeBundle/Controller/ContentController.php

Summary

Maintainability
B
4 hrs
Test Coverage

Method newAction has 48 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function newAction(Request $request, $contentTypeId, $language)
    {
        $siteId = $this->get('open_orchestra_backoffice.context_backoffice_manager')->getSiteId();
        $site = $this->get('open_orchestra_model.repository.site')->findOneBySiteId($siteId);

Severity: Minor
Found in BackofficeBundle/Controller/ContentController.php - About 1 hr to fix

Method formAction has 42 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function formAction(Request $request, $contentId, $language, $version)
    {
        $content = $this->get('open_orchestra_model.repository.content')->findOneByLanguageAndVersion($contentId, $language, $version);
        if (!$content instanceof ContentInterface) {
            throw new \UnexpectedValueException();
Severity: Minor
Found in BackofficeBundle/Controller/ContentController.php - About 1 hr to fix

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

    public function newAction(Request $request, $contentTypeId, $language)
    {
        $siteId = $this->get('open_orchestra_backoffice.context_backoffice_manager')->getSiteId();
        $site = $this->get('open_orchestra_model.repository.site')->findOneBySiteId($siteId);

Severity: Minor
Found in BackofficeBundle/Controller/ContentController.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 formAction has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public function formAction(Request $request, $contentId, $language, $version)
    {
        $content = $this->get('open_orchestra_model.repository.content')->findOneByLanguageAndVersion($contentId, $language, $version);
        if (!$content instanceof ContentInterface) {
            throw new \UnexpectedValueException();
Severity: Minor
Found in BackofficeBundle/Controller/ContentController.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

Missing class import via use statement (line '39', 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

Missing class import via use statement (line '45', 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

Missing class import via use statement (line '106', 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

Missing class import via use statement (line '115', 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 isAlwaysShared from undeclared class \OpenOrchestra\ModelInterface\Model\ContentTypeInterface
Open

            $contentType->isLinkedToSite() && $contentType->isAlwaysShared(),

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

            $this->dispatchEvent(ContentEvents::CONTENT_CREATION, new ContentEvent($content));

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

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

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

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

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

        if (!$content instanceof ContentInterface) {

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

            'need_link_to_site_defintion' => !$contentType->isLinkedToSite() && !$contentType->isAlwaysShared(),

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

                $this->dispatchEvent(ContentEvents::CONTENT_CREATION, new ContentEvent($translatedContent));

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

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

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

            if ($customTemplate != '' && $this->get('templating')->exists($customTemplate)) {

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

    public function formAction(Request $request, $contentId, $language, $version)

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

            'action' => $this->generateUrl('open_orchestra_backoffice_content_form', array(

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

            'disabled' => $content->getStatus() ? $content->getStatus()->isBlockedEdition() : false,

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

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

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

        $form = $this->createForm('oo_content', $content, array(

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

                Response::HTTP_CREATED,

Call to undeclared method \OpenOrchestra\BackofficeBundle\Controller\ContentController::isGranted
Open

            'delete_button' => $this->isGranted(ContributionActionInterface::DELETE, $content),

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

            'is_statusable' => $contentType->isDefiningStatusable()

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

        if ($form->isValid()) {

Reference to constant CONTENT_UPDATE from undeclared class \OpenOrchestra\ModelInterface\ContentEvents
Open

            $this->dispatchEvent(ContentEvents::CONTENT_UPDATE, new ContentEvent($content));

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

    public function newAction(Request $request, $contentTypeId, $language)

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

            'is_statusable' => $contentType->isDefiningStatusable()

Reference to constant CONTENT_CHANGE_STATUS from undeclared class \OpenOrchestra\ModelInterface\ContentEvents
Open

                $this->dispatchEvent(ContentEvents::CONTENT_CHANGE_STATUS, new ContentEvent($content, $status));

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

            $customTemplate = $contentType->getTemplate();

Reference to constant CONTENT_CREATION from undeclared class \OpenOrchestra\ModelInterface\ContentEvents
Open

                $this->dispatchEvent(ContentEvents::CONTENT_CREATION, new ContentEvent($translatedContent));

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

            $this->dispatchEvent(ContentEvents::CONTENT_UPDATE, new ContentEvent($content));

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

            $contentType->isLinkedToSite() && $contentType->isAlwaysShared(),

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

            'need_link_to_site_defintion' => !$contentType->isLinkedToSite() && !$contentType->isAlwaysShared(),

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

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

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

            $contentType->isDefiningStatusable()

Parameter $content has undeclared type \OpenOrchestra\ModelInterface\Model\ContentInterface
Open

    protected function createContentInNewLanguage(ContentInterface $content, $currentLanguage)

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

        if (!$contentType instanceof ContentTypeInterface || !in_array($contentType->getContentTypeId(), $site->getContentTypes())) {

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

        if ($form->isValid()) {

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

                $translatedContent = $this->get('open_orchestra_backoffice.manager.content')->createNewLanguageContent($content, $siteLanguage);

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

            $this->getFormTemplate($content->getContentType()

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

        if (!$content instanceof ContentInterface) {

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

            $response = new Response(

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

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

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

                'version' => $content->getVersion(),

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

            $this->get('session')->getFlashBag()->add('success', $message);

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

    public function newAction(Request $request, $contentTypeId, $language)

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

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

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

                $this->dispatchEvent(ContentEvents::CONTENT_CHANGE_STATUS, new ContentEvent($content, $status));

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

                $this->get('object_manager')->persist($translatedContent);

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

    public function formAction(Request $request, $contentId, $language, $version)

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

            !$this->get('open_orchestra_backoffice.business_rules_manager')->isGranted(BusinessActionInterface::EDIT, $content)

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

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

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

                'language' => $content->getLanguage(),

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

            'action' => $this->generateUrl('open_orchestra_backoffice_content_new', array(

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

            $this->dispatchEvent(ContentEvents::CONTENT_CREATION, new ContentEvent($content));

Reference to constant CONTENT_CREATION from undeclared class \OpenOrchestra\ModelInterface\ContentEvents
Open

            $this->dispatchEvent(ContentEvents::CONTENT_CREATION, new ContentEvent($content));

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

        $form->handleRequest($request);

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

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

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

        if (!$contentType instanceof ContentTypeInterface || !in_array($contentType->getContentTypeId(), $site->getContentTypes())) {

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

use Sensio\Bundle\FrameworkExtraBundle\Configuration as Config;

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

        $form = $this->createForm('oo_content', $content, $options);

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

        $form->handleRequest($request);

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

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

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

        return $this->renderAdminForm($form);

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

        if ($contentType instanceof ContentTypeInterface) {

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

        $languages = $this->get('open_orchestra_backoffice.context_backoffice_manager')->getSiteLanguages();

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

        $content = $this->get('open_orchestra_model.repository.content')->findOneByLanguageAndVersion($contentId, $language, $version);

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

        $publishedContents = $this->get('open_orchestra_model.repository.content')->findAllPublishedByContentId($contentId);

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

                'contentId' => $content->getContentId(),

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

            $this->dispatchEvent(ContentEvents::CONTENT_UPDATE, new ContentEvent($content));

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

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

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

        $contentManager = $this->get('open_orchestra_backoffice.manager.content');

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

                $this->dispatchEvent(ContentEvents::CONTENT_CREATION, new ContentEvent($translatedContent));

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

        if (!$contentType instanceof ContentTypeInterface &&

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

            $form,

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

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

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

        $status = $content->getStatus();

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

                $this->dispatchEvent(ContentEvents::CONTENT_CHANGE_STATUS, new ContentEvent($content, $status));

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

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

Blank line found at end of control structure
Open


Line exceeds 120 characters; contains 135 characters
Open

        $content = $this->get('open_orchestra_model.repository.content')->findOneByLanguageAndVersion($contentId, $language, $version);

Line exceeds 120 characters; contains 135 characters
Open

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

Line exceeds 120 characters; contains 155 characters
Open

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

Line exceeds 120 characters; contains 146 characters
Open

                array('Content-type' => 'text/plain; charset=utf-8', 'contentId' => $content->getContentId(), 'version' => $content->getVersion())

Line exceeds 120 characters; contains 124 characters
Open

        $publishedContents = $this->get('open_orchestra_model.repository.content')->findAllPublishedByContentId($contentId);

Line exceeds 120 characters; contains 147 characters
Open

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

Line exceeds 120 characters; contains 133 characters
Open

        if (!$contentType instanceof ContentTypeInterface || !in_array($contentType->getContentTypeId(), $site->getContentTypes())) {

Line exceeds 120 characters; contains 135 characters
Open

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

Line exceeds 120 characters; contains 127 characters
Open

            !$this->get('open_orchestra_backoffice.business_rules_manager')->isGranted(BusinessActionInterface::EDIT, $content)

Line exceeds 120 characters; contains 144 characters
Open

                $translatedContent = $this->get('open_orchestra_backoffice.manager.content')->createNewLanguageContent($content, $siteLanguage);

Closing parenthesis of a multi-line function call must be on a line by itself
Open

        ));

Expected 0 spaces before closing bracket; newline found
Open

            $this->getFormTemplate($content->getContentType()

There are no issues that match your filters.

Category
Status