Pointable::transactions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Gamer\Traits;
4
5
use Gamer\Models\Transaction;
6
use Illuminate\Database\Eloquent\Model;
7
8
trait Pointable
9
{
10
    /**
11
     * @return \Illuminate\Database\Eloquent\Relations\MorphMany
12
     */
13
    public function transactions($amount = null)
14
    {
15
        return $this->morphMany(Transaction::class, 'pointable')->orderBy('created_at','desc')->take($amount);
0 ignored issues
show
Bug introduced by
It seems like morphMany() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
16
    }
17
18
    // /**
19
    //  *
20
    //  * @return mix
21
    //  */
22
    // public function averagePoint($round= null)
23
    // {
24
    //   if ($round) {
25
    //         return $this->transactions()
26
    //           ->selectRaw('ROUND(AVG(amount), '.$round.') as averagePointTransaction')
27
    //           ->pluck('averagePointTransaction');
28
    //     }
29
    //
30
    //     return $this->transactions()
31
    //         ->selectRaw('AVG(amount) as averagePointTransaction')
32
    //         ->pluck('averagePointTransaction');
33
    // }
34
    //
35
    // /**
36
    //  *
37
    //  * @return mix
38
    //  */
39
    // public function countPoint(){
40
    //   return $this->transactions()
41
    //       ->selectRaw('count(amount) as countTransactions')
42
    //       ->pluck('countTransactions');
43
    // }
44
    //
45
    // /**
46
    //  *
47
    //  * @return mix
48
    //  */
49
    // public function sumPoint()
50
    // {
51
    //     return $this->transactions()
52
    //         ->selectRaw('SUM(amount) as sumPointTransactions')
53
    //         ->pluck('sumPointTransactions');
54
    // }
55
    //
56
    // /**
57
    //  * @param $max
58
    //  *
59
    //  * @return mix
60
    //  */
61
    // public function pointPercent($max = 5)
62
    // {
63
    //     $transactions = $this->transactions();
64
    //     $quantity = $transactions->count();
65
    //     $total = $transactions->selectRaw('SUM(amount) as total')->pluck('total');
66
    //     return ($quantity * $max) > 0 ? $total / (($quantity * $max) / 100) : 0;
67
    // }
68
69
    /**
70
     *
71
     * @return mix
72
     */
73
    public function countTransactions(){
74
      return $this->transactions()
75
          ->count();
76
    }
77
78
    /**
79
     *
80
     * @return double
81
     */
82
    public function currentPoints()
83
    {
84
        return (new Transaction())->getCurrentPoints($this);
85
    }
86
87
    /**
88
     * @param $amount
89
     * @param $message
90
     * @param $data
91
     *
92
     * @return static
93
     */
94
    public function addPoints($amount, $message, $data = null)
0 ignored issues
show
Unused Code introduced by
The parameter $data 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...
95
    {
96
        return (new Transaction())->addTransaction($this, $amount, $message, $data = null);
97
    }
98
}
99