Test Failed
Push — master ( 2dcdef...5f4570 )
by Julien
03:01
created

Round::fights()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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
    public function teams()
53
    {
54
        return $this->belongsToMany(Team::class, 'round_team');
55
    }
56
57
    public function competitors()
58
    {
59
        return $this->belongsToMany(Competitor::class, 'round_competitor');
60
    }
61
62
63
    /**
64
     * @param Collection $rounds
65
     * @param $settings
66
     * @param Championship $championship
67
     */
68
    public static function generateFights(Collection $rounds, $settings, Championship $championship = null)
69
    {
70
71
        // Delete previous fight for this championship
72
73
        $arrRoundsId = $rounds->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...
74
            return $value->id;
75
        })->toArray();
76
        Fight::destroy($arrRoundsId);
77
78
        Fight::saveRoundRobinFights($championship, $rounds);
79
80
81
//        if ($settings->hasPreliminary) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
82
//            if ($settings->preliminaryGroupSize == 3) {
83
//                for ($numRound = 1; $numRound <= $settings->preliminaryGroupSize; $numRound++) {
84
//
85
//                }
86
//            } else {
87
//                Fight::saveRoundRobinFights($championship, $tree);
88
//            }
89
//        } elseif ($settings->treeType == config('kendo-tournaments.DIRECT_ELIMINATION')) {
90
//            Fight::saveFightRound($tree); // Always C1 x C2
91
//        } elseif ($settings->treeType == config('kendo-tournaments.ROUND_ROBIN')) {
92
//            Fight::saveRoundRobinFights($championship, $tree);
93
//
94
//        }
95
96
    }
97
}