DriverNotFoundException::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0932

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 1
dl 0
loc 10
ccs 5
cts 7
cp 0.7143
crap 2.0932
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace Wandu\Database\Exception;
3
4
use RuntimeException;
5
6
class DriverNotFoundException extends RuntimeException
7
{
8
    const CODE_UNDEFINED = 1;
9
    const CODE_UNSUPPORTED = 2;
10
11
    /**
12
     * @param string $driver
13
     */
14 1
    public function __construct($driver = null)
15
    {
16 1
        if ($driver) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $driver of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
17 1
            $this->code = static::CODE_UNSUPPORTED;
18 1
            $this->message = "\"{$driver}\" is not supported.";
19
        } else {
20
            $this->code = static::CODE_UNDEFINED;
21
            $this->message = "driver is not defined.";
22
        }
23 1
    }
24
}
25