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 |
||
10 | class UserPostMessageSpec extends ObjectBehavior |
||
11 | { |
||
12 | function it_is_initializable() |
||
13 | { |
||
14 | $this->shouldHaveType(UserPostMessage::class); |
||
15 | } |
||
16 | |||
17 | function it_should_build() |
||
18 | { |
||
19 | $this->setFirstName('Example'); |
||
20 | $this->setLastName(''); |
||
21 | $this->setEmail('[email protected]'); |
||
22 | $this->setPlainPassword('12345'); |
||
23 | $this->setPhone('+1 234 567 890'); |
||
24 | $this->setDefaultLocale('en'); |
||
25 | |||
26 | $data = [ |
||
27 | 'firstName' => 'Example', |
||
28 | 'lastName' => '', |
||
29 | 'email' => '[email protected]', |
||
30 | 'plainPassword' => '12345', |
||
31 | 'phone' => '+1 234 567 890', |
||
32 | 'defaultLocale' => 'en', |
||
33 | ]; |
||
34 | |||
35 | $this->build()->shouldReturn($data); |
||
36 | } |
||
37 | |||
38 | function it_should_ask_for_plain_password() |
||
39 | { |
||
40 | $this->setFirstName('Example'); |
||
41 | $this->setLastName(''); |
||
42 | $this->setEmail('[email protected]'); |
||
43 | $this->setPhone('+1 234 567 890'); |
||
44 | $this->setDefaultLocale('en'); |
||
45 | |||
46 | $this->shouldThrow(LogicException::class)->during('build'); |
||
47 | } |
||
48 | } |
||
49 |