FakePDO   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 3
eloc 3
c 2
b 1
f 0
dl 0
loc 25
rs 10

2 Methods

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