open-orchestra/open-orchestra-cms-bundle

View on GitHub
Backoffice/Context/ContextBackOfficeManager.php

Summary

Maintainability
A
2 hrs
Test Coverage

Function getAvailableSites has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

    public function getAvailableSites()
    {
        $sites = array();
        $token = $this->tokenStorage->getToken();
        if ($token instanceof TokenInterface) {
Severity: Minor
Found in Backoffice/Context/ContextBackOfficeManager.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 __construct has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

        Session $session,
        TokenStorageInterface $tokenStorage,
        $defaultLocale,
        SiteRepositoryInterface $siteRepository,
        AuthorizationCheckerInterface $authorizationChecker
Severity: Minor
Found in Backoffice/Context/ContextBackOfficeManager.php - About 35 mins to fix

Function getBackOfficeLanguage has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    public function getBackOfficeLanguage()
    {
        $currentLanguage = $this->session->get(self::KEY_LOCALE);

        if (!$currentLanguage) {
Severity: Minor
Found in Backoffice/Context/ContextBackOfficeManager.php - About 35 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 '90', column '18').
Open

    public function getAvailableSites()
    {
        $sites = array();
        $token = $this->tokenStorage->getToken();
        if ($token instanceof TokenInterface) {

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

Avoid assigning values to variables in if clauses and the like (line '64', column '28').
Open

    public function getBackOfficeLanguage()
    {
        $currentLanguage = $this->session->get(self::KEY_LOCALE);

        if (!$currentLanguage) {

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

Avoid assigning values to variables in if clauses and the like (line '169', column '18').
Open

    public function getSiteContributionLanguage()
    {
        $currentLanguage = $this->getSite()['defaultLanguage'];

        $token = $this->tokenStorage->getToken();

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

Call to method remove from undeclared class \Symfony\Component\HttpFoundation\Session\Session
Open

        $this->session->remove(self::KEY_LOCALE);

Checking instanceof against undeclared class \FOS\UserBundle\Model\GroupableInterface
Open

            if (($user = $token->getUser()) instanceof GroupableInterface) {

Call to method set from undeclared class \Symfony\Component\HttpFoundation\Session\Session
Open

        $this->session->set(self::KEY_LOCALE, $language);

Parameter $tokenStorage has undeclared type \Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface
Open

    public function __construct(

Call to method getToken from undeclared class \Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface
Open

        $token = $this->tokenStorage->getToken();

Call to method remove from undeclared class \Symfony\Component\HttpFoundation\Session\Session
Open

        $this->session->remove(self::KEY_SITE);

Call to method getToken from undeclared class \Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface
Open

        $this->tokenStorage->getToken()->setAuthenticated(false);

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

        $currentSite = $this->session->get(self::KEY_SITE);

Call to method getToken from undeclared class \Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface
Open

            $token = $this->tokenStorage->getToken();

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

                $siteId = $site->getSiteId();

Return type of getAvailableSites() is undeclared type \OpenOrchestra\ModelInterface\Model\SiteInterface[]
Open

    public function getAvailableSites()

Call to method getUser from undeclared class \Symfony\Component\Security\Core\Authentication\Token\TokenInterface
Open

            if (($user = $token->getUser()) instanceof GroupableInterface) {

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

                $siteName = $site->getName();

Call to method set from undeclared class \Symfony\Component\HttpFoundation\Session\Session
Open

        $this->session->set(

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

                $locale = $site->getDefaultLanguage();

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

                $languages = $site->getLanguages();

Parameter $authorizationChecker has undeclared type \Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface
Open

    public function __construct(

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

        $currentLanguage = $this->session->get(self::KEY_LOCALE);

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

    public function __construct(

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

                return $this->siteRepository->findByDeleted(false);

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

                $currentSite = $this->session->get(self::KEY_SITE);

Checking instanceof against undeclared class \Symfony\Component\Security\Core\Authentication\Token\TokenInterface
Open

        if ($token instanceof TokenInterface) {

Call to method isGranted from undeclared class \Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface
Open

            if ($this->authorizationChecker->isGranted(ContributionRoleInterface::PLATFORM_ADMIN)) {

Checking instanceof against undeclared class \Symfony\Component\Security\Core\Authentication\Token\TokenInterface
Open

        if ($token instanceof TokenInterface) {

Checking instanceof against undeclared class \OpenOrchestra\UserBundle\Model\UserInterface
Open

            if ($token && ($user = $token->getUser()) instanceof UserInterface) {

Call to method getToken from undeclared class \Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface
Open

        $token = $this->tokenStorage->getToken();

Checking instanceof against undeclared class \OpenOrchestra\UserBundle\Model\UserInterface
Open

            if (($user = $token->getUser()) instanceof UserInterface && $user->hasLanguageBySite($this->getSiteId())) {

Call to method getUser from undeclared class \Symfony\Component\Security\Core\Authentication\Token\TokenInterface
Open

            if (($user = $token->getUser()) instanceof UserInterface && $user->hasLanguageBySite($this->getSiteId())) {

Parameter $session has undeclared type \Symfony\Component\HttpFoundation\Session\Session
Open

    public function __construct(

Declaration of function getAvailableSites() : \OpenOrchestra\ModelInterface\Model\SiteInterface[] should be compatible with function getAvailableSites() : \OpenOrchestra\Backoffice\Context\SiteInterface[] defined in /code/Backoffice/Context/ContextBackOfficeInterface.php:26
Open

    public function getAvailableSites()

Function closing brace must go on the next line following the body; found 1 blank lines before brace
Open

    }

There are no issues that match your filters.

Category
Status