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 |
||
| 19 | class FrontRenderTest extends PHPUnit_Framework_TestCase |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * @var string TEMPLATE_PATH |
||
| 23 | */ |
||
| 24 | const TEMPLATE_PATH = 'Template'; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var string TEMPLATE |
||
| 28 | */ |
||
| 29 | const TEMPLATE = 'index.html.twig'; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var string FAILED_TEMPLATE |
||
| 33 | */ |
||
| 34 | const FAILED_TEMPLATE = 'failed.html.twig'; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var string FAILED_PATH |
||
| 38 | */ |
||
| 39 | const FAILED_PATH = 'failedPath.html.twig'; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var EventDispatcher |
||
| 43 | */ |
||
| 44 | protected $eventDispatcher; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @var Twig_Loader_Filesystem |
||
| 48 | */ |
||
| 49 | protected $twigLoader; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @var Twig_Environment |
||
| 53 | */ |
||
| 54 | protected $twigEnvironment; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @var RenderSubscriber |
||
| 58 | */ |
||
| 59 | protected $renderSubscriber; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @var TemplateNameParser |
||
| 63 | */ |
||
| 64 | protected $templateNameParser; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @var FileLocator |
||
| 68 | */ |
||
| 69 | protected $fileLocator; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @var TwigEngine |
||
| 73 | */ |
||
| 74 | protected $engine; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @var FrontRender |
||
| 78 | */ |
||
| 79 | protected $frontRender; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @var LexerManager |
||
| 83 | */ |
||
| 84 | protected $lexerManager; |
||
| 85 | |||
| 86 | /** |
||
| 87 | * Set up the front render test |
||
| 88 | */ |
||
| 89 | public function setUp() |
||
| 106 | |||
| 107 | /** |
||
| 108 | * Test render of the template with parameter |
||
| 109 | */ |
||
| 110 | View Code Duplication | public function testTemplateRenderWithParameter() |
|
| 125 | |||
| 126 | /** |
||
| 127 | * Test render of the template without parameter |
||
| 128 | */ |
||
| 129 | View Code Duplication | public function testTemplateRenderWithoutParameter() |
|
| 138 | |||
| 139 | /** |
||
| 140 | * Test on the update of lexer |
||
| 141 | * |
||
| 142 | * @dataProvider lexerTags |
||
| 143 | * |
||
| 144 | * @param string $oldTags |
||
| 145 | * @param string $newTags |
||
| 146 | */ |
||
| 147 | public function testSetLexer($oldTags, $newTags) |
||
| 169 | |||
| 170 | /** |
||
| 171 | * Test on the failed template |
||
| 172 | * |
||
| 173 | * @expectedException Twig_Error_Syntax |
||
| 174 | */ |
||
| 175 | public function testExceptionOnSyntax() |
||
| 181 | |||
| 182 | /** |
||
| 183 | * Test when the template doesn't exist |
||
| 184 | * |
||
| 185 | * @expectedException InvalidArgumentException |
||
| 186 | */ |
||
| 187 | public function testExceptionOnFailedPath() |
||
| 193 | |||
| 194 | /** |
||
| 195 | * Test when the template path is empty |
||
| 196 | * |
||
| 197 | * @expectedException Chris\Bundle\FrontRenderBundle\Exception\FrontRenderException |
||
| 198 | */ |
||
| 199 | public function testExceptionOnEmptyPath() |
||
| 205 | |||
| 206 | /** |
||
| 207 | * Provide the lexer tags |
||
| 208 | * |
||
| 209 | * @return array |
||
| 210 | */ |
||
| 211 | public function lexerTags() |
||
| 220 | } |
||
| 221 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..