Passed
Push — test ( d6edfc...f7394f )
by Tom
02:30
created

Flags::keep()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
/* this file is part of pipelines */
4
5
namespace Ktomk\Pipelines\Runner;
6
7
/**
8
 * Flags for use in Runner
9
 */
10
class Flags
11
{
12
    /**
13
     * default flags
14
     */
15
    const FLAGS = 19;
16
17
    /**
18
     * remove docker container after pipeline run
19
     */
20
    const FLAG_DOCKER_REMOVE = 1;
21
22
    /**
23
     * kill running docker container after pipeline run
24
     */
25
    const FLAG_DOCKER_KILL = 2;
26
27
    /**
28
     * use copy to deploy project into pipeline container
29
     */
30
    const FLAG_DEPLOY_COPY = 4; # copy working dir into container
31
32
    /**
33
     * keep pipeline container in case of error (non zero exit status)
34
     */
35
    const FLAG_KEEP_ON_ERROR = 8;
36
37
    /**
38
     * mount docker daemon socket into pipeline container (docker in docker)
39
     */
40
    const FLAG_SOCKET = 16;
41
42
    /**
43
     * @var int flags bit-mask value
44
     */
45
    public $memory = self::FLAGS;
46
47
    /**
48
     * Flags constructor.
49
     *
50
     * @param int $memory [optional]
51
     */
52 9
    public function __construct($memory = null)
53
    {
54 9
        null === $memory || $this->memory = $memory;
55 9
    }
56
57
    /**
58
     * @return bool
59
     */
60 1
    public function deployCopy()
61
    {
62 1
        return (bool)($this->memory & self::FLAG_DEPLOY_COPY);
63
    }
64
65
    /**
66
     * @return bool
67
     */
68 1
    public function keep()
69
    {
70 1
        return !($this->memory & (self::FLAG_DOCKER_KILL | self::FLAG_DOCKER_REMOVE));
71
    }
72
73
    /**
74
     * @return bool
75
     */
76 1
    public function keepOnError()
77
    {
78 1
        return (bool)($this->memory & self::FLAG_KEEP_ON_ERROR);
79
    }
80
81
    /**
82
     * @return bool
83
     */
84 1
    public function killContainer()
85
    {
86 1
        return (bool)($this->memory & self::FLAG_DOCKER_KILL);
87
    }
88
89
    /**
90
     * @return bool
91
     */
92 1
    public function removeContainer()
93
    {
94 1
        return (bool)($this->memory & self::FLAG_DOCKER_REMOVE);
95
    }
96
97
    /**
98
     * @return bool
99
     */
100 1
    public function reuseContainer()
101
    {
102
        return
103 1
            ($this->memory & self::FLAG_KEEP_ON_ERROR)
104 1
            || !($this->memory & (self::FLAG_DOCKER_KILL | self::FLAG_DOCKER_REMOVE));
105
    }
106
107
    /**
108
     * @return bool
109
     */
110 1
    public function useDockerSocket()
111
    {
112 1
        return (bool)($this->memory & self::FLAG_SOCKET);
113
    }
114
115 1
    public function flgHas($flag)
116
    {
117 1
        return (bool)($this->memory & $flag);
118
    }
119
}
120