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 FieldSpec extends ObjectBehavior |
||
| 11 | { |
||
| 12 | function it_is_initializable() |
||
| 13 | { |
||
| 14 | $this->shouldHaveType(Field::class); |
||
| 15 | } |
||
| 16 | |||
| 17 | function let() |
||
| 18 | { |
||
| 19 | $transData = ['value' => 'Required field']; |
||
| 20 | |||
| 21 | $data = [ |
||
| 22 | 'id' => '7', |
||
| 23 | 'token' => 'required-field', |
||
| 24 | 'description' => 'Some information about it', |
||
| 25 | 'translations' => ['en' => $transData], |
||
| 26 | 'dataParent' => '8', |
||
| 27 | 'createdAt' => ['date' => '2011-05-19 20:46:21.000000', 'timezone_type' => 3, 'timezone' => 'UTC'], |
||
| 28 | 'updatedAt' => ['date' => '2016-01-11 00:00:00.000000', 'timezone_type' => 3, 'timezone' => 'UTC'], |
||
| 29 | 'inheritance_status' => 'inherited', |
||
| 30 | ]; |
||
| 31 | |||
| 32 | $this->beConstructedWith($data); |
||
| 33 | } |
||
| 34 | |||
| 35 | function it_should_be_hydrated() |
||
| 36 | { |
||
| 37 | $this->getId()->shouldReturn(7); |
||
| 38 | $this->getToken()->shouldReturn('required-field'); |
||
| 39 | $this->getDescription()->shouldReturn('Some information about it'); |
||
| 40 | $this->getTranslations()->shouldHaveCount(1); |
||
| 41 | $this->getDataParentId()->shouldReturn(8); |
||
| 42 | $this->getCreatedAt()->shouldBeLike(new \DateTime('2011-05-19 20:46:21')); |
||
| 43 | $this->getUpdatedAt()->shouldBeLike(new \DateTime('2016-01-11 00:00:00')); |
||
| 44 | $this->getInheritanceStatus()->shouldReturn(InheritanceStatuses::INHERITED); |
||
| 45 | } |
||
| 46 | } |
||
| 47 |