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 LocationPostMessageSpec extends ObjectBehavior |
||
| 11 | { |
||
| 12 | function it_is_initializable() |
||
| 13 | { |
||
| 14 | $this->shouldHaveType(LocationPostMessage::class); |
||
| 15 | } |
||
| 16 | |||
| 17 | function it_should_build() |
||
| 18 | { |
||
| 19 | $translation = new LocationTranslationMessage(); |
||
| 20 | $translation->setLocale('en'); |
||
| 21 | $translation->setTitle('Some location'); |
||
| 22 | $translation->setOpeningHours('24/7'); |
||
| 23 | |||
| 24 | $this->setTel('+1 123 456 78 90'); |
||
| 25 | $this->setTel2('+2 456 111 78 90'); |
||
| 26 | $this->setFax('+3 111 222 78 11'); |
||
| 27 | $this->setMail('[email protected]'); |
||
| 28 | $this->setAddress('88 St Patrick St'); |
||
| 29 | $this->setPostalCode('M5T 1V1'); |
||
| 30 | $this->setTown('Toronto'); |
||
| 31 | $this->setCountry('Canada'); |
||
| 32 | $this->setAddressForGoogleMap('88 St Patrick St, Toronto, M5T 1V1, Canada'); |
||
| 33 | $this->setDefaultLocation(true); |
||
| 34 | $this->setLatitude('43.6527222'); |
||
| 35 | $this->setLongitude('-79.3918831'); |
||
| 36 | $this->addTranslation($translation); |
||
| 37 | |||
| 38 | $translationData = [ |
||
| 39 | 'title' => 'Some location', |
||
| 40 | 'openingHours' => '24/7', |
||
| 41 | ]; |
||
| 42 | |||
| 43 | $data = [ |
||
| 44 | 'tel' => '+1 123 456 78 90', |
||
| 45 | 'tel2' => '+2 456 111 78 90', |
||
| 46 | 'fax' => '+3 111 222 78 11', |
||
| 47 | 'mail' => '[email protected]', |
||
| 48 | 'address' => '88 St Patrick St', |
||
| 49 | 'postalCode' => 'M5T 1V1', |
||
| 50 | 'town' => 'Toronto', |
||
| 51 | 'country' => 'Canada', |
||
| 52 | 'addressForGoogleMap' => '88 St Patrick St, Toronto, M5T 1V1, Canada', |
||
| 53 | 'defaultLocation' => true, |
||
| 54 | 'latitude' => '43.6527222', |
||
| 55 | 'longitude' => '-79.3918831', |
||
| 56 | 'translations' => ['en' => $translationData] |
||
| 57 | ]; |
||
| 58 | |||
| 59 | $this->build()->shouldReturn($data); |
||
| 60 | } |
||
| 61 | } |
||
| 62 |