LogsActivity::subscribe()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 47

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 47
rs 9.1563
c 0
b 0
f 0
nc 1
cc 1
nop 1
1
<?php
2
namespace STS\StorageConnect\Subscribers;
3
4
use STS\StorageConnect\Events\CloudStorageDisabled;
5
use STS\StorageConnect\Events\CloudStorageEnabled;
6
use STS\StorageConnect\Events\CloudStorageSetup;
7
use Log;
8
use STS\StorageConnect\Events\UploadFailed;
9
use STS\StorageConnect\Events\UploadInProgress;
10
use STS\StorageConnect\Events\UploadRetrying;
11
use STS\StorageConnect\Events\UploadStarted;
12
use STS\StorageConnect\Events\UploadSucceeded;
13
14
/**
15
 * Class LogsActivity
16
 * @package STS\StorageConnect\Subscribers
17
 */
18
class LogsActivity
19
{
20
    /**
21
     * @param $dispatcher
22
     */
23
    public function subscribe($dispatcher)
24
    {
25
        $dispatcher->listen(CloudStorageSetup::class, function (CloudStorageSetup $event) {
26
            $this->info("New cloud storage connection", $event->storage);
27
        });
28
29
        $dispatcher->listen(UploadSucceeded::class, function (UploadSucceeded $event) {
30
            $this->info("File uploaded to cloud storage", $event->storage, [
31
                'source'      => $event->sourcePath,
32
                'destination' => $event->destinationPath
33
            ]);
34
        });
35
36
        $dispatcher->listen(UploadRetrying::class, function (UploadRetrying $event) {
37
            $this->warning($event->message, $event->storage, [
38
                'source'  => $event->sourcePath
39
            ]);
40
        });
41
42
        $dispatcher->listen(UploadFailed::class, function (UploadFailed $event) {
43
            $this->error($event->message, $event->storage, [
44
                'source'  => $event->sourcePath
45
            ]);
46
        });
47
48
        $dispatcher->listen(UploadStarted::class, function (UploadStarted $event) {
49
            $this->info("Async upload started", $event->storage, [
50
                'source'  => $event->sourcePath
51
            ]);
52
        });
53
54
        $dispatcher->listen(UploadInProgress::class, function (UploadInProgress $event) {
55
            $this->info("Async upload in progress", $event->storage, [
56
                'source'  => $event->sourcePath
57
            ]);
58
        });
59
60
        $dispatcher->listen(CloudStorageDisabled::class, function (CloudStorageDisabled $event) {
61
            $this->warning("Connection disabled", $event->storage, [
62
                'reason'  => $event->storage->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...
63
            ]);
64
        });
65
66
        $dispatcher->listen(CloudStorageEnabled::class, function (CloudStorageEnabled $event) {
67
            $this->info("Connection enabled", $event->storage);
68
        });
69
    }
70
71
    /**
72
     * @param $message
73
     * @param $storage
74
     * @param array $context
75
     */
76
    protected function info($message, $storage, array $context = [])
77
    {
78
        Log::info($message, $this->getContext($storage, $context));
79
    }
80
81
    /**
82
     * @param $message
83
     * @param $storage
84
     * @param array $context
85
     */
86
    protected function warning($message, $storage, array $context = [])
87
    {
88
        Log::warning($message, $this->getContext($storage, $context));
89
    }
90
91
    /**
92
     * @param $message
93
     * @param $storage
94
     * @param array $context
95
     */
96
    protected function error($message, $storage, array $context = [])
97
    {
98
        Log::error($message, $this->getContext($storage, $context));
99
    }
100
101
    /**
102
     * @param $storage
103
     * @param array $context
104
     *
105
     * @return array
106
     */
107
    protected function getContext($storage, array $context = [])
108
    {
109
        return array_merge($context, [
110
            'storage' => $storage->id,
111
            'driver'  => $storage->driver,
112
            'owner'   => $storage->owner_description,
113
        ]);
114
    }
115
}
116