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 |
||
| 20 | class RegistryTest extends \PHPUnit_Framework_TestCase |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * @var Registry |
||
| 24 | */ |
||
| 25 | private $registry; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var ServiceInterface[] |
||
| 29 | */ |
||
| 30 | private $services; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * {@inheritdoc} |
||
| 34 | */ |
||
| 35 | protected function setUp() |
||
| 40 | |||
| 41 | public function testInheritance() |
||
| 48 | |||
| 49 | public function testDefaultState() |
||
| 56 | |||
| 57 | public function testInitialState() |
||
| 62 | |||
| 63 | public function testOffsetExists() |
||
| 71 | |||
| 72 | public function testOffsetGet() |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @expectedException \Lug\Component\Registry\Exception\ServiceNotFoundException |
||
| 81 | * @expectedExceptionMessage The service "baz" could not be found. |
||
| 82 | */ |
||
| 83 | public function testOffsetGetWithNonExistingService() |
||
| 87 | |||
| 88 | public function testOffsetSet() |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @expectedException \Lug\Component\Registry\Exception\ServiceAlreadyExistsException |
||
| 99 | * @expectedExceptionMessage The service "foo" already exists. |
||
| 100 | */ |
||
| 101 | public function testOffsetSetWithExistingService() |
||
| 105 | |||
| 106 | /** |
||
| 107 | * @expectedException \Lug\Component\Registry\Exception\InvalidServiceException |
||
| 108 | * @expectedExceptionMessage The service for the registry "Lug\Component\Registry\Model\Registry" must be an instance of "Lug\Component\Registry\Tests\Model\ServiceInterface", got "string". |
||
| 109 | */ |
||
| 110 | public function testOffsetSetWithScalarService() |
||
| 114 | |||
| 115 | /** |
||
| 116 | * @expectedException \Lug\Component\Registry\Exception\InvalidServiceException |
||
| 117 | * @expectedExceptionMessage The service for the registry "Lug\Component\Registry\Model\Registry" must be an instance of "Lug\Component\Registry\Tests\Model\ServiceInterface", got "stdClass". |
||
| 118 | */ |
||
| 119 | public function testOffsetSetWithInvalidService() |
||
| 123 | |||
| 124 | View Code Duplication | public function testOffsetUnset() |
|
| 135 | |||
| 136 | /** |
||
| 137 | * @expectedException \Lug\Component\Registry\Exception\ServiceNotFoundException |
||
| 138 | * @expectedExceptionMessage The service "baz" could not be found. |
||
| 139 | */ |
||
| 140 | public function testOffsetUnsetWithNonExistingService() |
||
| 144 | |||
| 145 | /** |
||
| 146 | * @return \PHPUnit_Framework_MockObject_MockObject|ServiceInterface |
||
| 147 | */ |
||
| 148 | private function createServiceMock() |
||
| 152 | } |
||
| 153 | |||
| 160 |
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..