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 LocationSpec extends ObjectBehavior |
||
| 11 | { |
||
| 12 | function it_is_initializable() |
||
| 13 | { |
||
| 14 | $this->shouldHaveType(Location::class); |
||
| 15 | } |
||
| 16 | |||
| 17 | function let() |
||
| 18 | { |
||
| 19 | $translation = [ |
||
| 20 | 'title' => 'Some location', |
||
| 21 | 'openingHours' => '24/7', |
||
| 22 | ]; |
||
| 23 | |||
| 24 | $data = [ |
||
| 25 | 'id' => '3', |
||
| 26 | 'tel' => '+1 123 456 78 90', |
||
| 27 | 'fax' => '+2 456 111 78 90', |
||
| 28 | 'mail' => '[email protected]', |
||
| 29 | 'address' => '88 St Patrick St', |
||
| 30 | 'postalCode' => 'M5T 1V1', |
||
| 31 | 'town' => 'City', |
||
| 32 | 'latitude' => '43.6527222', |
||
| 33 | 'longitude' => '-79.3918831', |
||
| 34 | 'country' => 'Canada', |
||
| 35 | 'defaultLocation' => 0, |
||
| 36 | 'dataParent' => '11', |
||
| 37 | 'translations' => ['en' => $translation], |
||
| 38 | 'inheritance_status' => 'overridden', |
||
| 39 | ]; |
||
| 40 | |||
| 41 | $this->beConstructedWith($data); |
||
| 42 | } |
||
| 43 | |||
| 44 | function it_should_be_hydrated() |
||
| 45 | { |
||
| 46 | $this->getId()->shouldReturn(3); |
||
| 47 | $this->getTel()->shouldReturn('+1 123 456 78 90'); |
||
| 48 | $this->getFax()->shouldReturn('+2 456 111 78 90'); |
||
| 49 | $this->getMail()->shouldReturn('[email protected]'); |
||
| 50 | $this->getAddress()->shouldReturn('88 St Patrick St'); |
||
| 51 | $this->getPostalCode()->shouldReturn('M5T 1V1'); |
||
| 52 | $this->getTown()->shouldReturn('City'); |
||
| 53 | $this->getLatitude()->shouldReturn('43.6527222'); |
||
| 54 | $this->getLongitude()->shouldReturn('-79.3918831'); |
||
| 55 | $this->getCountry()->shouldReturn('Canada'); |
||
| 56 | $this->isDefaultLocation()->shouldReturn(false); |
||
| 57 | $this->getDataParentId()->shouldReturn(11); |
||
| 58 | $this->getTranslations()->shouldHaveCount(1); |
||
| 59 | $this->getInheritanceStatus()->shouldReturn(InheritanceStatuses::OVERRIDDEN); |
||
| 60 | } |
||
| 61 | } |
||
| 62 |