PublishElementCommandTrait::executeUnpublish()   B
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 26
Code Lines 17

Duplication

Lines 26
Ratio 100 %

Importance

Changes 0
Metric Value
dl 26
loc 26
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 17
nc 2
nop 4
1
<?php
2
3
namespace OpenOrchestra\FunctionalTests\BackofficeBundle\Command;
4
5
use Symfony\Component\Console\Tester\CommandTester;
6
7
/**
8
 * Class PublishElementCommandTrait
9
 */
10
trait PublishElementCommandTrait
11
{
12
    /**
13
     * @param string $siteId
14
     * @param string $commandName
15
     * @param string $repositoryName
16
     * @param string $entityName
17
     */
18 View Code Duplication
    public function executePublish($siteId, $commandName, $repositoryName, $entityName)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
19
    {
20
        $command = $this->application->find($commandName);
0 ignored issues
show
Bug introduced by
The property application does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
21
        $commandTester = new CommandTester($command);
22
23
        $site = static::$kernel->getContainer()->get('open_orchestra_model.repository.site')->findOneBySiteId($siteId);
24
        $fromStatus = static::$kernel->getContainer()->get('open_orchestra_model.repository.status')
25
            ->findByAutoPublishFrom();
26
        $elements = static::$kernel->getContainer()->get($repositoryName)
27
            ->findElementToAutoPublish($site->getSiteId(), $fromStatus);
28
29
        $commandTester->execute(array('command' => $command->getName()));
30
        $this->assertRegExp(
0 ignored issues
show
Bug introduced by
It seems like assertRegExp() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
31
            '/Publishing '.$entityName.'s for siteId ' . $siteId . '/',
32
            $commandTester->getDisplay()
33
        );
34
35
        foreach ($elements as $element) {
36
            $this->assertRegExp(
0 ignored issues
show
Bug introduced by
It seems like assertRegExp() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
37
                '/-> ' . $element->getName() . ' \(v' . $element->getVersion() . ' ' . $element->getLanguage() . '\) published/',
38
                $commandTester->getDisplay()
39
            );
40
        }
41
42
        $this->assertRegExp('/Done./', $commandTester->getDisplay());
0 ignored issues
show
Bug introduced by
It seems like assertRegExp() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
43
    }
44
    /**
45
     * @param string $siteId
46
     * @param string $commandName
47
     * @param string $repositoryName
48
     * @param string $entityName
49
     */
50 View Code Duplication
    public function executeUnpublish($siteId, $commandName, $repositoryName, $entityName)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
51
    {
52
        $command = $this->application->find($commandName);
53
        $commandTester = new CommandTester($command);
54
55
        $site = static::$kernel->getContainer()->get('open_orchestra_model.repository.site')->findOneBySiteId($siteId);
56
        $fromStatus = static::$kernel->getContainer()->get('open_orchestra_model.repository.status')
57
            ->findOneByPublished();
58
        $elements = static::$kernel->getContainer()->get($repositoryName)
59
            ->findElementToAutoUnpublish($site->getSiteId(), $fromStatus);
60
61
        $commandTester->execute(array('command' => $command->getName()));
62
        $this->assertRegExp(
0 ignored issues
show
Bug introduced by
It seems like assertRegExp() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
63
            '/Unpublishing '.$entityName.'s for siteId ' . $siteId . '/',
64
            $commandTester->getDisplay()
65
        );
66
67
        foreach ($elements as $element) {
68
            $this->assertRegExp(
0 ignored issues
show
Bug introduced by
It seems like assertRegExp() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
69
                '/-> ' . $element->getName() . ' \(v' . $element->getVersion() . ' ' . $element->getLanguage() . '\) unpublished/',
70
                $commandTester->getDisplay()
71
            );
72
        }
73
74
        $this->assertRegExp('/Done./', $commandTester->getDisplay());
0 ignored issues
show
Bug introduced by
It seems like assertRegExp() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
75
    }
76
}
77