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 CategoryTranslationMessageSpec extends ObjectBehavior |
||
11 | { |
||
12 | function it_is_initializable() |
||
13 | { |
||
14 | $this->shouldHaveType(CategoryTranslationMessage::class); |
||
15 | } |
||
16 | |||
17 | function it_should_build() |
||
18 | { |
||
19 | $this->setTitle('Category alpha'); |
||
20 | $this->setDescription('Some information'); |
||
21 | |||
22 | $data = [ |
||
23 | 'title' => 'Category alpha', |
||
24 | 'description' => 'Some information', |
||
25 | ]; |
||
26 | |||
27 | $this->build()->shouldReturn($data); |
||
28 | } |
||
29 | |||
30 | function it_should_create_from_category_translation(CategoryTranslation $translation) |
||
31 | { |
||
32 | $translation->getLocale()->willReturn('en'); |
||
33 | $translation->getTitle()->willReturn('Big title'); |
||
34 | $translation->getDescription()->willReturn('Long description'); |
||
35 | |||
36 | $message = new CategoryTranslationMessage(); |
||
37 | $message->setLocale('en'); |
||
38 | $message->setTitle('Big title'); |
||
39 | $message->setDescription('Long description'); |
||
40 | |||
41 | $this::createFromCategoryTranslation($translation)->shouldBeLike($message); |
||
42 | } |
||
43 | } |
||
44 |