Test Failed
Push — master ( 241073...2d5b3a )
by Julien
03:08
created

Round   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

7 Methods

Rating   Name   Duplication   Size   Complexity  
A hasTournamentInRequest() 0 4 1
A hasChampionshipInRequest() 0 4 1
A championship() 0 4 1
A fights() 0 4 1
A teams() 0 4 1
A competitors() 0 4 1
A generateFights() 0 19 4
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
        if ($settings->hasPreliminary && $settings->preliminaryGroupSize == 3) {
79
80
            for ($numRound = 1; $numRound <= $settings->preliminaryGroupSize; $numRound++) {
81
                Fight::savePreliminaryFightRound($rounds, $numRound);
82
            }
83
        } else {
84
            Fight::saveRoundRobinFights($championship, $rounds);
85
        }
86
    }
87
}