ModelFeatureContext   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 100 %

Coupling/Cohesion

Components 2
Dependencies 7

Importance

Changes 0
Metric Value
wmc 5
lcom 2
cbo 7
dl 47
loc 47
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A iCreateModelWithIdForDomain() 8 8 1
A iShouldSeeAddedToDomain() 12 12 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
use Helpers\Repository\DomainRepository;
3
use Hexarchium\CoreDomain\Model\Domain\DomainId;
4
use Hexarchium\CoreDomain\Model\Domain\Events\ModelAdded;
5
use Hexarchium\CoreDomain\Model\Domain\Model\ModelId;
6
use Hexarchium\CoreDomain\UseCase\CreateModel\Command;
7
use Hexarchium\CoreDomain\UseCase\CreateModel\UseCase;
8
use PHPUnit_Framework_Assert as Assert;
9
10
/**
11
 * Copyright
12
 */
13 View Code Duplication
class ModelFeatureContext implements \Behat\Behat\Context\Context
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
Duplication introduced by
This class 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...
14
{
15
    /** @var  DomainRepository */
16
    private $domainRepository;
17
    /** @var UseCase */
18
    private $useCase;
19
20
    /**
21
     * ModelFeatureContext constructor.
22
     *
23
     * @param UseCase $useCase
24
     * @param DomainRepository $domainRepository
25
     */
26
    public function __construct(UseCase $useCase, DomainRepository $domainRepository)
27
    {
28
        $this->domainRepository = $domainRepository;
29
        $this->useCase = $useCase;
30
    }
31
32
    /**
33
     * @When I create model with :arg1 id for :arg2 domain
34
     */
35
    public function iCreateModelWithIdForDomain($arg1, $arg2)
36
    {
37
        $command = new Command(
38
            new ModelId($arg1),
39
            new DomainId($arg2)
40
        );
41
        $this->useCase->handle($command);
42
    }
43
44
    /**
45
     * @Then I should see new model in :arg1 domain
46
     */
47
    public function iShouldSeeAddedToDomain($arg1)
48
    {
49
        /** @var \Hexarchium\CoreDomain\Model\Domain\Entity\Domain $domain */
50
        $domain = $this->domainRepository->getById(new DomainId($arg1));
51
        $counter = 0;
52
        foreach ($domain->pullEvents() as $event) {
53
            if ($event instanceof ModelAdded) {
54
                $counter++;
55
            }
56
        }
57
        Assert::assertTrue($counter > 0);
58
    }
59
}
60