Passed
Push — master ( bb3b01...ed8c75 )
by MusikAnimal
06:02
created

EditCounterController::setUpEditCounter()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 26
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
cc 5
eloc 13
nc 4
nop 2
dl 0
loc 26
ccs 0
cts 13
cp 0
crap 30
rs 8.439
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file contains only the EditCounterController class.
4
 */
5
6
namespace AppBundle\Controller;
7
8
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
9
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
10
use Symfony\Component\HttpFoundation\Request;
11
use Symfony\Component\HttpFoundation\Response;
12
use Symfony\Component\HttpFoundation\RedirectResponse;
13
use Symfony\Component\HttpFoundation\JsonResponse;
14
use Xtools\EditCounter;
15
use Xtools\EditCounterRepository;
16
use Xtools\Page;
17
use Xtools\Project;
18
use Xtools\ProjectRepository;
19
use Xtools\User;
20
21
/**
22
 * Class EditCounterController
23
 */
24
class EditCounterController extends XtoolsController
25
{
26
27
    /** @var User The user being queried. */
28
    protected $user;
29
30
    /** @var Project The project being queried. */
31
    protected $project;
32
33
    /** @var EditCounter The edit-counter, that does all the work. */
34
    protected $editCounter;
35
36
    /**
37
     * Get the tool's shortname.
38
     * @return string
39
     * @codeCoverageIgnore
40
     */
41
    public function getToolShortname()
42
    {
43
        return 'ec';
44
    }
45
46
    /**
47
     * Every action in this controller (other than 'index') calls this first.
48
     * If a response is returned, the calling action is expected to return it.
49
     * @param Request $request
50
     * @param string $key API key, as given in the reuqest. Omit this for actions
51
     *   that are public (only /api/ec actions should pass this in).
52
     * @return null|RedirectResponse
53
     */
54
    protected function setUpEditCounter(Request $request, $key = null)
55
    {
56
        // Return the EditCounter if we already have one.
57
        if ($this->editCounter instanceof EditCounter) {
0 ignored issues
show
introduced by
The condition $this->editCounter instanceof Xtools\EditCounter can never be false since $this->editCounter is always a sub-type of Xtools\EditCounter.
Loading history...
58
            return;
59
        }
60
61
        // Validate key if attempted to make internal API request.
62
        if ($key && (string)$key !== (string)$this->container->getParameter('secret')) {
63
            throw $this->createAccessDeniedException('This endpoint is for internal use only.');
64
        }
65
66
        // Will redirect to Simple Edit Counter if they have too many edits.
67
        $ret = $this->validateProjectAndUser($request, 'SimpleEditCounterResult');
68
        if ($ret instanceof RedirectResponse) {
69
            return $ret;
70
        } else {
71
            // Get Project and User instances.
72
            list($this->project, $this->user) = $ret;
73
        }
74
75
        // Instantiate EditCounter.
76
        $editCounterRepo = new EditCounterRepository();
77
        $editCounterRepo->setContainer($this->container);
78
        $this->editCounter = new EditCounter($this->project, $this->user);
79
        $this->editCounter->setRepository($editCounterRepo);
80
    }
81
82
    /**
83
     * The initial GET request that displays the search form.
84
     *
85
     * @Route("/ec", name="ec")
86
     * @Route("/ec", name="EditCounter")
87
     * @Route("/ec/", name="EditCounterSlash")
88
     * @Route("/ec/index.php", name="EditCounterIndexPhp")
89
     * @Route("/ec/{project}", name="EditCounterProject")
90
     *
91
     * @param Request $request
92
     * @return RedirectResponse|Response
93
     */
94 1
    public function indexAction(Request $request)
95
    {
96 1
        $params = $this->parseQueryParams($request);
97
98 1
        if (isset($params['project']) && isset($params['username'])) {
99
            return $this->redirectToRoute('EditCounterResult', $params);
100
        }
101
102
        // Convert the given project (or default project) into a Project instance.
103 1
        $params['project'] = $this->getProjectFromQuery($params);
104
105
        // Otherwise fall through.
106 1
        return $this->render('editCounter/index.html.twig', [
107 1
            'xtPageTitle' => 'tool-ec',
108 1
            'xtSubtitle' => 'tool-ec-desc',
109 1
            'xtPage' => 'ec',
110 1
            'project' => $params['project'],
111
        ]);
112
    }
113
114
    /**
115
     * Display all results.
116
     * @Route("/ec/{project}/{username}", name="EditCounterResult")
117
     * @param Request $request
118
     * @param string $project
119
     * @param string $username
120
     * @return Response
121
     * @codeCoverageIgnore
122
     */
123
    public function resultAction(Request $request, $project, $username)
0 ignored issues
show
Unused Code introduced by
The parameter $username is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

123
    public function resultAction(Request $request, $project, /** @scrutinizer ignore-unused */ $username)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $project is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

123
    public function resultAction(Request $request, /** @scrutinizer ignore-unused */ $project, $username)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
124
    {
125
        $ret = $this->setUpEditCounter($request);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $ret is correct as $this->setUpEditCounter($request) targeting AppBundle\Controller\Edi...ler::setUpEditCounter() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
126
        if ($ret instanceof RedirectResponse) {
127
            return $ret;
128
        }
129
130
        // Asynchronously collect some of the data that will be shown.
131
        // If multithreading is turned off, the normal getters in the views will
132
        // collect the necessary data synchronously.
133
        if ($this->container->getParameter('app.multithread')) {
134
            $this->editCounter->prepareData($this->container);
0 ignored issues
show
Unused Code introduced by
The call to Xtools\EditCounter::prepareData() has too many arguments starting with $this->container. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

134
            $this->editCounter->/** @scrutinizer ignore-call */ 
135
                                prepareData($this->container);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
135
        }
136
137
        $ret = [
138
            'xtTitle' => $this->user->getUsername() . ' - ' . $this->project->getTitle(),
139
            'xtPage' => 'ec',
140
            'user' => $this->user,
141
            'project' => $this->project,
142
            'ec' => $this->editCounter,
143
        ];
144
145
        // Used when querying for global rights changes.
146
        if ((bool)$this->container->hasParameter('app.is_labs')) {
147
            $ret['metaProject'] = ProjectRepository::getProject('metawiki', $this->container);
148
        }
149
150
        // Output the relevant format template.
151
        return $this->getFormattedReponse($request, 'editCounter/result', $ret);
152
    }
153
154
    /**
155
     * Display the general statistics section.
156
     * @Route("/ec-generalstats/{project}/{username}", name="EditCounterGeneralStats")
157
     * @param Request $request
158
     * @return Response
159
     * @codeCoverageIgnore
160
     */
161
    public function generalStatsAction(Request $request)
162
    {
163
        $ret = $this->setUpEditCounter($request);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $ret is correct as $this->setUpEditCounter($request) targeting AppBundle\Controller\Edi...ler::setUpEditCounter() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
164
        if ($ret instanceof RedirectResponse) {
165
            return $ret;
166
        }
167
168
        $isSubRequest = $this->get('request_stack')->getParentRequest() !== null;
169
        $ret = [
170
            'xtTitle' => $this->user->getUsername(),
171
            'xtPage' => 'ec',
172
            'is_sub_request' => $isSubRequest,
173
            'user' => $this->user,
174
            'project' => $this->project,
175
            'ec' => $this->editCounter,
176
        ];
177
178
        // Output the relevant format template.
179
        return $this->getFormattedReponse($request, 'editCounter/general_stats', $ret);
180
    }
181
182
    /**
183
     * Display the namespace totals section.
184
     * @Route("/ec-namespacetotals/{project}/{username}", name="EditCounterNamespaceTotals")
185
     * @param Request $request
186
     * @return Response
187
     * @codeCoverageIgnore
188
     */
189
    public function namespaceTotalsAction(Request $request)
190
    {
191
        $ret = $this->setUpEditCounter($request);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $ret is correct as $this->setUpEditCounter($request) targeting AppBundle\Controller\Edi...ler::setUpEditCounter() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
192
        if ($ret instanceof RedirectResponse) {
193
            return $ret;
194
        }
195
196
        $isSubRequest = $this->get('request_stack')->getParentRequest() !== null;
197
        $ret = [
198
            'xtTitle' => $this->user->getUsername(),
199
            'xtPage' => 'ec',
200
            'is_sub_request' => $isSubRequest,
201
            'user' => $this->user,
202
            'project' => $this->project,
203
            'ec' => $this->editCounter,
204
        ];
205
206
        // Output the relevant format template.
207
        return $this->getFormattedReponse($request, 'editCounter/namespace_totals', $ret);
208
    }
209
210
    /**
211
     * Display the timecard section.
212
     * @Route("/ec-timecard/{project}/{username}", name="EditCounterTimecard")
213
     * @param Request $request
214
     * @return Response
215
     * @codeCoverageIgnore
216
     */
217
    public function timecardAction(Request $request)
218
    {
219
        $ret = $this->setUpEditCounter($request);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $ret is correct as $this->setUpEditCounter($request) targeting AppBundle\Controller\Edi...ler::setUpEditCounter() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
220
        if ($ret instanceof RedirectResponse) {
221
            return $ret;
222
        }
223
224
        $isSubRequest = $this->get('request_stack')->getParentRequest() !== null;
225
        $optedInPage = $this->project
226
            ->getRepository()
227
            ->getPage($this->project, $this->project->userOptInPage($this->user));
228
229
        $ret = [
230
            'xtTitle' => $this->user->getUsername(),
231
            'xtPage' => 'ec',
232
            'is_sub_request' => $isSubRequest,
233
            'user' => $this->user,
234
            'project' => $this->project,
235
            'ec' => $this->editCounter,
236
            'opted_in_page' => $optedInPage,
237
        ];
238
239
        // Output the relevant format template.
240
        return $this->getFormattedReponse($request, 'editCounter/timecard', $ret);
241
    }
242
243
    /**
244
     * Display the year counts section.
245
     * @Route("/ec-yearcounts/{project}/{username}", name="EditCounterYearCounts")
246
     * @param Request $request
247
     * @return Response
248
     * @codeCoverageIgnore
249
     */
250
    public function yearcountsAction(Request $request)
251
    {
252
        $ret = $this->setUpEditCounter($request);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $ret is correct as $this->setUpEditCounter($request) targeting AppBundle\Controller\Edi...ler::setUpEditCounter() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
253
        if ($ret instanceof RedirectResponse) {
254
            return $ret;
255
        }
256
257
        $isSubRequest = $this->container->get('request_stack')->getParentRequest() !== null;
258
        $ret = [
259
            'xtTitle' => $this->user->getUsername(),
260
            'xtPage' => 'ec',
261
            'is_sub_request' => $isSubRequest,
262
            'user' => $this->user,
263
            'project' => $this->project,
264
            'ec' => $this->editCounter,
265
        ];
266
267
        // Output the relevant format template.
268
        return $this->getFormattedReponse($request, 'editCounter/yearcounts', $ret);
269
    }
270
271
    /**
272
     * Display the month counts section.
273
     * @Route("/ec-monthcounts/{project}/{username}", name="EditCounterMonthCounts")
274
     * @param Request $request
275
     * @return Response
276
     * @codeCoverageIgnore
277
     */
278
    public function monthcountsAction(Request $request)
279
    {
280
        $ret = $this->setUpEditCounter($request);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $ret is correct as $this->setUpEditCounter($request) targeting AppBundle\Controller\Edi...ler::setUpEditCounter() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
281
        if ($ret instanceof RedirectResponse) {
282
            return $ret;
283
        }
284
285
        $isSubRequest = $this->container->get('request_stack')->getParentRequest() !== null;
286
        $optedInPage = $this->project
287
            ->getRepository()
288
            ->getPage($this->project, $this->project->userOptInPage($this->user));
289
        $ret = [
290
            'xtTitle' => $this->user->getUsername(),
291
            'xtPage' => 'ec',
292
            'is_sub_request' => $isSubRequest,
293
            'user' => $this->user,
294
            'project' => $this->project,
295
            'ec' => $this->editCounter,
296
            'opted_in_page' => $optedInPage,
297
        ];
298
299
        // Output the relevant format template.
300
        return $this->getFormattedReponse($request, 'editCounter/monthcounts', $ret);
301
    }
302
303
    /**
304
     * Display the user rights changes section.
305
     * @Route("/ec-rightschanges/{project}/{username}", name="EditCounterRightsChanges")
306
     * @param Request $request
307
     * @return Response
308
     * @codeCoverageIgnore
309
     */
310
    public function rightschangesAction(Request $request)
311
    {
312
        $ret = $this->setUpEditCounter($request);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $ret is correct as $this->setUpEditCounter($request) targeting AppBundle\Controller\Edi...ler::setUpEditCounter() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
313
        if ($ret instanceof RedirectResponse) {
314
            return $ret;
315
        }
316
317
        $isSubRequest = $this->container->get('request_stack')->getParentRequest() !== null;
318
        $ret = [
319
            'xtTitle' => $this->user->getUsername(),
320
            'xtPage' => 'ec',
321
            'is_sub_request' => $isSubRequest,
322
            'user' => $this->user,
323
            'project' => $this->project,
324
            'ec' => $this->editCounter,
325
        ];
326
327
        if ((bool)$this->container->hasParameter('app.is_labs')) {
328
            $ret['metaProject'] = ProjectRepository::getProject('metawiki', $this->container);
329
        }
330
331
        // Output the relevant format template.
332
        return $this->getFormattedReponse($request, 'editCounter/rights_changes', $ret);
333
    }
334
335
    /**
336
     * Display the latest global edits section.
337
     * @Route("/ec-latestglobal/{project}/{username}", name="EditCounterLatestGlobal")
338
     * @param Request $request The HTTP request.
339
     * @return Response
340
     * @codeCoverageIgnore
341
     */
342
    public function latestglobalAction(Request $request)
343
    {
344
        $ret = $this->setUpEditCounter($request);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $ret is correct as $this->setUpEditCounter($request) targeting AppBundle\Controller\Edi...ler::setUpEditCounter() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
345
        if ($ret instanceof RedirectResponse) {
346
            return $ret;
347
        }
348
349
        $isSubRequest = $request->get('htmlonly')
350
                        || $this->container->get('request_stack')->getParentRequest() !== null;
351
        return $this->render('editCounter/latest_global.html.twig', [
352
            'xtTitle' => $this->user->getUsername(),
353
            'xtPage' => 'ec',
354
            'is_sub_request' => $isSubRequest,
355
            'user' => $this->user,
356
            'project' => $this->project,
357
            'ec' => $this->editCounter,
358
        ]);
359
    }
360
361
362
    /**
363
     * Below are internal API endpoints for the Edit Counter.
364
     * All only respond with JSON and only to requests passing in the value
365
     * of the 'secret' parameter. This should not be used in JavaScript or clientside
366
     * applications, rather only used internally.
367
     */
368
369
    /**
370
     * Get (most) of the general statistics as JSON.
371
     * @Route("/api/ec/pairdata/{project}/{username}/{key}", name="EditCounterApiPairData")
372
     * @param Request $request
373
     * @param string $key API key.
374
     * @return JsonResponse
375
     * @codeCoverageIgnore
376
     */
377
    public function pairDataApiAction(Request $request, $key)
378
    {
379
        $ret = $this->setUpEditCounter($request, $key);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $ret is correct as $this->setUpEditCounter($request, $key) targeting AppBundle\Controller\Edi...ler::setUpEditCounter() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
380
        if ($ret instanceof RedirectResponse) {
381
            return $ret;
382
        }
383
384
        return new JsonResponse(
385
            $this->editCounter->getPairData(),
386
            Response::HTTP_OK
387
        );
388
    }
389
390
    /**
391
     * Get various log counts for the user as JSON.
392
     * @Route("/api/ec/logcounts/{project}/{username}/{key}", name="EditCounterApiLogCounts")
393
     * @param Request $request
394
     * @param string $key API key.
395
     * @return JsonResponse
396
     * @codeCoverageIgnore
397
     */
398
    public function logCountsApiAction(Request $request, $key)
399
    {
400
        $ret = $this->setUpEditCounter($request, $key);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $ret is correct as $this->setUpEditCounter($request, $key) targeting AppBundle\Controller\Edi...ler::setUpEditCounter() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
401
        if ($ret instanceof RedirectResponse) {
402
            return $ret;
403
        }
404
405
        return new JsonResponse(
406
            $this->editCounter->getLogCounts(),
407
            Response::HTTP_OK
408
        );
409
    }
410
411
    /**
412
     * Get edit sizes for the user as JSON.
413
     * @Route("/api/ec/editsizes/{project}/{username}/{key}", name="EditCounterApiEditSizes")
414
     * @param Request $request
415
     * @param string $key API key.
416
     * @return JsonResponse
417
     * @codeCoverageIgnore
418
     */
419
    public function editSizesApiAction(Request $request, $key)
420
    {
421
        $ret = $this->setUpEditCounter($request, $key);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $ret is correct as $this->setUpEditCounter($request, $key) targeting AppBundle\Controller\Edi...ler::setUpEditCounter() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
422
        if ($ret instanceof RedirectResponse) {
423
            return $ret;
424
        }
425
426
        return new JsonResponse(
427
            $this->editCounter->getEditSizeData(),
428
            Response::HTTP_OK
429
        );
430
    }
431
432
    /**
433
     * Get the namespace totals for the user as JSON.
434
     * @Route("/api/ec/namespacetotals/{project}/{username}/{key}", name="EditCounterApiNamespaceTotals")
435
     * @param Request $request
436
     * @param string $key API key.
437
     * @return Response
438
     * @codeCoverageIgnore
439
     */
440
    public function namespaceTotalsApiAction(Request $request, $key)
441
    {
442
        $ret = $this->setUpEditCounter($request, $key);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $ret is correct as $this->setUpEditCounter($request, $key) targeting AppBundle\Controller\Edi...ler::setUpEditCounter() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
443
        if ($ret instanceof RedirectResponse) {
444
            return $ret;
445
        }
446
447
        return new JsonResponse(
448
            $this->editCounter->namespaceTotals(),
449
            Response::HTTP_OK
450
        );
451
    }
452
453
    /**
454
     * Display or fetch the month counts for the user.
455
     * @Route("/api/ec/monthcounts/{project}/{username}/{key}", name="EditCounterApiMonthCounts")
456
     * @param Request $request
457
     * @param string $key API key.
458
     * @return Response
459
     * @codeCoverageIgnore
460
     */
461
    public function monthcountsApiAction(Request $request, $key)
462
    {
463
        $ret = $this->setUpEditCounter($request, $key);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $ret is correct as $this->setUpEditCounter($request, $key) targeting AppBundle\Controller\Edi...ler::setUpEditCounter() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
464
        if ($ret instanceof RedirectResponse) {
465
            return $ret;
466
        }
467
468
        return new JsonResponse(
469
            $this->editCounter->monthCounts(),
470
            Response::HTTP_OK
471
        );
472
    }
473
}
474