open-orchestra/open-orchestra-cms-bundle

View on GitHub
Backoffice/Manager/RouteDocumentManager.php

Summary

Maintainability
B
5 hrs
Test Coverage

Function generateRoutesForNode has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    protected function generateRoutesForNode(NodeInterface $node, ReadSiteInterface $site, array $routePattern)
    {
        $routes = array();

        if (!$node instanceof NodeInterface) {
Severity: Minor
Found in Backoffice/Manager/RouteDocumentManager.php - About 1 hr 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

Method generateRoutesForRedirection has 29 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    protected function generateRoutesForRedirection(RedirectionInterface $redirection, ReadSiteInterface $site)
    {
        $routes = array();

        $node = $this->getNodeForRedirection($redirection);
Severity: Minor
Found in Backoffice/Manager/RouteDocumentManager.php - About 1 hr to fix

Method generateRoutesForNode has 28 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    protected function generateRoutesForNode(NodeInterface $node, ReadSiteInterface $site, array $routePattern)
    {
        $routes = array();

        if (!$node instanceof NodeInterface) {
Severity: Minor
Found in Backoffice/Manager/RouteDocumentManager.php - About 1 hr to fix

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

    protected function generateRoutesForRedirection(RedirectionInterface $redirection, ReadSiteInterface $site)
    {
        $routes = array();

        $node = $this->getNodeForRedirection($redirection);
Severity: Minor
Found in Backoffice/Manager/RouteDocumentManager.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

Method completeRoutePattern has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

    protected function completeRoutePattern($parentId = null, $suffix = null, $language, $siteId, array $routePattern)
Severity: Minor
Found in Backoffice/Manager/RouteDocumentManager.php - About 35 mins to fix

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

        $routeDocumentClass,
        SiteRepositoryInterface $siteRepository,
        NodeRepositoryInterface $nodeRepository,
        RedirectionRepositoryInterface $redirectionRepository,
        RouteDocumentRepositoryInterface $routeDocumentRepository
Severity: Minor
Found in Backoffice/Manager/RouteDocumentManager.php - About 35 mins to fix

The method generateRoutesForRedirection uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

                } else {
                    $paramValue = $redirection->getUrl();
                }

ElseExpression

Since: 1.4.0

An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

Example

class Foo
{
    public function bar($flag)
    {
        if ($flag) {
            // one branch
        } else {
            // another branch
        }
    }
}

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

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

use OpenOrchestra\ModelInterface\Model\RouteDocumentInterface;

Parameter $site has undeclared type \OpenOrchestra\ModelInterface\Model\SiteInterface
Open

    public function createForSite(SiteInterface $site)

Call to method findPublishedByPathAndLanguage from undeclared class \OpenOrchestra\ModelInterface\Repository\NodeRepositoryInterface
Open

        $nodes = $this->nodeRepository->findPublishedByPathAndLanguage($node->getPath(), $site->getSiteId(), $node->getLanguage());

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

        $nodes = $this->nodeRepository->findPublishedByPathAndLanguage($node->getPath(), $site->getSiteId(), $node->getLanguage());

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

    public function __construct(

Call to method getSiteId from undeclared class \OpenOrchestra\ModelInterface\Model\SiteInterface
Open

            $nodes = $this->nodeRepository->findPublishedByLanguageAndSiteId($language, $site->getSiteId());

Call to method getSiteId from undeclared class \OpenOrchestra\ModelInterface\Model\SiteInterface
Open

            $routePattern = $this->nodeRepository->findAllRoutePattern($language, $site->getSiteId());

Argument 2 (site) is \OpenOrchestra\ModelInterface\Model\SiteInterface but \OpenOrchestra\Backoffice\Manager\RouteDocumentManager::generateRoutesForNode() takes \OpenOrchestra\ModelInterface\Model\ReadSiteInterface defined at /code/Backoffice/Manager/RouteDocumentManager.php:221
Open

                $routes = array_merge($this->generateRoutesForNode($node, $site, $routePattern), $routes);

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

    public function createForNode(NodeInterface $node)

Call to method getSiteId from undeclared class \OpenOrchestra\ModelInterface\Model\SiteInterface
Open

        $this->routeDocumentRepository->removeBySiteId($site->getSiteId());

Argument 2 (site) is \OpenOrchestra\ModelInterface\Model\SiteInterface but \OpenOrchestra\Backoffice\Manager\RouteDocumentManager::generateRoutesForRedirection() takes \OpenOrchestra\ModelInterface\Model\ReadSiteInterface defined at /code/Backoffice/Manager/RouteDocumentManager.php:265
Open

            $routes = array_merge($this->generateRoutesForRedirection($redirection, $site), $routes);

Call to method getLanguages from undeclared class \OpenOrchestra\ModelInterface\Model\SiteInterface
Open

        $siteLanguages = $site->getLanguages();

Parameter $routeDocumentRepository has undeclared type \OpenOrchestra\ModelInterface\Repository\RouteDocumentRepositoryInterface
Open

    public function __construct(

Call to method findPublishedByLanguageAndSiteId from undeclared class \OpenOrchestra\ModelInterface\Repository\NodeRepositoryInterface
Open

            $nodes = $this->nodeRepository->findPublishedByLanguageAndSiteId($language, $site->getSiteId());

Parameter $redirectionRepository has undeclared type \OpenOrchestra\ModelInterface\Repository\RedirectionRepositoryInterface
Open

    public function __construct(

Parameter $site has undeclared type \OpenOrchestra\ModelInterface\Model\SiteInterface
Open

    public function clearForSite(SiteInterface $site)

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

        $nodes = $this->nodeRepository->findPublishedByPathAndLanguage($node->getPath(), $site->getSiteId(), $node->getLanguage());

Call to method findAllRoutePattern from undeclared class \OpenOrchestra\ModelInterface\Repository\NodeRepositoryInterface
Open

        $routePattern = $this->nodeRepository->findAllRoutePattern($node->getLanguage(), $site->getSiteId());

Call to method findBySiteId from undeclared class \OpenOrchestra\ModelInterface\Repository\RedirectionRepositoryInterface
Open

        $listRedirection = $this->redirectionRepository->findBySiteId($site->getSiteId());

Call to method getSiteId from undeclared class \OpenOrchestra\ModelInterface\Model\SiteInterface
Open

        $listRedirection = $this->redirectionRepository->findBySiteId($site->getSiteId());

Call to method findAllRoutePattern from undeclared class \OpenOrchestra\ModelInterface\Repository\NodeRepositoryInterface
Open

            $routePattern = $this->nodeRepository->findAllRoutePattern($language, $site->getSiteId());

Call to method getId from undeclared class \OpenOrchestra\ModelInterface\Model\RedirectionInterface
Open

        $this->routeDocumentRepository->removeByRedirectionId($redirection->getId());

Reference to constant SCHEME_DEFAULT from undeclared class \OpenOrchestra\ModelInterface\Model\SchemeableInterface
Open

                if (is_null($scheme) || SchemeableInterface::SCHEME_DEFAULT == $scheme) {

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

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

Parameter $redirection has undeclared type \OpenOrchestra\ModelInterface\Model\RedirectionInterface
Open

    public function createOrUpdateForRedirection(RedirectionInterface $redirection)

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

        $this->routeDocumentRepository->removeByNodeIdsSiteIdAndLanguage($nodeIds, $node->getSiteId(), $node->getLanguage());

Parameter $redirection has undeclared type \OpenOrchestra\ModelInterface\Model\RedirectionInterface
Open

    protected function getNodeForRedirection(RedirectionInterface $redirection)

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

use OpenOrchestra\ModelInterface\Model\SiteAliasInterface;

Parameter $nodeRepository has undeclared type \OpenOrchestra\ModelInterface\Repository\NodeRepositoryInterface
Open

    public function __construct(

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

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

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

        $routePattern = $this->nodeRepository->findAllRoutePattern($node->getLanguage(), $site->getSiteId());

Return type of clearForNode() is undeclared type \Doctrine\Common\Collections\Collection
Open

    public function clearForNode(NodeInterface $node)

Call to method findNodeIdByIncludedPathSiteIdAndLanguage from undeclared class \OpenOrchestra\ModelInterface\Repository\NodeRepositoryInterface
Open

        $nodeIds = $this->nodeRepository->findNodeIdByIncludedPathSiteIdAndLanguage(

Call to method removeByNodeIdsSiteIdAndLanguage from undeclared class \OpenOrchestra\ModelInterface\Repository\RouteDocumentRepositoryInterface
Open

        $this->routeDocumentRepository->removeByNodeIdsSiteIdAndLanguage($nodeIds, $node->getSiteId(), $node->getLanguage());

Return type of getNodeForRedirection() is undeclared type \OpenOrchestra\ModelInterface\Model\NodeInterface
Open

    protected function getNodeForRedirection(RedirectionInterface $redirection)

Call to method getNodeId from undeclared class \OpenOrchestra\ModelInterface\Model\RedirectionInterface
Open

        if (is_null($redirection->getNodeId())) {

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

    protected function generateRoutesForNode(NodeInterface $node, ReadSiteInterface $site, array $routePattern)

Call to method getSiteId from undeclared class \OpenOrchestra\ModelInterface\Model\RedirectionInterface
Open

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

Required argument follows optional
Open

    protected function completeRoutePattern($parentId = null, $suffix = null, $language, $siteId, array $routePattern)

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

        if (!$node instanceof NodeInterface) {

Call to method removeBySiteId from undeclared class \OpenOrchestra\ModelInterface\Repository\RouteDocumentRepositoryInterface
Open

        $this->routeDocumentRepository->removeBySiteId($site->getSiteId());

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

    public function clearForNode(NodeInterface $node)

Call to method getRoutePattern from undeclared class \OpenOrchestra\ModelInterface\Model\RedirectionInterface
Open

                $route->setPattern($redirection->getRoutePattern());

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

            $node->getPath(),

Call to method getSiteId from undeclared class \OpenOrchestra\ModelInterface\Model\ReadSiteInterface
Open

                $pattern = $this->completeRoutePattern($node->getParentId(), $node->getRoutePattern(), $node->getLanguage(), $site->getSiteId(), $routePattern);

Call to method getAliases from undeclared class \OpenOrchestra\ModelInterface\Model\ReadSiteInterface
Open

        foreach ($site->getAliases() as $key => $alias) {

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

                $scheme = $node->getScheme();

Call to method getSiteId from undeclared class \OpenOrchestra\ModelInterface\Model\ReadSiteInterface
Open

                $route->setSiteId($site->getSiteId());

Parameter $site has undeclared type \OpenOrchestra\ModelInterface\Model\ReadSiteInterface
Open

    protected function generateRoutesForRedirection(RedirectionInterface $redirection, ReadSiteInterface $site)

Call to method getId from undeclared class \OpenOrchestra\ModelInterface\Model\RedirectionInterface
Open

                $route->setName($key . '_' . $redirection->getId());

Call to method getUrl from undeclared class \OpenOrchestra\ModelInterface\Model\RedirectionInterface
Open

                    $paramValue = $redirection->getUrl();

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

        $this->routeDocumentRepository->removeByNodeIdsSiteIdAndLanguage($nodeIds, $node->getSiteId(), $node->getLanguage());

Call to method getNodeId from undeclared class \OpenOrchestra\ModelInterface\Model\RedirectionInterface
Open

            $redirection->getNodeId(),

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

            if ($alias->getLanguage() == $node->getLanguage()) {

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

                $route->setLanguage($node->getLanguage());

Call to method isPermanent from undeclared class \OpenOrchestra\ModelInterface\Model\RedirectionInterface
Open

                    'permanent' => $redirection->isPermanent()

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

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

Parameter $redirection has undeclared type \OpenOrchestra\ModelInterface\Model\RedirectionInterface
Open

    public function deleteForRedirection(RedirectionInterface $redirection)

Call to method removeByRedirectionId from undeclared class \OpenOrchestra\ModelInterface\Repository\RouteDocumentRepositoryInterface
Open

        $this->routeDocumentRepository->removeByRedirectionId($redirection->getId());

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

            $node->getSiteId(),

Call to method findOnePublished from undeclared class \OpenOrchestra\ModelInterface\Repository\NodeRepositoryInterface
Open

        $node = $this->nodeRepository->findOnePublished(

Call to method getSiteId from undeclared class \OpenOrchestra\ModelInterface\Model\RedirectionInterface
Open

            $redirection->getSiteId()

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

                $route->setNodeId($node->getNodeId());

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

        if ($node instanceof NodeInterface) {

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

                    $paramValue = $key . '_' . $node->getId();

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

                $route->setName($key . '_' . $node->getId());

Call to method getSiteId from undeclared class \OpenOrchestra\ModelInterface\Model\ReadSiteInterface
Open

                $route->setSiteId($site->getSiteId());

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

            $node->getLanguage()

Call to method getLocale from undeclared class \OpenOrchestra\ModelInterface\Model\RedirectionInterface
Open

            $redirection->getLocale(),

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

                $pattern = $this->completeRoutePattern($node->getParentId(), $node->getRoutePattern(), $node->getLanguage(), $site->getSiteId(), $routePattern);

Method \OpenOrchestra\Backoffice\Manager\RouteDocumentManager::clearForNode is declared to return \Doctrine\Common\Collections\Collection but has no return value
Open

    public function clearForNode(NodeInterface $node)

Call to method getAliases from undeclared class \OpenOrchestra\ModelInterface\Model\ReadSiteInterface
Open

        foreach ($site->getAliases() as $key => $alias) {

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

                $pattern = $this->completeRoutePattern($node->getParentId(), $node->getRoutePattern(), $node->getLanguage(), $site->getSiteId(), $routePattern);

Parameter $redirection has undeclared type \OpenOrchestra\ModelInterface\Model\RedirectionInterface
Open

    protected function generateRoutesForRedirection(RedirectionInterface $redirection, ReadSiteInterface $site)

Parameter $site has undeclared type \OpenOrchestra\ModelInterface\Model\ReadSiteInterface
Open

    protected function generateRoutesForNode(NodeInterface $node, ReadSiteInterface $site, array $routePattern)

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

                if ($node instanceof NodeInterface) {

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

        if (is_null($parentId) || NodeInterface::ROOT_PARENT_ID == $parentId || '' == $parentId || 0 === strpos($suffix, '/')) {

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

                $pattern = $this->completeRoutePattern($node->getParentId(), $node->getRoutePattern(), $node->getLanguage(), $site->getSiteId(), $routePattern);

Call to method getLocale from undeclared class \OpenOrchestra\ModelInterface\Model\RedirectionInterface
Open

            if ($alias->getLanguage() == $redirection->getLocale()) {

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

    protected $routeDocumentRepository;

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

        RedirectionRepositoryInterface $redirectionRepository,

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

    protected $redirectionRepository;

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

        RouteDocumentRepositoryInterface $routeDocumentRepository

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

The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line
Open

    {

Line exceeds 120 characters; contains 125 characters
Open

        $this->routeDocumentRepository->removeByNodeIdsSiteIdAndLanguage($nodeIds, $node->getSiteId(), $node->getLanguage());

Line exceeds 120 characters; contains 174 characters
Open

            return $this->suppressDoubleSlashes($this->completeRoutePattern($parent['parentId'], $parent['routePattern'] . '/' . $suffix, $language, $siteId, $routePattern));

Line exceeds 120 characters; contains 128 characters
Open

        if (is_null($parentId) || NodeInterface::ROOT_PARENT_ID == $parentId || '' == $parentId || 0 === strpos($suffix, '/')) {

Arguments with default values must be at the end of the argument list
Open

    protected function completeRoutePattern($parentId = null, $suffix = null, $language, $siteId, array $routePattern)

Line exceeds 120 characters; contains 160 characters
Open

                $pattern = $this->completeRoutePattern($node->getParentId(), $node->getRoutePattern(), $node->getLanguage(), $site->getSiteId(), $routePattern);

Line exceeds 120 characters; contains 131 characters
Open

        $nodes = $this->nodeRepository->findPublishedByPathAndLanguage($node->getPath(), $site->getSiteId(), $node->getLanguage());

There are no issues that match your filters.

Category
Status