Completed
Push — master ( 0cb788...5f9089 )
by Matthew
03:43
created

OutfitTotalsStatisticsEndpoint   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 5
dl 34
loc 34
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A readStatistics() 13 13 2

How to fix   Duplicated Code   

Duplicated Code

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
2
3
namespace Ps2alerts\Api\Controller\Statistics;
4
5
use League\Route\Http\JsonResponse as Response;
6
use Ps2alerts\Api\Controller\EndpointBaseController;
7
use Ps2alerts\Api\Loader\Statistics\OutfitTotalsStatisticsLoader;
8
use Symfony\Component\HttpFoundation\Request;
9
10 View Code Duplication
class OutfitTotalsStatisticsEndpoint extends EndpointBaseController
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
11
{
12
    /**
13
     * Construct
14
     *
15
     * @param \Ps2alerts\Api\Loader\Metrics\OutfitTotalsStatisticsLoader $loader
16
     */
17
    public function __construct(OutfitTotalsStatisticsLoader $loader)
18
    {
19
        $this->loader = $loader;
20
    }
21
22
    /**
23
     * Returns top X entries
24
     *
25
     * @param  \Symfony\Component\HttpFoundation\Request $request
26
     * @param  array                                     $args
0 ignored issues
show
Bug introduced by
There is no parameter named $args. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
27
     *
28
     * @return \League\Route\Http\JsonResponse
29
     */
30
    public function readStatistics(Request $request)
31
    {
32
        // Collect any POST variables
33
        $post = $request->request->all();
34
35
        $return = $this->loader->readStatistics($post);
0 ignored issues
show
Bug introduced by
The method readStatistics does only exist in Ps2alerts\Api\Loader\Sta...\PlayerStatisticsLoader, but not in Ps2alerts\Api\Loader\Ale...Metrics\XpMetricsLoader.

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:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
36
37
        if (empty($return)) {
38
            return new Response\NoContent();
39
        }
40
41
        return new Response\Ok($return);
42
    }
43
}
44