SleepTask::getOptions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 1
rs 10
1
<?php
2
3
/*
4
 * This file is part of the Magallanes package.
5
 *
6
 * (c) Andrés Montañez <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Mage\Task\BuiltIn;
13
14
use Mage\Task\Exception\ErrorException;
15
use Mage\Task\AbstractTask;
16
17
/**
18
 * Sleep task. Sleeps for a given number of seconds so you can delay task
19
 * execution.
20
 *
21
 * @author Yanick Witschi <https://github.com/Toflar>
22
 */
23
class SleepTask extends AbstractTask
24
{
25 48
    public function getName(): string
26
    {
27 48
        return 'sleep';
28
    }
29
30 2
    public function getDescription(): string
31
    {
32 2
        $options = $this->getOptions();
33
34 2
        return sprintf('[Sleep] Sleeping for %d second(s)', $options['seconds']);
35
    }
36
37
    /**
38
     * @throws ErrorException
39
     */
40 2
    public function execute(): bool
41
    {
42 2
        $options = $this->getOptions();
43
44 2
        sleep(intval($options['seconds']));
45
46 2
        return true;
47
    }
48
49
    /**
50
     * @return array<string, string|int>
51
     */
52 2
    protected function getOptions(): array
53
    {
54 2
        $options = array_merge(
55 2
            ['seconds' => 1],
56 2
            $this->options
57
        );
58
59 2
        return $options;
60
    }
61
}
62