TournamentTeamController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 7
dl 0
loc 74
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A catalogue() 0 6 1
A add() 0 13 2
1
<?php
2
3
namespace App\Http\Controllers\API;
4
5
use App\Tournament;
6
use App\TournamentTeam;
7
use App\Transformers\TournamentTeamTransformer;
8
use Illuminate\Support\Facades\Input;
9
use App\Http\Requests\Tournament\AddTeam;
10
use Symfony\Component\Process\Exception\LogicException;
11
12
/**
13
 * Class TournamentTeamController
14
 * @package App\Http\Controllers\API
15
 */
16
class TournamentTeamController extends Controller
17
{
18
19
    /**
20
     * @SWG\Get(
21
     *     tags={"Team"},
22
     *     path="/api/v1/teams",
23
     *     description="Returns all teams from specified tournament",
24
     *     operationId="catalogue",
25
     *     produces={"application/json"},
26
     *     @SWG\Parameter(
27
     *         description="Tournament id",
28
     *         in="query",
29
     *         name="tournamentId",
30
     *         required=true,
31
     *         type="integer"
32
     *     ),
33
     *     @SWG\Response(
34
     *     response="200",
35
     *     description="Successfully get list of teams"
36
     *     )
37
     * )
38
     */
39
    public function catalogue()
40
    {
41
        $collection = TournamentTeam::with('Team')->where(['tournamentId' => Input::get('tournamentId')]);
0 ignored issues
show
Bug introduced by
The method where does only exist in Illuminate\Database\Eloquent\Builder, but not in Illuminate\Database\Eloquent\Model.

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...
42
43
        return $this->response->collection($collection->get(), new TournamentTeamTransformer(), 'teams');
44
    }
45
46
    /**
47
     * @SWG\Post(
48
     *     tags={"Team"},
49
     *     path="/api/v1/teams",
50
     *     description="Add new team to specified tournament",
51
     *     operationId="add",
52
     *     produces={"application/json"},
53
     *     @SWG\Parameter(
54
     *         description="Tournament id",
55
     *         in="query",
56
     *         name="team[tournamentId]",
57
     *         required=true,
58
     *         type="integer"
59
     *     ),
60
     *     @SWG\Parameter(
61
     *         description="Team id",
62
     *         in="query",
63
     *         name="team[teamId]",
64
     *         required=true,
65
     *         type="integer"
66
     *     ),
67
     *     @SWG\Response(
68
     *     response="200",
69
     *     description="Successfully add new team"
70
     *     )
71
     * )
72
     * @param AddTeam $request
73
     * @return array
74
     * @throws \Symfony\Component\Process\Exception\LogicException
75
     */
76
    public function add(AddTeam $request)
77
    {
78
        $tournament = Tournament::findOrFail($request->input('team.tournamentId'));
79
80
        if (Tournament::STATUS_DRAFT !== $tournament->status) {
81
            throw new LogicException('Team can be assigned only to tournament with draft status.');
82
        }
83
84
        $team = TournamentTeam::create($request->input('team'));
0 ignored issues
show
Bug introduced by
The method create() does not exist on App\TournamentTeam. Did you maybe mean created()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
85
        $tournamentTeam = TournamentTeam::where(['id' => $team->id])->get();
86
87
        return $this->response->collection($tournamentTeam, new TournamentTeamTransformer(), 'teams');
88
    }
89
}
90