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 |
||
9 | class CompanySpec extends ObjectBehavior |
||
10 | { |
||
11 | function it_is_initializable() |
||
12 | { |
||
13 | $this->shouldHaveType(Company::class); |
||
14 | } |
||
15 | |||
16 | function let() |
||
17 | { |
||
18 | $data = [ |
||
19 | 'id' => '4', |
||
20 | 'companyName' => 'First company', |
||
21 | 'parent' => '1', |
||
22 | ]; |
||
23 | |||
24 | $this->beConstructedWith($data); |
||
25 | } |
||
26 | |||
27 | function it_should_be_hydrated() |
||
28 | { |
||
29 | $this->getId()->shouldReturn(4); |
||
30 | $this->getName()->shouldReturn('First company'); |
||
31 | $this->getParentId()->shouldReturn(1); |
||
32 | } |
||
33 | } |
||
34 |