UseCaseFeatureContext   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 100 %

Coupling/Cohesion

Components 2
Dependencies 7

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A iCreateUsecaseWithIdForDomain() 9 9 1
A iShouldSeeNewUsecaseInDomain() 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 Hexarchium\CoreDomain\Model\Domain\DomainId;
3
use Hexarchium\CoreDomain\Model\Domain\Repository\DomainRepositoryInterface;
4
use Hexarchium\CoreDomain\Model\Domain\UseCase\UseCaseId;
5
use Hexarchium\CoreDomain\UseCase\CreateUseCase\Command;
6
use Hexarchium\CoreDomain\UseCase\CreateUseCase\UseCase;
7
use PHPUnit_Framework_Assert as Assert;
8
9
/**
10
 * Copyright
11
 */
12 View Code Duplication
class UseCaseFeatureContext 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...
13
{
14
    /** @var UseCase */
15
    private $useCase;
16
17
    /** @var DomainRepositoryInterface */
18
    private $domainRepository;
19
20
    /**
21
     * UseCaseFeatureContext constructor.
22
     *
23
     * @param UseCase $useCase
24
     * @param DomainRepositoryInterface $domainRepository
25
     */
26
    public function __construct(UseCase $useCase, DomainRepositoryInterface $domainRepository)
27
    {
28
        $this->useCase = $useCase;
29
        $this->domainRepository = $domainRepository;
30
    }
31
32
    /**
33
     * @When I create usecase with :arg1 and type :arg2 id for :arg3 domain
34
     */
35
    public function iCreateUsecaseWithIdForDomain($arg1, $arg2, $arg3)
36
    {
37
        $command = new Command(
38
            new UseCaseId($arg1),
39
            new DomainId($arg3),
40
            $arg2
41
        );
42
        $this->useCase->handle($command);
43
    }
44
45
    /**
46
     * @Then I should see new usecase in :arg1 domain
47
     */
48
    public function iShouldSeeNewUsecaseInDomain($arg1)
49
    {
50
        /** @var \Hexarchium\CoreDomain\Model\Domain\Entity\Domain $domain */
51
        $domain = $this->domainRepository->getById(new DomainId($arg1));
52
        $counter = 0;
53
        foreach ($domain->pullEvents() as $event) {
54
            if ($event instanceof \Hexarchium\CoreDomain\Model\Domain\Events\UseCaseAdded) {
55
                $counter++;
56
            }
57
        }
58
        Assert::assertTrue($counter > 0);
59
    }
60
}
61