Completed
Push — master ( 6e9cb0...09d0a5 )
by Tyler
02:15
created

HasLicenses::getLicensesUsed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Tylercd100\License\Traits;
4
5
use Tylercd100\License\License;
6
7
trait HasLicenses
8
{
9
    public function checkLicensesAvailable($class, $quantity)
10
    {
11
        $license = $this->getLicenseInstance($class);        
12
        $license->check($quantity);
13
        return $this;
14
    }
15
16
    public function getLicensesRemaining($class)
17
    {
18
        $license = $this->getLicenseInstance($class);        
19
        return $license->remaining();
20
    }
21
22
    public function getLicensesUsed($class)
23
    {
24
        $license = $this->getLicenseInstance($class);        
25
        return $license->used();
26
    }
27
28
    public function addLicenses($class, $quantity = 1)
29
    {
30
        // Add quantity of licenses
31
        $license = $this->getLicenseInstance($class);
32
        return $license->add($quantity);
33
    }
34
35
    public function subLicenses($class, $quantity = 1)
36
    {
37
        // Subtract quantity of licenses
38
        $license = $this->getLicenseInstance($class);
39
        return $license->sub($quantity);
40
    }
41
42
    public function setLicenses($class, $quantity = 1)
43
    {
44
        // Set the quantity of licenses
45
        $license = $this->getLicenseInstance($class);
46
        return $license->set($quantity);
0 ignored issues
show
Bug introduced by
The method set() does not seem to exist on object<Tylercd100\License\License>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
47
    }
48
49
    public function removeLicenses($class)
50
    {
51
        // Remove all licenses of type
52
        $license = $this->getLicenseInstance($class);
53
        return $license->remove();
0 ignored issues
show
Bug introduced by
The method remove() does not seem to exist on object<Tylercd100\License\License>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
54
    }
55
56
    private function getLicenseInstance($class)
57
    {
58
        $license = new $class($this);
59
        if (!($license instanceof License)) {
60
            throw LicenseException("Expected ".get_class($license)." to be an instanceof ".License::class);
61
        }
62
        return $license;
63
    }
64
}
65