open-orchestra/open-orchestra-cms-bundle

View on GitHub
GroupBundle/EventSubscriber/GroupPerimeterSubscriber.php

Summary

Maintainability
A
45 mins
Test Coverage

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

    public function postSubmit(FormEvent $event)
    {
        if (($group = $event->getData()) instanceof GroupInterface) {
            $isSiteAdmin = $group->hasRole(ContributionRoleInterface::SITE_ADMIN);
            $siteId = $group->getSite()->getSiteId();
Severity: Minor
Found in GroupBundle/EventSubscriber/GroupPerimeterSubscriber.php - About 45 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 assigning values to variables in if clauses and the like (line '40', column '14').
Open

    public function postSubmit(FormEvent $event)
    {
        if (($group = $event->getData()) instanceof GroupInterface) {
            $isSiteAdmin = $group->hasRole(ContributionRoleInterface::SITE_ADMIN);
            $siteId = $group->getSite()->getSiteId();

IfStatementAssignment

Since: 2.7.0

Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

Example

class Foo
{
    public function bar($flag)
    {
        if ($foo = 'bar') { // possible typo
            // ...
        }
        if ($baz = 0) { // always false
            // ...
        }
    }
}

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

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

    public function postSubmit(FormEvent $event)

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

        $site = $this->siteRepository->findOneBySiteId($node->getSiteId());

Reference to constant PATH_UPDATED from undeclared class \OpenOrchestra\ModelInterface\NodeEvents
Open

            NodeEvents::PATH_UPDATED => 'updateNodeInPerimeter',

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

            NodeInterface::ENTITY_TYPE,

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

            NodeInterface::ENTITY_TYPE,

Reference to constant NODE_HARD_DELETED from undeclared class \OpenOrchestra\ModelInterface\NodeEvents
Open

            NodeEvents::NODE_HARD_DELETED => 'removeNodeFromPerimeter',

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

    public function __construct(GroupRepositoryInterface $groupRepository, SiteRepositoryInterface $siteRepository)

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

        if (($group = $event->getData()) instanceof GroupInterface) {

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

        $site = $this->siteRepository->findOneBySiteId($node->getSiteId());

Call to method getNode from undeclared class \OpenOrchestra\ModelInterface\Event\NodeEvent
Open

        $node = $event->getNode();

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

            $perimeter->setType(SiteInterface::ENTITY_TYPE);

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

class GroupPerimeterSubscriber implements EventSubscriberInterface

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

            $items = !is_null($group->getPerimeter(SiteInterface::ENTITY_TYPE)) ? $group->getPerimeter(SiteInterface::ENTITY_TYPE)->getItems() : array();

Parameter $event has undeclared type \OpenOrchestra\ModelInterface\Event\NodeEvent
Open

    public function updateNodeInPerimeter(NodeEvent $event)

Call to method getNode from undeclared class \OpenOrchestra\ModelInterface\Event\NodeEvent
Open

        $node = $event->getNode();

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

            FormEvents::POST_SUBMIT  => 'postSubmit',

Parameter $event has undeclared type \OpenOrchestra\ModelInterface\Event\NodeEvent
Open

    public function removeNodeFromPerimeter(NodeEvent $event)

Call to method getPreviousPath from undeclared class \OpenOrchestra\ModelInterface\Event\NodeEvent
Open

            $event->getPreviousPath(),

Line exceeds 120 characters; contains 153 characters
Open

            $items = !is_null($group->getPerimeter(SiteInterface::ENTITY_TYPE)) ? $group->getPerimeter(SiteInterface::ENTITY_TYPE)->getItems() : array();

There are no issues that match your filters.

Category
Status