Passed
Push — test ( b603bb...b43068 )
by Tom
02:32
created

Flags::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 1
nc 2
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 2
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
     * 19: FLAG_DOCKER_REMOVE (1) | FLAG_DOCKER_KILL (2) | FLAG_SOCKET (16)
16
     */
17
    const FLAGS = 19;
18
19
    /**
20
     * remove docker container after pipeline run
21
     */
22
    const FLAG_DOCKER_REMOVE = 1;
23
24
    /**
25
     * kill running docker container after pipeline run
26
     */
27
    const FLAG_DOCKER_KILL = 2;
28
29
    /**
30
     * use copy to deploy project into pipeline container
31
     */
32
    const FLAG_DEPLOY_COPY = 4; # copy working dir into container
33
34
    /**
35
     * keep pipeline container in case of error (non zero exit status)
36
     */
37
    const FLAG_KEEP_ON_ERROR = 8;
38
39
    /**
40
     * mount docker daemon socket into pipeline container (docker in docker)
41
     */
42
    const FLAG_SOCKET = 16;
43
44
    /**
45
     * do not make use of dependency caches
46
     */
47
    const FLAG_NO_CACHE = 32;
48
49
    /**
50
     * @var int flags bit-mask value
51
     */
52
    public $memory = self::FLAGS;
53
54
    /**
55
     * Flags constructor.
56
     *
57
     * @param int $memory [optional]
58
     */
59 10
    public function __construct($memory = null)
60
    {
61 10
        null === $memory || $this->memory = $memory;
62 10
    }
63
64
    /**
65
     * @return bool
66
     */
67 1
    public function deployCopy()
68
    {
69 1
        return (bool)($this->memory & self::FLAG_DEPLOY_COPY);
70
    }
71
72
    /**
73
     * @return bool
74
     */
75 1
    public function keep()
76
    {
77 1
        return !($this->memory & (self::FLAG_DOCKER_KILL | self::FLAG_DOCKER_REMOVE));
78
    }
79
80
    /**
81
     * @return bool
82
     */
83 1
    public function keepOnError()
84
    {
85 1
        return (bool)($this->memory & self::FLAG_KEEP_ON_ERROR);
86
    }
87
88
    /**
89
     * @return bool
90
     */
91 1
    public function killContainer()
92
    {
93 1
        return (bool)($this->memory & self::FLAG_DOCKER_KILL);
94
    }
95
96
    /**
97
     * @return bool
98
     */
99 1
    public function removeContainer()
100
    {
101 1
        return (bool)($this->memory & self::FLAG_DOCKER_REMOVE);
102
    }
103
104
    /**
105
     * @return bool
106
     */
107 1
    public function reuseContainer()
108
    {
109
        return
110 1
            ($this->memory & self::FLAG_KEEP_ON_ERROR)
111 1
            || !($this->memory & (self::FLAG_DOCKER_KILL | self::FLAG_DOCKER_REMOVE));
112
    }
113
114
    /**
115
     * @return bool
116
     */
117 1
    public function useDockerSocket()
118
    {
119 1
        return (bool)($this->memory & self::FLAG_SOCKET);
120
    }
121
122
    /**
123
     * @return bool
124
     */
125 1
    public function noCache()
126
    {
127 1
        return (bool)($this->memory & self::FLAG_NO_CACHE);
128
    }
129
130
    /**
131
     * @param int $flag
132
     *
133
     * @return bool
134
     */
135 1
    public function flgHas($flag)
136
    {
137 1
        return (bool)($this->memory & $flag);
138
    }
139
}
140