Passed
Push — unix_timestamp_zero ( 021a5e...8f7601 )
by Jonathan
13:08 queued 11:41
created

FakePDO::getAttribute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Vectorface\Tests\MySQLite\Util;
4
5
/**
6
 * Work around mocking issue in PDO.
7
 *
8
 * Credit: http://erichogue.ca/2013/02/best-practices/mocking-pdo-in-phpunit/
9
 */
10
class FakePDO extends \PDO
11
{
12
    /**
13
     * Empty constructor.
14
     */
15
    public function __construct()
16
    {
17
    }
18
19
    /**
20
     * A map of attributes to be passed back from getAttribute.
21
     *
22
     * @var mixed[]
23
     */
24
    public $attributes = [];
25
26
    /**
27
     * Get the value of an attribute. Uses an element of the Attributes array if available, falling back to parent.
28
     *
29
     * @param mixed $attr The attribute whose value is to be fetched.
30
     * @return mixed The value of the attribute.
31
     */
32
    public function getAttribute($attr): mixed
33
    {
34
        return isset($this->attributes[$attr]) ? $this->attributes[$attr] : parent::getAttribute($attr);
35
    }
36
}
37