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 |
||
8 | class CallbackTransformerSpec extends ObjectBehavior |
||
9 | { |
||
10 | function let() |
||
11 | { |
||
12 | $this->beConstructedWith('array_reverse'); |
||
13 | } |
||
14 | |||
15 | function it_is_initializable() |
||
16 | { |
||
17 | $this->shouldHaveType('Extraload\Transformer\CallbackTransformer'); |
||
18 | } |
||
19 | |||
20 | function it_implements_transformer_interface() |
||
21 | { |
||
22 | $this->shouldImplement('Extraload\Transformer\TransformerInterface'); |
||
23 | } |
||
24 | |||
25 | function it_transforms_data_using_callback() |
||
26 | { |
||
27 | $this->transform(['foo', 'bar'])->shouldReturn(['bar', 'foo']); |
||
28 | } |
||
29 | } |
||
30 |