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 |
||
15 | class OAuthUserCreatorTest extends TestCase |
||
16 | { |
||
17 | /** |
||
18 | * @var OAuthUserCreator |
||
19 | */ |
||
20 | private $object; |
||
21 | |||
22 | /** |
||
23 | * @var EntityManager |
||
24 | */ |
||
25 | private $em; |
||
26 | |||
27 | /** |
||
28 | * @var OAuthUserFinderInterface |
||
29 | */ |
||
30 | private $finder; |
||
31 | |||
32 | /** |
||
33 | * @return \PHPUnit_Framework_MockObject_MockObject |
||
|
|||
34 | */ |
||
35 | private function getEm() |
||
43 | |||
44 | /** |
||
45 | * @return \PHPUnit_Framework_MockObject_MockObject |
||
46 | */ |
||
47 | private function getFinder() |
||
55 | |||
56 | public function setUp(): void |
||
57 | { |
||
58 | $em = $this->getEm(); |
||
59 | $finder = $this->getFinder(); |
||
60 | $object = new OAuthUserCreator($em, [[ |
||
61 | 'domain_name' => 'gmail.com', |
||
62 | 'access_levels' => ['ROLE_ADMIN'], |
||
63 | ]], User::class, $finder); |
||
64 | $this->object = $object; |
||
65 | } |
||
66 | |||
67 | public function testGetOrCreateUserReturnsNull() |
||
73 | |||
74 | View Code Duplication | public function testGetOrCreateUserReturnsUser() |
|
87 | |||
88 | View Code Duplication | public function testGetOrCreateUserCreatesCorrectUserClass() |
|
101 | |||
102 | /** |
||
103 | * @throws \ReflectionException |
||
104 | */ |
||
105 | public function testAccessLevelsReturnsNull() |
||
120 | } |
||
121 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.