Constant::getName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of NACL.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @copyright 2019 Nuglif (2018) Inc.
9
 * @license   http://www.opensource.org/licenses/mit-license.html  MIT License
10
 * @author    Pierrick Charron <[email protected]>
11
 * @author    Charle Demers <[email protected]>
12
 */
13
14
declare(strict_types=1);
15
16
namespace Nuglif\Nacl\Macros;
17
18
use Nuglif\Nacl\MacroInterface;
19
20
class Constant implements MacroInterface
21
{
22 591
    public function getName(): string
23
    {
24 591
        return 'const';
25
    }
26
27 4
    public function execute(mixed $parameter, array $options = []): mixed
28
    {
29 4
        if (!is_string($parameter)) {
30 1
            throw new \InvalidArgumentException('Constant parameter must be a string');
31
        }
32
33 3
        if (!defined($parameter) && array_key_exists('default', $options)) {
34 1
            return $options['default'];
35
        }
36
37 2
        return constant($parameter);
38
    }
39
}
40