Completed
Push — master ( 2c4f4a...51d604 )
by Joseph
01:42
created

src/Models/Concerns/ManagesStorageConnection.php (10 issues)

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
namespace STS\StorageConnect\Models\Concerns;
3
4
use STS\StorageConnect\Events\CloudStorageDisabled;
5
use STS\StorageConnect\Events\CloudStorageEnabled;
6
use STS\StorageConnect\Exceptions\StorageUnavailableException;
7
8
trait ManagesStorageConnection
9
{
10
    /**
11
     * @return bool
12
     */
13
    public function isReady()
14
    {
15
        if ($this->isFull()) {
0 ignored issues
show
It seems like isFull() 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 Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
16
            $this->ping();
17
        }
18
19
        return $this->isEnabled();
20
    }
21
22
    /**
23
     * Sometimes we want to gracefully check up on the cloud storage account without any exceptions
24
     */
25
    public function ping()
26
    {
27
        if (!$this->shouldCheckSpace()) {
0 ignored issues
show
It seems like shouldCheckSpace() 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 Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
28
            return;
29
        }
30
31
        try {
32
            $this->checkSpaceUsage();
0 ignored issues
show
It seems like checkSpaceUsage() 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 Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
33
        } catch (\Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
34
        }
35
    }
36
37
    /**
38
     * @return bool
39
     * @throws StorageUnavailableException
40
     */
41
    public function verify()
42
    {
43
        if (!$this->isReady()) {
44
            throw new StorageUnavailableException($this);
45
        }
46
47
        return true;
48
    }
49
50
    /**
51
     * @return mixed
52
     */
53
    public function isConnected()
54
    {
55
        return $this->connected;
0 ignored issues
show
The property connected 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;
Loading history...
56
    }
57
58
    /**
59
     * @return bool
60
     */
61
    public function isEnabled()
62
    {
63
        return $this->isConnected() && $this->enabled;
0 ignored issues
show
The property enabled 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;
Loading history...
64
    }
65
66
    /**
67
     * @return bool
68
     */
69
    public function isDisabled()
70
    {
71
        return !$this->isEnabled();
72
    }
73
74
    /**
75
     * @return bool
76
     */
77
    public function isTokenInvalid()
78
    {
79
        return $this->isDisabled() && $this->reason == self::INVALID_TOKEN;
0 ignored issues
show
The property reason 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;
Loading history...
80
    }
81
82
    /**
83
     * @param null $reason
84
     *
85
     * @return $this
86
     */
87 View Code Duplication
    public function disable($reason = null)
88
    {
89
        $this->enabled = 0;
90
        $this->reason = $reason;
91
92
        if ($reason == self::SPACE_FULL) {
93
            $this->full = 1;
0 ignored issues
show
The property 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;
Loading history...
94
        }
95
96
        $this->save();
0 ignored issues
show
It seems like save() 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 Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
97
        event(new CloudStorageDisabled($this));
98
99
        return $this;
100
    }
101
102
    /**
103
     * @return $this
104
     */
105 View Code Duplication
    public function enable()
106
    {
107
        $this->reason = null;
108
        $this->enabled = 1;
109
        $this->full = 0;
110
111
        $this->save();
0 ignored issues
show
It seems like save() 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 Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
112
        event(new CloudStorageEnabled($this));
113
114
        return $this;
115
    }
116
}