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 |
||
| 18 | class SameSubnetStrategyTest extends WebTestCase |
||
| 19 | { |
||
| 20 | protected $strategy; |
||
| 21 | /** @var Client */ |
||
| 22 | protected $client; |
||
| 23 | protected $propertyKey; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * UnitTest Starts this on reach test |
||
| 27 | * @return void |
||
| 28 | */ |
||
| 29 | View Code Duplication | public function setUp() |
|
| 41 | |||
| 42 | /** |
||
| 43 | * @covers \Graviton\SecurityBundle\Authentication\Strategies\SameSubnetStrategy::apply |
||
| 44 | * @covers \Graviton\SecurityBundle\Authentication\Strategies\AbstractHttpStrategy::extractFieldInfo |
||
| 45 | * @covers \Graviton\SecurityBundle\Authentication\Strategies\AbstractHttpStrategy::validateField |
||
| 46 | * |
||
| 47 | * @return void |
||
| 48 | */ |
||
| 49 | public function testApplyHeader() |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @covers \Graviton\SecurityBundle\Authentication\Strategies\SameSubnetStrategy::apply |
||
| 60 | * @covers \Graviton\SecurityBundle\Authentication\Strategies\AbstractHttpStrategy::extractFieldInfo |
||
| 61 | * @covers \Graviton\SecurityBundle\Authentication\Strategies\AbstractHttpStrategy::validateField |
||
| 62 | * |
||
| 63 | * @return void |
||
| 64 | */ |
||
| 65 | public function testApplyHeaderReturnEmpty() |
||
| 73 | } |
||
| 74 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: