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 STS\StorageConnect\Models\Concerns; |
||
4 | |||
5 | use Carbon\Carbon; |
||
6 | use STS\StorageConnect\Types\Quota; |
||
7 | |||
8 | trait TracksQuota |
||
9 | { |
||
10 | /** |
||
11 | * @return bool |
||
12 | */ |
||
13 | public function isFull() |
||
14 | { |
||
15 | return (bool) $this->full; |
||
0 ignored issues
–
show
|
|||
16 | } |
||
17 | |||
18 | /** |
||
19 | * @return mixed |
||
20 | */ |
||
21 | public function percentFull() |
||
22 | { |
||
23 | return $this->percent_full; |
||
0 ignored issues
–
show
The property
percent_full does not exist. Did you maybe forget to declare it?
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code: class MyClass { }
$x = new MyClass();
$x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: class MyClass {
public $foo;
}
$x = new MyClass();
$x->foo = true;
![]() |
|||
24 | } |
||
25 | |||
26 | /** |
||
27 | * @return bool |
||
28 | */ |
||
29 | public function shouldCheckSpace() |
||
30 | { |
||
31 | return |
||
32 | // Never checked before |
||
33 | !$this->space_checked_at |
||
0 ignored issues
–
show
The property
space_checked_at does not exist. Did you maybe forget to declare it?
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code: class MyClass { }
$x = new MyClass();
$x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: class MyClass {
public $foo;
}
$x = new MyClass();
$x->foo = true;
![]() |
|||
34 | |||
35 | // If we believe storage if full, check again after an hour |
||
36 | || ($this->isFull() && $this->space_checked_at->diffInMinutes(Carbon::now()) > 60) |
||
37 | |||
38 | // Otherwise just periodically check in |
||
39 | || $this->space_checked_at->diffInHours(Carbon::now()) > 24; |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * |
||
44 | */ |
||
45 | public function checkSpaceUsage() |
||
46 | { |
||
47 | $this->updateQuota($this->adapter()->getQuota()); |
||
0 ignored issues
–
show
It seems like
adapter() 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 Adding the ![]() |
|||
48 | } |
||
49 | |||
50 | /** |
||
51 | * @param Quota $quota |
||
52 | * |
||
53 | * @return $this |
||
54 | */ |
||
55 | public function updateQuota(Quota $quota) |
||
56 | { |
||
57 | $this->fill($quota->toArray())->save(); |
||
0 ignored issues
–
show
It seems like
fill() 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 Adding the ![]() |
|||
58 | |||
59 | if ($this->full && $this->percent_full < 99) { |
||
60 | $this->enable(); |
||
0 ignored issues
–
show
It seems like
enable() 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 Adding the ![]() |
|||
61 | } else if (!$this->full && $this->percent_full > 99) { |
||
62 | $this->disable(self::SPACE_FULL); |
||
0 ignored issues
–
show
It seems like
disable() 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 Adding the ![]() |
|||
63 | } |
||
64 | |||
65 | return $this; |
||
66 | } |
||
67 | } |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: