Completed
Pull Request — master (#180)
by Gorka
05:29
created

it_handles_task_priority_change()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 30
Code Lines 22

Duplication

Lines 30
Ratio 100 %

Importance

Changes 0
Metric Value
dl 30
loc 30
c 0
b 0
f 0
rs 8.8571
cc 1
eloc 22
nc 1
nop 9

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
/*
4
 * This file is part of the Kreta package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace Spec\Kreta\TaskManager\Application\Command\Project\Task;
14
15
use Kreta\TaskManager\Application\Command\Project\Task\ChangeTaskProgressCommand;
16
use Kreta\TaskManager\Application\Command\Project\Task\ChangeTaskProgressHandler;
17
use Kreta\TaskManager\Domain\Model\Organization\Organization;
18
use Kreta\TaskManager\Domain\Model\Organization\OrganizationId;
19
use Kreta\TaskManager\Domain\Model\Organization\OrganizationRepository;
20
use Kreta\TaskManager\Domain\Model\Project\Project;
21
use Kreta\TaskManager\Domain\Model\Project\ProjectId;
22
use Kreta\TaskManager\Domain\Model\Project\ProjectRepository;
23
use Kreta\TaskManager\Domain\Model\Project\Task\Task;
24
use Kreta\TaskManager\Domain\Model\Project\Task\TaskId;
25
use Kreta\TaskManager\Domain\Model\Project\Task\TaskProgress;
26
use Kreta\TaskManager\Domain\Model\Project\Task\TaskRepository;
27
use Kreta\TaskManager\Domain\Model\User\UserId;
28
use PhpSpec\ObjectBehavior;
29
use Prophecy\Argument;
30
31
class ChangeTaskProgressHandlerSpec extends ObjectBehavior
32
{
33
    function let(
34
        OrganizationRepository $organizationRepository,
35
        ProjectRepository $projectRepository,
36
        TaskRepository $taskRepository
37
    ) {
38
        $this->beConstructedWith($organizationRepository, $projectRepository, $taskRepository);
39
    }
40
41
    function it_is_initializable()
42
    {
43
        $this->shouldHaveType(ChangeTaskProgressHandler::class);
44
    }
45
46 View Code Duplication
    function it_handles_task_priority_change(
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...
47
        OrganizationRepository $organizationRepository,
48
        ProjectRepository $projectRepository,
49
        TaskRepository $taskRepository,
50
        ChangeTaskProgressCommand $command,
51
        Task $task,
52
        Project $project,
53
        ProjectId $projectId,
54
        OrganizationId $organizationId,
55
        Organization $organization
56
    ) {
57
        $command->id()->shouldBeCalled()->willReturn('task-id');
58
        $command->progress()->shouldBeCalled()->willReturn('doing');
59
        $command->editorId()->shouldBeCalled()->willReturn('editor-id');
60
61
        $taskRepository->taskOfId(Argument::type(TaskId::class))->shouldBeCalled()->willReturn($task);
62
        $task->projectId()->shouldBeCalled()->willReturn($projectId);
63
64
        $projectRepository->projectOfId($projectId)->shouldBeCalled()->willReturn($project);
65
        $project->organizationId()->shouldBeCalled()->willReturn($organizationId);
66
67
        $organizationRepository->organizationOfId($organizationId)->shouldBeCalled()->willReturn($organization);
68
        $organization->isOrganizationMember(UserId::generate('editor-id'))->shouldBeCalled()->willReturn(true);
69
70
        $task->changeProgress(Argument::type(TaskProgress::class))->shouldBeCalled();
71
72
        $taskRepository->persist(Argument::type(Task::class))->shouldBeCalled();
73
74
        $this->__invoke($command);
75
    }
76
}
77