Passed
Push — master ( 1416ae...b5a8b1 )
by Luis
54s queued 13s
created

CodeParserConfiguration::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
nc 1
nop 1
dl 0
loc 12
ccs 11
cts 11
cp 1
crap 1
rs 9.9332
c 1
b 0
f 0
1
<?php declare(strict_types=1);
2
/**
3
 * PHP version 8.1
4
 *
5
 * This source file is subject to the license that is bundled with this package in the file LICENSE.
6
 */
7
8
namespace PhUml\Parser;
9
10
use Webmozart\Assert\Assert;
11
12
final class CodeParserConfiguration
13
{
14
    /** @var string */
15
    private const ASSOCIATIONS = 'associations';
16
17
    /** @var string */
18
    private const HIDE_PRIVATE = 'hide-private';
19
20
    /** @var string */
21
    private const HIDE_PROTECTED = 'hide-protected';
22
23
    /** @var string */
24
    private const HIDE_PROPERTIES = 'hide-attributes';
25
26
    /** @var string */
27
    private const HIDE_METHODS = 'hide-methods';
28
29
    private readonly bool $extractAssociations;
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_STRING, expecting T_VARIABLE on line 29 at column 21
Loading history...
30
31
    private readonly bool $hideProtected;
32
33
    private readonly bool $hidePrivate;
34
35
    private readonly bool $hideAttributes;
36
37
    private readonly bool $hideMethods;
38
39 5
    public static function defaultConfiguration(): CodeParserConfiguration
40
    {
41 5
        return new CodeParserConfiguration([
42
            self::ASSOCIATIONS => false,
43
            self::HIDE_PRIVATE => false,
44
            self::HIDE_PROTECTED => false,
45
            self::HIDE_PROPERTIES => false,
46
            self::HIDE_METHODS => false,
47
        ]);
48
    }
49
50
    /** @param mixed[] $options */
51 42
    public function __construct(array $options)
52
    {
53 42
        Assert::boolean($options[self::ASSOCIATIONS], 'Extract associations option must be a boolean value');
54 41
        $this->extractAssociations = $options[self::ASSOCIATIONS];
55 41
        Assert::boolean($options[self::HIDE_PRIVATE], 'Hide private members option must be a boolean value');
56 40
        $this->hidePrivate = $options[self::HIDE_PRIVATE];
57 40
        Assert::boolean($options[self::HIDE_PROTECTED], 'Hide protected members option must be a boolean value');
58 39
        $this->hideProtected = $options[self::HIDE_PROTECTED];
59 39
        Assert::boolean($options[self::HIDE_PROPERTIES], 'Hide attributes option must be a boolean value');
60 38
        $this->hideAttributes = $options[self::HIDE_PROPERTIES];
61 38
        Assert::boolean($options[self::HIDE_METHODS], 'Hide methods option must be a boolean value');
62 37
        $this->hideMethods = $options[self::HIDE_METHODS];
63
    }
64
65 31
    public function extractAssociations(): bool
66
    {
67 31
        return $this->extractAssociations;
68
    }
69
70 37
    public function hidePrivate(): bool
71
    {
72 37
        return $this->hidePrivate;
73
    }
74
75 37
    public function hideProtected(): bool
76
    {
77 37
        return $this->hideProtected;
78
    }
79
80 37
    public function hideAttributes(): bool
81
    {
82 37
        return $this->hideAttributes;
83
    }
84
85 37
    public function hideMethods(): bool
86
    {
87 37
        return $this->hideMethods;
88
    }
89
}
90