PlaybookDefenition::times()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Scaling\Playbook;
4
5
class PlaybookDefenition
6
{
7
    /**
8
     * The playbook identification.
9
     *
10
     * @var string
11
     */
12
    public $id;
13
14
    /**
15
     * The instance of the playbook.
16
     *
17
     * @var \Scaling\Playbook\Playbook
18
     */
19
    public $playbook;
20
21
    /**
22
     * Times the playbook needs to run.
23
     *
24
     * @var int
25
     */
26
    public $times = 1;
27
28
    /**
29
     * Playbook only has to run once.
30
     *
31
     * @var bool
32
     */
33
    public $once = false;
34
35
    /**
36
     * Create a new playbook instance.
37
     *
38
     * @param string $className
39
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
40
     */
41
    public function __construct(string $className)
42
    {
43
        $this->playbook = app($className);
44
        $this->id = get_class($this->playbook);
45
    }
46
47
    /**
48
     * Create a new playbook instance which has to run more than one time.
49
     *
50
     * @param string $className
51
     * @param int $times
52
     * @return \Scaling\Playbook\PlaybookDefenition
53
     */
54
    public static function times(string $className, int $times): self
55
    {
56
        $defenition = new self($className);
57
        $defenition->times = $times;
58
59
        return $defenition;
60
    }
61
62
    /**
63
     * Create a new playbook instance which only has to run once.
64
     *
65
     * @param string $className
66
     * @return \Scaling\Playbook\PlaybookDefenition
67
     */
68
    public static function once(string $className): self
69
    {
70
        $defenition = new self($className);
71
        $defenition->once = true;
72
73
        return $defenition;
74
    }
75
}
76