Passed
Push — master ( 418178...dff5b7 )
by Aleksandar
02:11
created

CaseWhen::else()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 3
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
/**
3
 * Copyright 2021 Aleksandar Panic
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 *   http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
18
namespace ArekX\PQL\Sql\Statement;
19
20
use ArekX\PQL\Contracts\StructuredQuery;
21
use ArekX\PQL\Query;
22
23
/**
24
 * Represents a CASE statement.
25
 */
26
class CaseWhen extends Query
27
{
28
    /**
29
     * Of value to be set for the CASE
30
     *
31
     * @param array|StructuredQuery $of
32
     * @return $this
33
     */
34 1
    public function of($of)
35
    {
36 1
        $this->use('of', $of);
37 1
        return $this;
38
    }
39
40
    /**
41
     * When cases to be set
42
     *
43
     * @param array|StructuredQuery[] $when
44
     * @return $this
45
     */
46 1
    public function when($when)
47
    {
48 1
        $this->use('when', $when);
49 1
        return $this;
50
    }
51
52
    /**
53
     * Appends another WHEN case
54
     *
55
     * @param array|StructuredQuery $when Condition
56
     * @param array|StructuredQuery $then Result
57
     * @return $this
58
     */
59 1
    public function addWhen($when, $then)
60
    {
61 1
        $this->append('when', [$when, $then]);
62 1
        return $this;
63
    }
64
65
    /**
66
     * Adds else for default case
67
     *
68
     * @param array|StructuredQuery $else Else result.
69
     * @return $this
70
     */
71 1
    public function else($else)
72
    {
73 1
        $this->use('else', $else);
74 1
        return $this;
75
    }
76
}