open-orchestra/open-orchestra-cms-bundle

View on GitHub
BackofficeBundle/Command/OrchestraUnpublishElementCommand.php

Summary

Maintainability
B
4 hrs
Test Coverage

Function execute has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        if ($siteId = $input->getOption('siteId')) {
            $site = $this->getContainer()->get('open_orchestra_model.repository.site')->findOneBySiteId($siteId);
            if ($site) {
Severity: Minor
Found in BackofficeBundle/Command/OrchestraUnpublishElementCommand.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

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

        } else {
            $siteCollection = $this->getContainer()->get('open_orchestra_model.repository.site')->findByDeleted(false);
            if ($siteCollection) {
                foreach ($siteCollection as $site) {
                    $this->unpublishElements($site, $output);

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

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

            } else {
                $output->writeln("<error>No website found with siteId " . $siteId . ".</error>");

                return 1;
            }

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

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

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        if ($siteId = $input->getOption('siteId')) {
            $site = $this->getContainer()->get('open_orchestra_model.repository.site')->findOneBySiteId($siteId);
            if ($site) {

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 writeln from undeclared class \Symfony\Component\Console\Output\OutputInterface
Open

                $output->writeln("<error>No website found with siteId " . $siteId . ".</error>");

Call to method writeln from undeclared class \Symfony\Component\Console\Output\OutputInterface
Open

        $output->writeln("\n<info>Done.</info>");

Call to method writeln from undeclared class \Symfony\Component\Console\Output\OutputInterface
Open

            $output->writeln("<error>There is no published status defined.</error>");

Call to method writeln from undeclared class \Symfony\Component\Console\Output\OutputInterface
Open

        $output->writeln("\n<info>Unpublishing ".$this->getElementType()."s for siteId " . $site->getSiteId() . "</info>");

Call to method writeln from undeclared class \Symfony\Component\Console\Output\OutputInterface
Open

            $output->writeln("<error>There is no status defined to unpublish ".$this->getElementType()."s.</error>");

Call to undeclared method \OpenOrchestra\BackofficeBundle\Command\OrchestraUnpublishElementCommand::setName
Open

        $this

Parameter $output has undeclared type \Symfony\Component\Console\Output\OutputInterface
Open

    protected function unpublishElements(ReadSiteInterface $site, OutputInterface $output)

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

    protected function unpublishElements(ReadSiteInterface $site, OutputInterface $output)

Call to undeclared method \OpenOrchestra\BackofficeBundle\Command\OrchestraUnpublishElementCommand::getElementType
Open

            ->addOption('siteId', null, InputOption::VALUE_REQUIRED, 'If set, will unpublish '.$this->getElementType().'s only for this site');

Call to method getOption from undeclared class \Symfony\Component\Console\Input\InputInterface
Open

        if ($siteId = $input->getOption('siteId')) {

Call to undeclared method \OpenOrchestra\BackofficeBundle\Command\OrchestraUnpublishElementCommand::getContainer
Open

        $elementPublisherManager = $this->getContainer()->get($this->getManagerName());

Reference to constant VALUE_REQUIRED from undeclared class \Symfony\Component\Console\Input\InputOption
Open

            ->addOption('siteId', null, InputOption::VALUE_REQUIRED, 'If set, will unpublish '.$this->getElementType().'s only for this site');

Parameter $output has undeclared type \Symfony\Component\Console\Output\OutputInterface
Open

    protected function execute(InputInterface $input, OutputInterface $output)

Call to undeclared method \OpenOrchestra\BackofficeBundle\Command\OrchestraUnpublishElementCommand::getContainer
Open

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

Call to undeclared method \OpenOrchestra\BackofficeBundle\Command\OrchestraUnpublishElementCommand::getElementType
Open

            $output->writeln("<error>There is no status defined to unpublish ".$this->getElementType()."s.</error>");

Class extends undeclared class \Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand
Open

abstract class OrchestraUnpublishElementCommand extends ContainerAwareCommand

Parameter $input has undeclared type \Symfony\Component\Console\Input\InputInterface
Open

    protected function execute(InputInterface $input, OutputInterface $output)

Call to method writeln from undeclared class \Symfony\Component\Console\Output\OutputInterface
Open

                $output->writeln("<comment>-> " . $element['name'] . " (v" . $element['version'] . " " . $element['language'] . ") unpublished</comment>");

Call to undeclared method \OpenOrchestra\BackofficeBundle\Command\OrchestraUnpublishElementCommand::getElementType
Open

            ->setName('orchestra:unpublish:'.$this->getElementType())

Call to undeclared method \OpenOrchestra\BackofficeBundle\Command\OrchestraUnpublishElementCommand::getContainer
Open

            $siteCollection = $this->getContainer()->get('open_orchestra_model.repository.site')->findByDeleted(false);

Call to undeclared method \OpenOrchestra\BackofficeBundle\Command\OrchestraUnpublishElementCommand::getElementType
Open

        $output->writeln("\n<info>Unpublishing ".$this->getElementType()."s for siteId " . $site->getSiteId() . "</info>");

Call to undeclared method \OpenOrchestra\BackofficeBundle\Command\OrchestraUnpublishElementCommand::getElementType
Open

            ->setDescription('Unpublish all eligibles '.$this->getElementType().'s')

Call to undeclared method \OpenOrchestra\BackofficeBundle\Command\OrchestraUnpublishElementCommand::getManagerName
Open

        $elementPublisherManager = $this->getContainer()->get($this->getManagerName());

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

        $output->writeln("\n<info>Unpublishing ".$this->getElementType()."s for siteId " . $site->getSiteId() . "</info>");

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        if ($siteId = $input->getOption('siteId')) {
            $site = $this->getContainer()->get('open_orchestra_model.repository.site')->findOneBySiteId($siteId);
            if ($site) {
BackofficeBundle/Command/OrchestraPublishElementCommand.php on lines 36..59

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 158.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

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

        $elementPublisherManager = $this->getContainer()->get($this->getManagerName());

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

Blank line found at end of control structure
Open


Blank line found at end of control structure
Open


Line exceeds 120 characters; contains 123 characters
Open

        $output->writeln("\n<info>Unpublishing ".$this->getElementType()."s for siteId " . $site->getSiteId() . "</info>");

Line exceeds 120 characters; contains 155 characters
Open

                $output->writeln("<comment>-> " . $element['name'] . " (v" . $element['version'] . " " . $element['language'] . ") unpublished</comment>");

Line exceeds 120 characters; contains 143 characters
Open

            ->addOption('siteId', null, InputOption::VALUE_REQUIRED, 'If set, will unpublish '.$this->getElementType().'s only for this site');

There are no issues that match your filters.

Category
Status