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 CategoryArticleUnpublishMessageSpec extends ObjectBehavior |
||
| 10 | { |
||
| 11 | function it_is_initializable() |
||
| 12 | { |
||
| 13 | $this->shouldHaveType(CategoryArticleUnpublishMessage::class); |
||
| 14 | } |
||
| 15 | |||
| 16 | function it_should_build() |
||
| 17 | { |
||
| 18 | $this->setCategoryId(5); |
||
| 19 | $this->setArticleIds([1, 2]); |
||
| 20 | |||
| 21 | $data = [ |
||
| 22 | 'category' => 5, |
||
| 23 | 'articles' => [1, 2], |
||
| 24 | ]; |
||
| 25 | |||
| 26 | $this->build()->shouldReturn($data); |
||
| 27 | } |
||
| 28 | } |
||
| 29 |