SubscriptionService   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
eloc 12
c 2
b 1
f 1
dl 0
loc 49
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A getSubscription() 0 3 1
A getModel() 0 3 1
A getParentRelationship() 0 5 1
A getUnsetFields() 0 3 1
1
<?php
2
3
namespace Faithgen\Miscellaneous\Services;
4
5
use Faithgen\Miscellaneous\Models\Subscription;
6
use Illuminate\Database\Eloquent\Model as ParentModel;
7
use InnoFlash\LaraStart\Services\CRUDServices;
8
9
class SubscriptionService extends CRUDServices
10
{
11
    private Subscription $subscription;
12
13
    public function __construct(Subscription $subscription)
14
    {
15
        if (request()->has('subscription_id')) {
16
            $this->subscription = Subscription::findOrFail(request('subscription_id'));
17
        } else {
18
            $this->subscription = $subscription;
19
        }
20
    }
21
22
    /**
23
     * Retrieves an instance of subscription.
24
     */
25
    public function getSubscription(): Subscription
26
    {
27
        return $this->subscription;
28
    }
29
30
    /**
31
     * Makes a list of fields that you do not want to be sent
32
     * to the create or update methods.
33
     * Its mainly the fields that you do not have in the subscriptions table.
34
     */
35
    public function getUnsetFields()
36
    {
37
        return ['subscription_id'];
38
    }
39
40
    /**
41
     * This returns the model found in the constructor
42
     * or an instance of the class if no subscription is found.
43
     */
44
    public function getModel()
45
    {
46
        return $this->getSubscription();
47
    }
48
49
    /**
50
     * Attaches a parent to the current subscription.
51
     * You can delete this if you do not intent to create subscriptions from parent relationships.
52
     */
53
    public function getParentRelationship()
54
    {
55
        return [
56
            ParentModel::class,
57
            'relationshipName',
58
        ];
59
    }
60
}
61