Conditions | 1 |
Paths | 1 |
Total Lines | 68 |
Code Lines | 53 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
87 | public function testHandle() |
||
88 | { |
||
89 | $grid = $this->createGridMock(); |
||
90 | $grid |
||
|
|||
91 | ->expects($this->once()) |
||
92 | ->method('getResource') |
||
93 | ->will($this->returnValue($resource = $this->createResourceMock())); |
||
94 | |||
95 | $grid |
||
96 | ->expects($this->once()) |
||
97 | ->method('getOptions') |
||
98 | ->will($this->returnValue($options = ['foo' => 'bar'])); |
||
99 | |||
100 | $resource |
||
101 | ->expects($this->once()) |
||
102 | ->method('getName') |
||
103 | ->will($this->returnValue($name = 'name')); |
||
104 | |||
105 | $this->repositoryRegistry |
||
106 | ->expects($this->once()) |
||
107 | ->method('offsetGet') |
||
108 | ->with($this->identicalTo($name)) |
||
109 | ->will($this->returnValue($repository = $this->createRepositoryMock())); |
||
110 | |||
111 | $repository |
||
112 | ->expects($this->once()) |
||
113 | ->method('createDataSourceBuilder') |
||
114 | ->with($this->identicalTo($options)) |
||
115 | ->will($this->returnValue($builder = $this->createDataSourceBuilderMock())); |
||
116 | |||
117 | $this->filterer |
||
118 | ->expects($this->once()) |
||
119 | ->method('filter') |
||
120 | ->with( |
||
121 | $this->identicalTo($builder), |
||
122 | $this->identicalTo($grid), |
||
123 | $this->identicalTo($filters = ['filter']) |
||
124 | ); |
||
125 | |||
126 | $this->sorter |
||
127 | ->expects($this->once()) |
||
128 | ->method('sort') |
||
129 | ->with( |
||
130 | $this->identicalTo($builder), |
||
131 | $this->identicalTo($grid), |
||
132 | $this->identicalTo($sorting = ['sort']) |
||
133 | ); |
||
134 | |||
135 | $this->slicer |
||
136 | ->expects($this->once()) |
||
137 | ->method('slice') |
||
138 | ->with( |
||
139 | $this->identicalTo($builder), |
||
140 | $this->identicalTo($grid), |
||
141 | $this->identicalTo($slicing = ['slice']) |
||
142 | ); |
||
143 | |||
144 | $this->gridViewFactory |
||
145 | ->expects($this->once()) |
||
146 | ->method('create') |
||
147 | ->with( |
||
148 | $this->identicalTo($grid), |
||
149 | $this->identicalTo($builder) |
||
150 | ) |
||
151 | ->will($this->returnValue($view = $this->createGridViewMock())); |
||
152 | |||
153 | $this->assertSame($view, $this->handler->handle($grid, $filters, $sorting, $slicing)); |
||
154 | } |
||
155 | |||
236 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: