Conditions | 1 |
Paths | 1 |
Total Lines | 59 |
Code Lines | 38 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
55 | public function testAddFieldNoType() |
||
56 | { |
||
57 | $fieldDescriptionCollection = $this->prophesize(FieldDescriptionCollection::class); |
||
58 | $fieldDescription = $this->prophesize(FieldDescriptionInterface::class); |
||
59 | $admin = $this->prophesize(AdminInterface::class); |
||
60 | $typeGuess = $this->prophesize(TypeGuess::class); |
||
|
|||
61 | $modelManager = $this->prophesize(ModelManager::class); |
||
62 | $typeGuess = $this->prophesize(TypeGuess::class); |
||
63 | |||
64 | $admin->getClass()->willReturn($adminClassReturn = 'FakeClass')->shouldBeCalledTimes(2); |
||
65 | |||
66 | $fieldDescription->getName()->willReturn($fieldDescriptionNameReturn = 'FakeName') |
||
67 | ->shouldBeCalledTimes(4); |
||
68 | |||
69 | $admin->getModelManager()->willReturn($modelManager->reveal())->shouldBeCalledTimes(2); |
||
70 | |||
71 | $typeGuess->getType()->willReturn($typeGuessReturn = 'fakeType')->shouldBeCalledTimes(1); |
||
72 | |||
73 | $this->guesser->guessType($adminClassReturn, $fieldDescriptionNameReturn, $modelManager) |
||
74 | ->willReturn($typeGuess) |
||
75 | ->shouldBeCalledTimes(1); |
||
76 | |||
77 | $fieldDescription->setType($typeGuessReturn)->shouldBeCalledTimes(1); |
||
78 | |||
79 | $fieldDescription->setAdmin($admin)->shouldBeCalledTimes(1); |
||
80 | |||
81 | $modelManager->hasMetadata($adminClassReturn)->willReturn(false)->shouldBeCalledTimes(1); |
||
82 | |||
83 | $fieldDescription->getType()->willReturn(true)->shouldBeCalledTimes(1); |
||
84 | |||
85 | $fieldDescription->setOption('code', $fieldDescriptionNameReturn)->shouldBeCalledTimes(1); |
||
86 | $fieldDescription->setOption('label', $fieldDescriptionNameReturn)->shouldBeCalledTimes(1); |
||
87 | |||
88 | $fieldDescription->getOption('code', $fieldDescriptionNameReturn) |
||
89 | ->willReturn($fieldDescriptionNameReturn) |
||
90 | ->shouldBeCalledTimes(1); |
||
91 | |||
92 | $fieldDescription->getOption('label', $fieldDescriptionNameReturn) |
||
93 | ->willReturn($fieldDescriptionNameReturn) |
||
94 | ->shouldBeCalledTimes(1); |
||
95 | |||
96 | $fieldDescription->getTemplate()->willReturn(true)->shouldBeCalledTimes(1); |
||
97 | |||
98 | $fieldDescription->getMappingType()->willReturn(ClassMetadata::MANY_TO_ONE)->shouldBeCalledTimes(1); |
||
99 | |||
100 | $admin->attachAdminClass($fieldDescription)->shouldBeCalledTimes(1); |
||
101 | |||
102 | $admin->addShowFieldDescription($fieldDescriptionNameReturn, $fieldDescription) |
||
103 | ->shouldBeCalledTimes(1); |
||
104 | |||
105 | $fieldDescriptionCollection->add($fieldDescription)->shouldBeCalledTimes(1); |
||
106 | |||
107 | $this->showBuilder->addField( |
||
108 | $fieldDescriptionCollection->reveal(), |
||
109 | null, |
||
110 | $fieldDescription->reveal(), |
||
111 | $admin->reveal() |
||
112 | ); |
||
113 | } |
||
114 | |||
200 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.