Issues (36)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Plan.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Sagitarius29\LaravelSubscriptions;
4
5
use Illuminate\Database\Eloquent\Builder;
6
use Illuminate\Database\Eloquent\Model;
7
use Sagitarius29\LaravelSubscriptions\Contracts\GroupContract;
8
use Sagitarius29\LaravelSubscriptions\Contracts\PlanContract;
9
use Sagitarius29\LaravelSubscriptions\Entities\Group;
10
use Sagitarius29\LaravelSubscriptions\Exceptions\PlanErrorException;
11
use Sagitarius29\LaravelSubscriptions\Traits\HasFeatures;
12
13
abstract class Plan extends Model implements PlanContract
14
{
15
    use HasFeatures;
16
17
    protected $table = 'plans';
18
19
    protected $fillable = [
20
        'name', 'description', 'free_days', 'sort_order', 'is_enabled', 'is_default', 'group',
21
    ];
22
23
    /**
24
     * @param  string  $name
25
     * @param  string  $description
26
     * @param  int  $free_days
0 ignored issues
show
There is no parameter named $free_days. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
27
     * @param  int  $sort_order
28
     * @param  bool  $is_enabled
29
     * @param  bool  $is_default
30
     * @param  GroupContract|null  $group
31
     * @return Model|PlanContract
32
     */
33
    public static function create(
34
        string $name,
35
        string $description,
36
        int $sort_order,
37
        bool $is_enabled = false,
38
        bool $is_default = false,
39
        GroupContract $group = null
40
    ): PlanContract {
41
        $attributes = [
42
            'name'        => $name,
43
            'description' => $description,
44
            'sort_order'  => $sort_order,
45
            'is_enabled'  => $is_enabled,
46
            'is_default'  => $is_default,
47
            'group'       => $group,
48
        ];
49
        $calledClass = get_called_class();
50
51
        if (! self::defaultExists($group)) {
52
            $attributes['is_default'] = true;
53
        }
54
55
        $plan = new $calledClass($attributes);
56
        $plan->save();
57
58
        return $plan;
59
    }
60
61
    private static function defaultExists(GroupContract $group = null): bool
62
    {
63
        $calledClass = get_called_class();
64
65
        return $calledClass::query()
66
            ->byGroup($group)
67
            ->isDefault()
68
            ->exists();
69
    }
70
71
    public function scopeByGroup(Builder $q, GroupContract $group = null)
72
    {
73
        return $q->where('group', $group);
74
    }
75
76
    public function scopeIsDefault(Builder $q)
77
    {
78
        return $q->where('is_default', 1);
79
    }
80
81
    public function scopeEnabled(Builder $q)
82
    {
83
        return $q->where('is_enabled', 1);
84
    }
85
86
    public function scopeDisabled(Builder $q)
87
    {
88
        return $q->where('is_enabled', 1);
89
    }
90
91
    public function isDefault(): bool
92
    {
93
        return $this->is_default;
94
    }
95
96
    public function isEnabled(): bool
97
    {
98
        return $this->is_enabled;
99
    }
100
101
    public function isDisabled(): bool
102
    {
103
        return ! $this->is_enabled;
104
    }
105
106
    public function isFree(): bool
107
    {
108
        return $this->intervals()->count() == 0 || $this->intervals()->first()->price == 0;
109
    }
110
111
    public function intervals()
112
    {
113
        return $this->hasMany(config('subscriptions.entities.plan_interval'), 'plan_id')
114
            ->orderBy('price');
115
    }
116
117
    public function isNotFree(): bool
118
    {
119
        return $this->intervals()->count() > 0 && $this->intervals()->first()->price > 0;
120
    }
121
122
    public function hasManyIntervals(): bool
123
    {
124
        return $this->intervals()->count() > 1;
125
    }
126
127
    public function setFree()
128
    {
129
        $this->intervals()->delete();
130
    }
131
132
    public function setDefault()
133
    {
134
        $myGroup = $this->myGroup();
135
        $calledClass = get_called_class();
136
137
        $currentDefaults = $calledClass::query()
138
            ->byGroup($myGroup)
139
            ->isDefault()
140
            ->get();
141
142
        $currentDefaults->each(function ($plan) {
143
            $plan->is_default = false;
144
            $plan->save();
145
        });
146
147
        $this->is_default = true;
148
        $this->save();
149
    }
150
151
    public function myGroup(): ?GroupContract
152
    {
153
        return empty($this->group) ? null : new Group($this->group);
154
    }
155
156
    public function changeToGroup(GroupContract $group): void
157
    {
158
        $this->group = $group;
159
160
        if (! self::defaultExists($group)) {
161
            $this->is_default = true;
162
        }
163
164
        $this->save();
165
    }
166
167
    public function getName()
168
    {
169
        return $this->name;
170
    }
171
172
    public function getDescription()
173
    {
174
        return $this->description;
175
    }
176
177
    public function delete()
178
    {
179
        if ($this->subscriptions()->exists() > 0) {
180
            throw new PlanErrorException('You cannot delete this plan because this has subscriptions.');
181
        }
182
183
        return parent::delete();
184
    }
185
186
    public function subscriptions()
187
    {
188
        return $this->hasMany(config('subscriptions.entities.plan_subscription'));
189
    }
190
}
191