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 __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

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

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

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

    public function __construct(

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

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

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

    public function __construct(

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);

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

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

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

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

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);

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

    public function clearForSite(SiteInterface $site)

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

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

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

    public function createOrUpdateForRedirection(RedirectionInterface $redirection)

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

        $siteLanguages = $site->getLanguages();

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

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

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

    public function __construct(

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

    public function createForSite(SiteInterface $site)

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

    public function createForNode(NodeInterface $node)

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

use OpenOrchestra\ModelInterface\Model\RouteDocumentInterface;

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

use OpenOrchestra\ModelInterface\Model\SiteAliasInterface;

Call to method findBySiteId from undeclared class \OpenOrchestra\ModelInterface\Repository\RedirectionRepositoryInterface
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 getSiteId from undeclared class \OpenOrchestra\ModelInterface\Model\SiteInterface
Open

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

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

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

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

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

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 getPath from undeclared class \OpenOrchestra\ModelInterface\Model\NodeInterface
Open

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

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

    public function __construct(

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

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

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

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

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

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

Call to method getSiteId from undeclared class \OpenOrchestra\ModelInterface\Model\NodeInterface
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)

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

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

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

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

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

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

Required argument follows optional
Open

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

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

    public function clearForNode(NodeInterface $node)

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\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) {

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();

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 getNodeId from undeclared class \OpenOrchestra\ModelInterface\Model\RedirectionInterface
Open

            $redirection->getNodeId(),

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

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

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

            $redirection->getSiteId()

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

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

Parameter $redirection has undeclared type \OpenOrchestra\ModelInterface\Model\RedirectionInterface
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 getNodeId from undeclared class \OpenOrchestra\ModelInterface\Model\RedirectionInterface
Open

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

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

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

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

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

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

                    $paramValue = $redirection->getUrl();

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

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

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

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

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

    public function deleteForRedirection(RedirectionInterface $redirection)

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 getScheme from undeclared class \OpenOrchestra\ModelInterface\Model\NodeInterface
Open

                $scheme = $node->getScheme();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            $node->getPath(),

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

            $node->getSiteId(),

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

    protected function getNodeForRedirection(RedirectionInterface $redirection)

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

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

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

    public function clearForNode(NodeInterface $node)

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 getAliases from undeclared class \OpenOrchestra\ModelInterface\Model\ReadSiteInterface
Open

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

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

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

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

        if ($node instanceof NodeInterface) {

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

        if (!$node instanceof NodeInterface) {

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

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

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

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

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

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

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

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

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

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);

There are no issues that match your filters.

Category
Status