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 CategorySpec extends ObjectBehavior |
||
| 11 | { |
||
| 12 | function it_is_initializable() |
||
| 13 | { |
||
| 14 | $this->shouldHaveType(Category::class); |
||
| 15 | } |
||
| 16 | |||
| 17 | function let() |
||
| 18 | { |
||
| 19 | $translation = [ |
||
| 20 | 'locale' => 'en', |
||
| 21 | 'title' => 'English translation', |
||
| 22 | 'description' => 'Big text', |
||
| 23 | ]; |
||
| 24 | |||
| 25 | $data = [ |
||
| 26 | 'id' => '3', |
||
| 27 | 'translations' => ['en' => $translation], |
||
| 28 | 'enabled' => 1, |
||
| 29 | 'dataParent' => '11', |
||
| 30 | 'parentRootId' => '123', |
||
| 31 | 'createdAt' => ['date' => '2011-05-19 20:46:21.000000', 'timezone_type' => 3, 'timezone' => 'UTC'], |
||
| 32 | 'updatedAt' => ['date' => '2016-01-11 00:00:00.000000', 'timezone_type' => 3, 'timezone' => 'UTC'], |
||
| 33 | 'inheritance_status' => 'none', |
||
| 34 | ]; |
||
| 35 | |||
| 36 | $this->beConstructedWith($data); |
||
| 37 | } |
||
| 38 | |||
| 39 | function it_should_be_hydrated() |
||
| 40 | { |
||
| 41 | $this->getId()->shouldReturn(3); |
||
| 42 | $this->getTranslations()->shouldHaveCount(1); |
||
| 43 | $this->isEnabled()->shouldReturn(true); |
||
| 44 | $this->getDataParentId()->shouldReturn(11); |
||
| 45 | $this->getParentRootId()->shouldReturn(123); |
||
| 46 | $this->getCreatedAt()->shouldBeLike(new \DateTime('2011-05-19 20:46:21')); |
||
| 47 | $this->getUpdatedAt()->shouldBeLike(new \DateTime('2016-01-11 00:00:00')); |
||
| 48 | $this->getInheritanceStatus()->shouldReturn(InheritanceStatuses::NONE); |
||
| 49 | } |
||
| 50 | } |
||
| 51 |