HasVouchers   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A vouchers() 0 4 1
A createVouchers() 0 4 1
A createVoucher() 0 4 1
1
<?php
2
3
namespace BeyondCode\Vouchers\Traits;
4
5
use BeyondCode\Vouchers\Models\Voucher;
6
use BeyondCode\Vouchers\Facades\Vouchers;
7
8
trait HasVouchers
9
{
10
    /**
11
     * Set the polymorphic relation.
12
     *
13
     * @return mixed
14
     */
15
    public function vouchers()
16
    {
17
        return $this->morphMany(config('vouchers.model', Voucher::class), 'model');
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...
18
    }
19
20
    /**
21
     * @param int $amount
22
     * @param array $data
23
     * @param null $expires_at
24
     * @return Voucher[]
25
     */
26
    public function createVouchers(int $amount, array $data = [], $expires_at = null)
27
    {
28
        return Vouchers::create($this, $amount, $data, $expires_at);
0 ignored issues
show
Bug introduced by
The method create() does not exist on BeyondCode\Vouchers\Facades\Vouchers. Did you maybe mean createFreshMockInstance()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
29
    }
30
31
    /**
32
     * @param array $data
33
     * @param null $expires_at
34
     * @return Voucher
35
     */
36
    public function createVoucher(array $data = [], $expires_at = null)
37
    {
38
        return $this->createVouchers(1, $data, $expires_at)[0];
39
    }
40
}
41