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 |
||
16 | abstract class BaseTwigTest extends \PHPUnit_Framework_TestCase |
||
17 | { |
||
18 | protected static $TEMP_PATH = '/../../tmp/'; |
||
19 | protected static $RESOURCE_PATH = '/../Resources/views/'; |
||
20 | protected static $TEMPLATE_PATH = '/../Resources/templates/'; |
||
21 | |||
22 | /** |
||
23 | * @var Filesystem |
||
24 | */ |
||
25 | protected static $fileSystem; |
||
26 | /** |
||
27 | * @var \Twig_Environment |
||
28 | */ |
||
29 | protected static $environment; |
||
30 | |||
31 | /** |
||
32 | * {@inheritdoc} |
||
33 | * |
||
34 | * @throws \Twig_Error_Loader |
||
35 | */ |
||
36 | public static function setUpBeforeClass() |
||
47 | |||
48 | /** |
||
49 | * {@inheritdoc} |
||
50 | * |
||
51 | * @throws \Symfony\Component\Filesystem\Exception\IOException |
||
52 | */ |
||
53 | public static function tearDownAfterClass() |
||
59 | |||
60 | // |
||
61 | // PhpUnit |
||
62 | // |
||
63 | |||
64 | /** |
||
65 | * @return array |
||
66 | */ |
||
67 | abstract public function formatProvider(); |
||
68 | |||
69 | // |
||
70 | // Helper |
||
71 | // |
||
72 | |||
73 | /** |
||
74 | * @param string $templateName |
||
75 | * @param string $format |
||
76 | * |
||
77 | * @throws \Twig_Error_Syntax |
||
78 | * @throws \Twig_Error_Loader |
||
79 | * @throws \Symfony\Component\Filesystem\Exception\IOException |
||
80 | * @throws \InvalidArgumentException |
||
81 | * |
||
82 | * @return Spreadsheet|string |
||
83 | */ |
||
84 | protected function getDocument($templateName, $format) |
||
128 | } |
||
129 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.