Test Failed
Push — master ( bf81a5...2dcdef )
by Julien
03:10
created

Round::generateFights()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 26
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 26
rs 8.439
c 1
b 0
f 0
cc 6
eloc 15
nc 6
nop 3
1
<?php
2
3
namespace Xoco70\KendoTournaments\Models;
4
5
6
use Illuminate\Database\Eloquent\Model;
7
use Illuminate\Support\Collection;
8
9
class Round extends Model
10
{
11
    protected $table = 'round';
12
    public $timestamps = true;
13
    protected $guarded = ['id'];
14
15
    /**
16
     * Check if Request contains tournamentSlug / Should Move to TreeRequest When Built
17
     * @param $request
18
     * @return bool
19
     */
20
    public static function hasTournamentInRequest($request)
21
    {
22
        return $request->tournament != null;
23
    }
24
25
    /**
26
     * Check if Request contains championshipId / Should Move to TreeRequest When Built
27
     * @param $request
28
     * @return bool
29
     */
30
    public static function hasChampionshipInRequest($request)
31
    {
32
        return $request->championshipId != null; // has return false, don't know why
33
    }
34
35
36
    /**
37
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
38
     */
39
    public function championship()
40
    {
41
        return $this->belongsTo(Championship::class);
42
    }
43
44
    /**
45
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
46
     */
47
    public function fights()
48
    {
49
        return $this->hasMany(Fight::class, 'tree_id', 'id');
50
    }
51
52
//    /**
0 ignored issues
show
Unused Code Comprehensibility introduced by
39% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
53
//     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
54
//     */
55
//    public function user1()
56
//    {
57
//        return $this->belongsTo(User::class, 'c1', 'id');
58
//    }
59
//
60
//    /**
61
//     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
62
//     */
63
//    public function user2()
64
//    {
65
//        return $this->belongsTo(User::class, 'c2', 'id');
66
//    }
67
//
68
//    /**
69
//     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
70
//     */
71
//    public function user3()
72
//    {
73
//        return $this->belongsTo(User::class, 'c3', 'id');
74
//    }
75
//
76
//    /**
77
//     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
78
//     */
79
//    public function user4()
80
//    {
81
//        return $this->belongsTo(User::class, 'c4', 'id');
82
//    }
83
//
84
//    /**
85
//     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
86
//     */
87
//    public function user5()
88
//    {
89
//        return $this->belongsTo(User::class, 'c5', 'id');
90
//    }
91
//
92
//
93
//    /**
94
//     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
95
//     */
96
//    public function team1()
97
//    {
98
//        return $this->belongsTo(Team::class, 'c1', 'id');
99
//    }
100
//
101
//    /**
102
//     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
103
//     */
104
//    public function team2()
105
//    {
106
//        return $this->belongsTo(Team::class, 'c2', 'id');
107
//    }
108
//
109
//    /**
110
//     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
111
//     */
112
//    public function team3()
113
//    {
114
//        return $this->belongsTo(Team::class, 'c3', 'id');
115
//    }
116
117
118
    /**
119
     * @param Collection $tree
120
     * @param $settings
121
     * @param Championship $championship
122
     */
123
    public static function generateFights(Collection $tree, $settings, Championship $championship = null)
124
    {
125
126
        // Delete previous fight for this championship
127
128
        $arrayTreeId = $tree->map(function ($value, $key) {
0 ignored issues
show
Unused Code introduced by
The parameter $key is not used and could be removed.

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

Loading history...
129
            return $value->id;
130
        })->toArray();
131
        Fight::destroy($arrayTreeId);
132
133
        if ($settings->hasPreliminary) {
134
            if ($settings->preliminaryGroupSize == 3) {
135
                for ($numRound = 1; $numRound <= $settings->preliminaryGroupSize; $numRound++) {
136
                    Fight::saveFightRound($tree, $numRound);
137
                }
138
            } else {
139
                Fight::saveRoundRobinFights($championship, $tree);
140
            }
141
        } elseif ($settings->treeType == config('kendo-tournaments.DIRECT_ELIMINATION')) {
142
            Fight::saveFightRound($tree); // Always C1 x C2
143
        } elseif ($settings->treeType == config('kendo-tournaments.ROUND_ROBIN')) {
144
            Fight::saveRoundRobinFights($championship, $tree);
145
146
        }
147
148
    }
149
}