ManagesStorageConnection::isEnabled()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 2
nc 2
nop 0
1
<?php
2
namespace STS\StorageConnect\Models\Concerns;
3
4
use Carbon\Carbon;
5
use STS\StorageConnect\Events\CloudStorageDisabled;
6
use STS\StorageConnect\Events\CloudStorageEnabled;
7
use STS\StorageConnect\Exceptions\StorageUnavailableException;
8
9
trait ManagesStorageConnection
10
{
11
    /**
12
     * @return bool
13
     */
14
    public function isReady()
15
    {
16
        if ($this->isFull()) {
0 ignored issues
show
Bug introduced by
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...
17
            $this->ping();
18
        }
19
20
        return $this->isEnabled();
21
    }
22
23
    /**
24
     * Sometimes we want to gracefully check up on the cloud storage account without any exceptions
25
     */
26
    public function ping()
27
    {
28
        if (!$this->shouldCheckSpace()) {
0 ignored issues
show
Bug introduced by
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...
29
            return;
30
        }
31
32
        try {
33
            $this->checkSpaceUsage();
0 ignored issues
show
Bug introduced by
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...
34
        } catch (\Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
35
        }
36
    }
37
38
    /**
39
     * @return bool
40
     * @throws StorageUnavailableException
41
     */
42
    public function verify()
43
    {
44
        if (!$this->isReady()) {
45
            throw new StorageUnavailableException($this);
46
        }
47
48
        return true;
49
    }
50
51
    /**
52
     * @return mixed
53
     */
54
    public function isConnected()
55
    {
56
        return $this->connected;
0 ignored issues
show
Bug introduced by
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...
57
    }
58
59
    /**
60
     * @return bool
61
     */
62
    public function isEnabled()
63
    {
64
        return $this->isConnected() && $this->enabled;
0 ignored issues
show
Bug introduced by
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...
65
    }
66
67
    /**
68
     * @return bool
69
     */
70
    public function isDisabled()
71
    {
72
        return !$this->isEnabled();
73
    }
74
75
    /**
76
     * @return bool
77
     */
78
    public function isTokenInvalid()
79
    {
80
        return $this->isDisabled() && $this->reason == self::INVALID_TOKEN;
0 ignored issues
show
Bug introduced by
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...
81
    }
82
83
    /**
84
     * @param null $reason
85
     *
86
     * @return $this
87
     */
88 View Code Duplication
    public function disable($reason = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
89
    {
90
        $this->enabled = 0;
91
        $this->reason = $reason;
92
        $this->disabled_at = Carbon::now();
0 ignored issues
show
Bug introduced by
The property disabled_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;
Loading history...
93
94
        if ($reason == self::SPACE_FULL) {
95
            $this->full = 1;
0 ignored issues
show
Bug introduced by
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...
96
        }
97
98
        $this->save();
0 ignored issues
show
Bug introduced by
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...
99
        event(new CloudStorageDisabled($this));
100
101
        return $this;
102
    }
103
104
    /**
105
     * @return $this
106
     */
107 View Code Duplication
    public function enable()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
108
    {
109
        $this->reason = null;
110
        $this->enabled = 1;
111
        $this->full = 0;
112
        $this->enabled_at = Carbon::now();
0 ignored issues
show
Bug introduced by
The property enabled_at does not seem to exist. Did you mean enabled?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
113
114
        $this->save();
0 ignored issues
show
Bug introduced by
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...
115
        event(new CloudStorageEnabled($this));
116
117
        return $this;
118
    }
119
}