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 CategoryPostMessageSpec extends ObjectBehavior |
||
| 11 | { |
||
| 12 | function it_is_initializable() |
||
| 13 | { |
||
| 14 | $this->shouldHaveType(CategoryPostMessage::class); |
||
| 15 | } |
||
| 16 | |||
| 17 | function it_should_build() |
||
| 18 | { |
||
| 19 | $translation = new CategoryTranslationMessage(); |
||
| 20 | $translation->setLocale('en'); |
||
| 21 | $translation->setTitle('English title'); |
||
| 22 | $translation->setDescription('English description'); |
||
| 23 | |||
| 24 | $this->setParentRootId(11); |
||
| 25 | $this->setEnabled(true); |
||
| 26 | $this->addTranslation($translation); |
||
| 27 | |||
| 28 | $transData = [ |
||
| 29 | 'title' => 'English title', |
||
| 30 | 'description' => 'English description', |
||
| 31 | ]; |
||
| 32 | |||
| 33 | $data = [ |
||
| 34 | 'parentRootId' => 11, |
||
| 35 | 'enabled' => true, |
||
| 36 | 'translations' => ['en' => $transData], |
||
| 37 | ]; |
||
| 38 | |||
| 39 | $this->build()->shouldReturn($data); |
||
| 40 | } |
||
| 41 | } |
||
| 42 |