Completed
Push — master ( 12f683...a4b1f6 )
by Miro
02:18
created

GithubIssueSourceSpec::let()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 27
rs 8.8571
cc 1
eloc 23
nc 1
nop 8

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
namespace spec\DevBoardLib\GithubObjectApiFacade\Repo\Issue;
3
4
use DateTime;
5
use DevBoardLib\GithubCore\Issue\GithubIssueId;
6
use DevBoardLib\GithubCore\Issue\State\GithubIssueOpenState;
7
use DevBoardLib\GithubCore\Milestone\GithubMilestone;
8
use DevBoardLib\GithubCore\Milestone\GithubMilestoneId;
9
use DevBoardLib\GithubCore\Repo\GithubRepo;
10
use DevBoardLib\GithubCore\Repo\GithubRepoId;
11
use DevBoardLib\GithubCore\User\GithubUser;
12
use DevBoardLib\GithubCore\User\GithubUserId;
13
use PhpSpec\ObjectBehavior;
14
use Prophecy\Argument;
15
16
class GithubIssueSourceSpec extends ObjectBehavior
17
{
18
    public function it_is_initializable()
19
    {
20
        $this->shouldHaveType('DevBoardLib\GithubObjectApiFacade\Repo\Issue\GithubIssueSource');
21
        $this->shouldHaveType('DevBoardLib\GithubCore\Issue\GithubIssue');
22
    }
23
24
    public function let(
25
        GithubIssueId $id,
26
        GithubRepo $repo,
27
        GithubUser $createdByUser,
28
        GithubUser $assignedToUser = null,
29
        GithubMilestone $milestone = null,
30
        DateTime $githubCreatedAt,
31
        DateTime $githubUpdatedAt,
32
        DateTime $githubClosedAt
33
    ) {
34
        $this->beConstructedWith(
35
            $id,
36
            $repo,
37
            22,
38
            new GithubIssueOpenState(),
39
            'Issue title',
40
            'Issue body ...',
41
            $createdByUser,
42
            $assignedToUser,
43
            $milestone,
44
            123,
45
            $githubCreatedAt,
46
            $githubUpdatedAt,
47
            $githubClosedAt
48
49
        );
50
    }
51
52
    public function it_has_github_id_as_primary_key($id)
53
    {
54
        $this->getId()->shouldReturn($id);
55
    }
56
57
    public function it_holds_repo_id_it_belongs_to($repo, GithubRepoId $repoId)
58
    {
59
        $repo->getId()->willReturn($repoId);
60
        $this->getRepoId()->shouldReturn($repoId);
61
    }
62
63
    public function it_holds_repo_it_belongs_to($repo)
64
    {
65
        $this->getRepo()->shouldReturn($repo);
66
    }
67
68
    public function it_holds_issue_number()
69
    {
70
        $this->getNumber()->shouldReturn(22);
71
    }
72
73
    public function it_holds_issue_state()
74
    {
75
        $this->getState()->shouldReturnAnInstanceOf('DevBoardLib\GithubCore\Issue\State\GithubIssueState');
76
    }
77
78
    public function it_holds_title()
79
    {
80
        $this->getTitle()->shouldReturn('Issue title');
81
    }
82
83
    public function it_holds_body()
84
    {
85
        $this->getBody()->shouldReturn('Issue body ...');
86
    }
87
88
    public function it_knows_who_created_issue($createdByUser)
89
    {
90
        $this->getCreatedByUser()->shouldReturn($createdByUser);
91
    }
92
93
    public function it_knows_id_who_created_issue($createdByUser, GithubUserId $createdByUserId)
94
    {
95
        $createdByUser->getGithubUserId()->willReturn($createdByUserId);
96
        $this->getCreatedByUserId()->shouldReturn($createdByUserId);
97
    }
98
99
    public function it_knows_who_is_assigned_to_issue($assignedToUser)
100
    {
101
        $this->getAssignedToUser()->shouldReturn($assignedToUser);
102
    }
103
104
    public function it_knows_id_of_user_who_is_assigned_to_issue($assignedToUser, GithubUserId $assignedToUserId)
105
    {
106
        $assignedToUser->getGithubUserId()->willReturn($assignedToUserId);
107
108
        $this->getAssignedToUserId()->shouldReturn($assignedToUserId);
109
    }
110
111
    public function it_knows_id_of_issue_is_assigned_to_a_milestone($milestone, GithubMilestoneId $milestoneId)
112
    {
113
        $milestone->getId()->willReturn($milestoneId);
114
        $this->getMilestoneId()->shouldReturn($milestoneId);
115
    }
116
117
    public function it_knows_if_issue_is_assigned_to_a_milestone($milestone)
118
    {
119
        $this->getMilestone()->shouldReturn($milestone);
120
    }
121
122
    public function it_knows_number_of_comments_on_issue()
123
    {
124
        $this->getCommentCount()->shouldReturn(123);
125
    }
126
127
    public function it_knows_time_when_created_on_github($githubCreatedAt)
128
    {
129
        $this->getGithubCreatedAt()->shouldReturn($githubCreatedAt);
130
    }
131
132
    public function it_knows_time_when_last_updated_on_github($githubUpdatedAt)
133
    {
134
        $this->getGithubUpdatedAt()->shouldReturn($githubUpdatedAt);
135
    }
136
137
    public function it_knows_time_when_issue_was_closed($githubClosedAt)
138
    {
139
        $this->getGithubClosedAt()->shouldReturn($githubClosedAt);
140
    }
141
}
142