Increment::setInc()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
ccs 3
cts 3
cp 1
crap 1
1
<?php
2
/**
3
 * @author Todd Burry <[email protected]>
4
 * @copyright 2009-2017 Vanilla Forums Inc.
5
 * @license MIT
6
 */
7
8
namespace Garden\Db;
9
10
/**
11
 * Represents an incrementer calculation.
12
 *
13
 * Pass an instance of this class as a value to a database update call.
14
 */
15
class Increment extends Literal {
16
    /**
17
     * @var int The amount to increment.
18
     */
19
    private $inc;
20
21
    /**
22
     * Construct an increment.
23
     *
24
     * @param int $inc The amount to increment by.
25
     */
26 2
    public function __construct($inc = 1) {
27 2
        parent::__construct('%1$s %2$+d');
28 2
        $this->setInc($inc);
29 2
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34 2
    public function getValue(Db $db, ...$args) {
35 2
        if (empty($args)) {
36
            throw new \InvalidArgumentException("Increment must specify the column to increment.");
37
        }
38
39 2
        $args[1] = $this->getInc();
40 2
        return parent::getValue($db, ...$args);
41
    }
42
43
    /**
44
     * Get the amount to increment.
45
     *
46
     * @return int Returns a number.
47
     */
48 2
    public function getInc() {
49 2
        return $this->inc;
50
    }
51
52
    /**
53
     * Set the amount to increment.
54
     *
55
     * @param int $inc
56
     * @return $this
57
     */
58 2
    public function setInc($inc) {
59 2
        $this->inc = (int)$inc;
60 2
        return $this;
61
    }
62
}
63