Completed
Pull Request — master (#1)
by Adolfo
01:07
created

Subscription::getElapsedDays()   A

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 0
1
<?php
2
3
4
namespace Sagitarius29\LaravelSubscriptions\Entities;
5
6
7
use Carbon\Carbon;
8
use Illuminate\Database\Eloquent\Builder;
9
use Illuminate\Database\Eloquent\Model;
10
use Sagitarius29\LaravelSubscriptions\Contracts\PlanContract;
11
use Sagitarius29\LaravelSubscriptions\Contracts\SubscriptionContact;
12
13
class Subscription extends Model implements SubscriptionContact
14
{
15
    protected $table = 'subscriptions';
16
17
    protected $fillable = [
18
        'plan_id', 'start_at', 'end_at'
19
    ];
20
21
    public function scopeCurrent(Builder $q, Carbon $date)
22
    {
23
        return $q->where('start_at', '<', $date)
24
            ->where('end_at', '>', $date);
25
    }
26
27
    public function isPerpetual(): bool
28
    {
29
        return $this->end_at == null;
30
    }
31
32
    public function getDaysLeft(): int
33
    {
34
        // TODO: Implement getDaysLeft() method.
35
    }
36
37
    public function getElapsedDays(): int
38
    {
39
        // TODO: Implement getElapsedDays() method.
40
    }
41
42
    public function getExpirationDate(): ?Carbon
43
    {
44
        // TODO: Implement getExpirationDate() method.
45
    }
46
47
    public function getStartDate(): ?Carbon
48
    {
49
        // TODO: Implement getStartDate() method.
50
    }
51
52
    public function subscriber()
53
    {
54
        // TODO: Implement subscriber() method.
55
    }
56
57
    public static function make(PlanContract $plan, Carbon $start_at, Carbon $end_at = null): Model
58
    {
59
        return new Subscription([
60
            'plan_id'   => $plan->id,
0 ignored issues
show
Bug introduced by
Accessing id on the interface Sagitarius29\LaravelSubs...\Contracts\PlanContract suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
61
            'start_at'  => $start_at,
62
            'end_at'    => $end_at
63
        ]);
64
    }
65
}
66