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

PdoValue   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 39
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getType() 0 3 1
A __construct() 0 4 1
A getValue() 0 3 1
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