Test Failed
Push — master ( b6687a...d5e75a )
by Julien
06:32
created

ChampionshipSettings   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 4
dl 0
loc 69
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A championship() 0 4 1
A createOrUpdate() 0 14 2
1
<?php
2
3
namespace Xoco70\LaravelTournaments\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Eloquent\SoftDeletes;
7
use Illuminate\Http\Request;
8
9
class ChampionshipSettings extends Model
10
{
11
    use SoftDeletes;
12
13
    protected $dates = ['created_at', 'updated_at', 'deleted_at'];
14
15
    protected $table = 'championship_settings';
16
    public $timestamps = true;
17
    protected $guarded = ['id'];
18
19
    const MIN_COMPETITORS_BY_AREA = 2,
20
        PLAY_OFF = 0,
21
        DIRECT_ELIMINATION = 1,
22
        PRELIMINARY_GROUP_SIZE = [3 => 3, 4 => 4, 5 => 5],
23
        PRELIMINARY_WINNERS = [1 => 1], // , 2 => 2, 3 => 3
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% 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...
24
        TEAM_SIZE = [2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10],
25
        TEAM_RESERVE = [1 => 1, 2 => 2, 3 => 3, 4 => 4],
26
        LIMIT_BY_ENTITY = [0 => '-', 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10],
27
        DEFAULT_SETTINGS = [
28
        'fightingAreas' => '1',
29
        'fightDuration' => '05:00',
30
        'hasPreliminary' => '1',
31
        'preliminaryGroupSize' => '3',
32
        'preliminaryDuration' => '05:00',
33
        'preliminaryWinner' => '1',
34
        'hasEncho' => '1',
35
        'enchoQty' => '1',
36
        'enchoDuration' => '0',
37
        'hasHantei' => '0',
38
        'hanteiLimit' => '0', // 1/2 Finals
39
        'enchoGoldPoint' => '0', // Step where Encho has no more time limit
40
        'limitByEntity' => '4',
41
        'cost' => '',
42
        'treeType' => '1',
43
        'seedQuantity' => '4',
44
45
    ];
46
47
    /**
48
     * A Setting belongs to a Championship.
49
     *
50
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
51
     */
52
    public function championship()
53
    {
54
        return $this->belongsTo(Championship::class);
55
    }
56
57
    /**
58
     * @param Request $request
59
     * @param Championship $championship
60
     *
61
     * @return ChampionshipSettings
62
     */
63
    public static function createOrUpdate(Request $request, Championship $championship): ChampionshipSettings
64
    {
65
        $request->request->add(['championship_id' => $championship->id]);
66
        $arrSettings = $request->except('_token', 'numFighters','isTeam');
67
        $settings = static::where(['championship_id' => $championship->id])->first();
68
        if ($settings == null) {
69
            $settings = new self();
70
        }
71
        $settings->fill($arrSettings);
72
73
        $settings->save();
74
75
        return $settings;
76
    }
77
}
78