StorageUnavailableException   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 41
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A why() 0 10 3
A reason() 0 7 1
1
<?php
2
3
namespace STS\StorageConnect\Exceptions;
4
5
use Illuminate\Support\Arr;
6
use STS\StorageConnect\Connections\Connection;
7
use STS\StorageConnect\Models\CloudStorage;
8
use Throwable;
9
10
/**
11
 * Class StorageUnavailableException
12
 * @package STS\StorageConnect\Exceptions
13
 */
14
class StorageUnavailableException extends \Exception
15
{
16
    /**
17
     * StorageUnavailableException constructor.
18
     *
19
     * @param CloudStorage $storage
20
     */
21
    public function __construct(CloudStorage $storage)
22
    {
23
        $this->message = $this->why($storage);
24
    }
25
26
    /**
27
     * @param CloudStorage $storage
28
     *
29
     * @return string
30
     */
31
    protected function why(CloudStorage $storage)
32
    {
33
        if(!$storage->connected) {
0 ignored issues
show
Documentation introduced by
The property connected does not exist on object<STS\StorageConnect\Models\CloudStorage>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
34
            return "Connection is not set up";
35
        }
36
37
        if(!$storage->enabled) {
0 ignored issues
show
Documentation introduced by
The property enabled does not exist on object<STS\StorageConnect\Models\CloudStorage>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
38
            return "Connection has been disabled: " . $this->reason($storage) . " [" . $storage->owner_description . "]";
39
        }
40
    }
41
42
    /**
43
     * @param CloudStorage $storage
44
     *
45
     * @return mixed
46
     */
47
    protected function reason(CloudStorage $storage)
48
    {
49
        return Arr::get([
50
            'invalid' => 'Connection is invalid, please re-authorize',
51
            'full' => 'Storage is full, please clear space or upgrade storage account'
52
        ], $storage->reason,'unknown reason');
0 ignored issues
show
Documentation introduced by
The property reason does not exist on object<STS\StorageConnect\Models\CloudStorage>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
53
    }
54
}