Game::cdcs()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * rmarchiv.tk
5
 * (c) 2016-2017 by Marcel 'ryg' Hering
6
 */
7
8
namespace App\Models;
9
10
use GeneaLabs\LaravelModelCaching\Traits\Cachable;
11
use Laravel\Scout\Searchable;
12
use Illuminate\Database\Eloquent\Model;
13
use Waavi\Translation\Traits\Translatable;
14
use Spatie\Activitylog\Traits\LogsActivity;
15
16
/**
17
 * Class Game.
18
 *
19
 * @property int $id
20
 * @property string $title
21
 * @property string $subtitle
22
 * @property string $desc_md
23
 * @property string $desc_html
24
 * @property string $website_url
25
 * @property int $user_id
26
 * @property int $views
27
 * @property string $release_date
28
 * @property int $maker_id
29
 * @property int $lang_id
30
 * @property string $deleted_at
31
 * @property int $atelier_id
32
 * @property \Carbon\Carbon $created_at
33
 * @property \Carbon\Carbon $updated_at
34
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Game whereId($value)
35
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Game whereTitle($value)
36
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Game whereSubtitle($value)
37
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Game whereDescMd($value)
38
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Game whereDescHtml($value)
39
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Game whereWebsiteUrl($value)
40
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Game whereUserId($value)
41
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Game whereViews($value)
42
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Game whereReleaseDate($value)
43
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Game whereMakerId($value)
44
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Game whereLangId($value)
45
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Game whereDeletedAt($value)
46
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Game whereCreatedAt($value)
47
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Game whereUpdatedAt($value)
48
 * @mixin \Eloquent
49
 * @property-read \App\Models\User $user
50
 * @property-read \App\Models\Maker $maker
51
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\GamesDeveloper[] $developer
52
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Developer[] $developers
53
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Screenshot[] $screenshots
54
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Comment[] $comments
55
 * @property-read mixed $votes
56
 * @property-read \App\Models\Language $language
57
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\GamesFile[] $gamefiles
58
 * @property string $youtube
59
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Game whereYoutube($value)
60
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\TagRelation[] $tags
61
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\UserCredit[] $credits
62
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\GamesAward[] $awards
63
 * @property-read \Illuminate\Database\Eloquent\Collection|\Spatie\Activitylog\Models\Activity[] $activity
64
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\GamesCoupdecoeur[] $cdcs
65
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Game whereAtelierId($value)
66
 * @property int $release_type
67
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Game whereReleaseType($value)
68
 * @property int $voteup
69
 * @property int $votedown
70
 * @property string $avg
71
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Game whereAvg($value)
72
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Game whereComments($value)
73
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Game whereVotedown($value)
74
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Game whereVoteup($value)
75
 * @property-read \Illuminate\Database\Eloquent\Collection|\Venturecraft\Revisionable\Revision[] $revisionHistory
76
 * @property string $desc_md_translation
77
 * @property int $license_id
78
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Game whereDescMdTranslation($value)
79
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Game whereLicenseId($value)
80
 * @property-read \App\Models\License $license
81
 */
82
class Game extends Model
83
{
84
    use \Venturecraft\Revisionable\RevisionableTrait;
85
    //use Translatable;
86
    use LogsActivity;
87
    use Searchable;
88
89
    protected static $logAttributes = [
90
        'title',
91
        'subtitle',
92
        'desc_md',
93
        'website_url',
94
        'user_id',
95
        'maker_id',
96
        'lang_id',
97
        'atelier_id',
98
    ];
99
    public $timestamps = true;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 14 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
100
    protected $table = 'games';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 16 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
101
    protected $fillable = [
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 13 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
102
        'title',
103
        'subtitle',
104
        'desc_md',
105
        'desc_html',
106
        'website_url',
107
        'user_id',
108
        'views',
109
        'release_date',
110
        'maker_id',
111
        'lang_id',
112
        'atelier_id',
113
        'release_type',
114
        'voteup',
115
        'votedown',
116
        'avg',
117
        'comments',
118
        'license_id',
119
    ];
120
    protected $hidden = [
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 15 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
121
        'votes',
122
    ];
123
124
    protected $guarded = [];
125
    protected $appends = ['votes'];
126
    //protected $translatableAttributes = ['desc_md'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
127
128
    public function user()
129
    {
130
        return $this->hasOne('App\Models\User', 'id', 'user_id');
131
    }
132
133
    public function maker()
134
    {
135
        return $this->hasOne('App\Models\Maker', 'id', 'maker_id');
136
    }
137
138
    public function developers()
139
    {
140
        return $this->hasMany('App\Models\GamesDeveloper', 'game_id', 'id');
141
    }
142
143
    public function screenshots()
144
    {
145
        return $this->hasMany('App\Models\Screenshot');
146
    }
147
148 View Code Duplication
    public function getVotesAttribute()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
149
    {
150
        $vote['up'] = intval($this->comments()->sum('vote_up'));
0 ignored issues
show
Coding Style Comprehensibility introduced by
$vote was never initialized. Although not strictly required by PHP, it is generally a good practice to add $vote = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
151
        $vote['down'] = intval($this->comments()->sum('vote_down'));
152
        $vote['avg'] = @round(($vote['up'] - $vote['down']) / ($vote['up'] + $vote['down']), 2);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
153
        //(voteup - votedown) / (voteup + votedown)
154
        return $vote;
155
    }
156
157
    public function comments()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
158
    {
159
        return $this->hasMany('App\Models\Comment', 'content_id', 'id')->Where('content_type', '=', \DB::raw("'game'"))->with('user');
160
    }
161
162
    public function language()
163
    {
164
        return $this->hasOne('App\Models\Language', 'id', 'lang_id');
165
    }
166
167
    public function gamefiles()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
168
    {
169
        return $this->hasMany('App\Models\GamesFile', 'game_id', 'id')
170
            ->orderBy('release_type', 'desc')
171
            ->orderBy('release_year', 'desc')
172
            ->orderBy('release_month', 'desc')
173
            ->orderBy('release_day', 'desc')
174
            ->with('gamefiletype')
175
            ->withTrashed();
176
    }
177
178
    public function tagCount()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
179
    {
180
        return $this->tags()
181
            ->selectRaw('id, count(*) as tagcount')
182
            ->groupBy('id');
183
    }
184
185
    public function tags()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
186
    {
187
        return $this->hasMany('App\Models\TagRelation', 'content_id', 'id')->Where('content_type', '=', \DB::raw("'game'"))->with('tag');
188
    }
189
190
    public function credits()
191
    {
192
        return $this->hasMany('App\Models\UserCredit', 'game_id', 'id');
193
    }
194
195
    public function awards()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
196
    {
197
        return $this->hasMany('App\Models\GamesAward', 'game_id', 'id')->Where('place', '<=', 3);
198
    }
199
200
    public function cdcs()
201
    {
202
        return $this->hasMany('App\Models\GamesCoupdecoeur', 'game_id', 'id');
203
    }
204
205
    /**
206
     * Get the indexable data array for the model.
207
     *
208
     * @return array
209
     */
210
    public function toSearchableArray()
211
    {
212
        return [
213
            'id'       => $this->id,
214
            'title'    => $this->title,
215
            'subtitle' => $this->subtitle,
216
        ];
217
    }
218
219
    public function license()
220
    {
221
        return $this->hasOne('App\Models\License', 'id', 'license_id');
222
    }
223
}
224