Test Failed
Push — feature-laravel-5.4 ( d62334...6d0d6f )
by Kirill
04:24
created

Tip::rating()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * This file is part of laravel.su package.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
declare(strict_types=1);
10
11
namespace App\Models;
12
13
use App\Models\Tip\RatingType;
14
use Illuminate\Database\Eloquent\Model;
15
use Illuminate\Database\Eloquent\Relations\HasMany;
16
use Illuminate\Database\Eloquent\Relations\BelongsTo;
17
18
/**
19
 * Class Tip.
20
 */
21
class Tip extends Model
22
{
23
    /**
24
     * @var string
25
     */
26
    protected $table = 'tips';
27
28
    /**
29
     * @return BelongsTo
30
     */
31
    public function user(): BelongsTo
32
    {
33
        return $this->belongsTo(User::class);
34
    }
35
36
    /**
37
     * @return HasMany
38
     */
39
    public function rating(): HasMany
40
    {
41
        return $this->hasMany(TipRating::class);
42
    }
43
44
    /**
45
     * @return HasMany
46
     */
47
    public function likes(): HasMany
48
    {
49
        return $this->rating()->where('type', RatingType::LIKE);
50
    }
51
52
    /**
53
     * @return HasMany
54
     */
55
    public function dislikes(): HasMany
56
    {
57
        return $this->rating()->where('type', RatingType::DISLIKE);
58
    }
59
}