Failed Conditions
Pull Request — develop (#3348)
by Sergei
21:04
created

Identifier::__construct()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 3
nc 2
nop 2
crap 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\DBAL\Schema;
6
7
use function assert;
8
use function is_string;
9
10
/**
11
 * An abstraction class for an asset identifier.
12
 *
13
 * Wraps identifier names like column names in indexes / foreign keys
14
 * in an abstract class for proper quotation capabilities.
15
 */
16
class Identifier extends AbstractAsset
17
{
18
    /**
19
     * @param string $identifier Identifier name to wrap.
20
     * @param bool   $quote      Whether to force quoting the given identifier.
21
     */
22 20779
    public function __construct(string $identifier, bool $quote = false)
23
    {
24 20779
        $this->_setName($identifier);
25
26 20779
        if (! $quote || $this->_quoted) {
27 20779
            return;
28
        }
29
30 10663
        $this->_setName('"' . $this->getName() . '"');
31 10663
    }
32
33 20675
    public function getName() : string
34
    {
35 20675
        $name = parent::getName();
36 20675
        assert(is_string($name));
37
38 20675
        return $name;
39
    }
40
}
41