Passed
Pull Request — 2.2 (#19879)
by Wilmer
05:27
created

PdoValue::getType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @link https://www.yiiframework.com/
4
 * @copyright Copyright (c) 2008 Yii Software LLC
5
 * @license https://www.yiiframework.com/license/
6
 */
7
8
namespace yii\db;
9
10
/**
11
 * Class PdoValue represents a $value that should be bound to PDO with exact $type.
12
 *
13
 * For example, it will be useful when you need to bind binary data to BLOB column in DBMS:
14
 *
15
 * ```php
16
 * [':name' => 'John', ':profile' => new PdoValue($profile, \PDO::PARAM_LOB)]`.
17
 * ```
18
 *
19
 * To see possible types, check [PDO::PARAM_* constants](https://www.php.net/manual/en/pdo.constants.php).
20
 *
21
 * @see https://www.php.net/manual/en/pdostatement.bindparam.php
22
 * @author Dmytro Naumenko <[email protected]>
23
 * @since 2.0.14
24
 */
25
final class PdoValue implements ExpressionInterface
26
{
27
    /**
28
     * @var mixed
29
     */
30
    private $value;
31
    /**
32
     * @var int One of PDO_PARAM_* constants
33
     * @see https://www.php.net/manual/en/pdo.constants.php
34
     */
35
    private $type;
36
37
38
    /**
39
     * PdoValue constructor.
40
     *
41
     * @param $value
42
     * @param $type
43
     */
44
    public function __construct($value, $type)
45
    {
46
        $this->value = $value;
47
        $this->type = $type;
48
    }
49
50
    /**
51
     * @return mixed
52
     */
53
    public function getValue()
54
    {
55
        return $this->value;
56
    }
57
58
    /**
59
     * @return int
60
     */
61
    public function getType()
62
    {
63
        return $this->type;
64
    }
65
}
66