Completed
Pull Request — master (#141)
by Raffael
11:16
created

CleanTempStorage   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 72
ccs 0
cts 30
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A setOptions() 0 20 5
A preExecuteAsyncJobs() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * balloon
7
 *
8
 * @copyright   Copryright (c) 2012-2018 gyselroth GmbH (https://gyselroth.com)
9
 * @license     GPL-3.0 https://opensource.org/licenses/GPL-3.0
10
 */
11
12
namespace Balloon\Hook;
13
14
use Balloon\Async\CleanTempStorage as Job;
15
use TaskScheduler\Async;
16
17
class CleanTempStorage extends AbstractHook
18
{
19
    /**
20
     * Execution interval.
21
     *
22
     * @var int
23
     */
24
    protected $interval = 172800;
25
26
    /**
27
     * max age.
28
     *
29
     * @var int
30
     */
31
    protected $max_age = 172800;
32
33
    /**
34
     * Async.
35
     *
36
     * @var Async
37
     */
38
    protected $async;
39
40
    /**
41
     * Constructor.
42
     *
43
     * @param iterable $config
44
     */
45
    public function __construct(Async $async, ?Iterable $config = null)
46
    {
47
        $this->async = $async;
48
        $this->setOptions($config);
49
    }
50
51
    /**
52
     * Set options.
53
     *
54
     * @param iterable $config
55
     */
56
    public function setOptions(?Iterable $config = null): HookInterface
57
    {
58
        if (null === $config) {
59
            return $this;
60
        }
61
62
        foreach ($config as $option => $value) {
63
            switch ($option) {
64
                case 'max_age':
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
65
                case 'interval':
66
                    $this->{$option} = (int) $value;
67
68
                break;
69
                default:
70
                    throw new Exception('invalid option '.$option.' given');
71
            }
72
        }
73
74
        return $this;
75
    }
76
77
    /**
78
     * {@inheritdoc}
79
     */
80
    public function preExecuteAsyncJobs(): void
81
    {
82
        $this->async->addJobOnce(Job::class, [
83
            'max_age' => $this->max_age,
84
        ], [
85
            'interval' => $this->interval,
86
        ]);
87
    }
88
}
89