Passed
Pull Request — 3.x (#900)
by Anders
04:33
created

ASTPropertyHook::isFinal()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * This file is part of PDepend.
5
 *
6
 * PHP Version 5
7
 *
8
 * Copyright (c) 2008-2017 Manuel Pichler <[email protected]>.
9
 * All rights reserved.
10
 *
11
 * Redistribution and use in source and binary forms, with or without
12
 * modification, are permitted provided that the following conditions
13
 * are met:
14
 *
15
 *   * Redistributions of source code must retain the above copyright
16
 *     notice, this list of conditions and the following disclaimer.
17
 *
18
 *   * Redistributions in binary form must reproduce the above copyright
19
 *     notice, this list of conditions and the following disclaimer in
20
 *     the documentation and/or other materials provided with the
21
 *     distribution.
22
 *
23
 *   * Neither the name of Manuel Pichler nor the names of his
24
 *     contributors may be used to endorse or promote products derived
25
 *     from this software without specific prior written permission.
26
 *
27
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
30
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
34
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
37
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38
 * POSSIBILITY OF SUCH DAMAGE.
39
 *
40
 * @copyright 2008-2017 Manuel Pichler. All rights reserved.
41
 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
42
 */
43
44
namespace PDepend\Source\AST;
45
46
use InvalidArgumentException;
47
48
/**
49
 * Represents a PHP property hook node.
50
 *
51
 * @copyright 2008-2017 Manuel Pichler. All rights reserved.
52
 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
53
 */
54
class ASTPropertyHook extends AbstractASTCallable
55
{
56
    protected null|ASTFieldDeclaration|ASTFormalParameter $parentClass = null;
57
58
    /** Defined modifiers for this property node. */
59
    protected int $modifiers = 0;
60
61
    /**
62
     * The magic sleep method will be called by the PHP engine when this class
63
     * gets serialized. It returns an array with those properties that should be
64
     * cached for hook instances.
65
     *
66
     * @return list<string>
0 ignored issues
show
Bug introduced by
The type PDepend\Source\AST\list was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
67
     */
68
    public function __sleep(): array
69
    {
70
        return ['modifiers', ...parent::__sleep()];
0 ignored issues
show
Bug Best Practice introduced by
The expression return array('modifiers', parent::__sleep()) returns the type array<integer,array<integer,string>|string> which is incompatible with the documented return type PDepend\Source\AST\list.
Loading history...
71
    }
72
73
    /**
74
     * This method returns a OR combined integer of the declared modifiers for
75
     * this hook.
76
     */
77
    public function getModifiers(): int
78
    {
79
        return $this->modifiers;
80
    }
81
82
    /**
83
     * This method sets a OR combined integer of the declared modifiers for this
84
     * node.
85
     *
86
     * This method will throw an exception when the value of given <b>$modifiers</b>
87
     * contains an invalid/unexpected modifier
88
     *
89
     * @throws InvalidArgumentException If the given modifier contains unexpected values.
90
     */
91
    public function setModifiers(int $modifiers): void
92
    {
93
        $expected = ~State::IS_PUBLIC
94
                  & ~State::IS_PROTECTED
95
                  & ~State::IS_PRIVATE
96
                  & ~State::IS_FINAL;
97
98
        if (($expected & $modifiers) !== 0) {
99
            throw new InvalidArgumentException('Invalid hook modifier given.');
100
        }
101
102
        $this->modifiers = $modifiers;
103
    }
104
105
    /**
106
     * Returns <b>true</b> if this node is marked as public, otherwise the
107
     * returned value will be <b>false</b>.
108
     */
109
    public function isPublic(): bool
110
    {
111
        return (($this->modifiers & State::IS_PUBLIC) === State::IS_PUBLIC);
112
    }
113
114
    /**
115
     * Returns <b>true</b> if this node is marked as protected, otherwise the
116
     * returned value will be <b>false</b>.
117
     */
118
    public function isProtected(): bool
119
    {
120
        return (($this->modifiers & State::IS_PROTECTED) === State::IS_PROTECTED);
121
    }
122
123
    /**
124
     * Returns <b>true</b> if this node is marked as private, otherwise the
125
     * returned value will be <b>false</b>.
126
     */
127
    public function isPrivate(): bool
128
    {
129
        return (($this->modifiers & State::IS_PRIVATE) === State::IS_PRIVATE);
130
    }
131
132
    /**
133
     * Returns <b>true</b> when this node is declared as final, otherwise the
134
     * returned value will be <b>false</b>.
135
     */
136
    public function isFinal(): bool
137
    {
138
        return (($this->modifiers & State::IS_FINAL) === State::IS_FINAL);
139
    }
140
141
    /**
142
     * Returns the parent type object or <b>null</b>
143
     */
144
    public function getParent(): null|ASTFieldDeclaration|ASTFormalParameter
145
    {
146
        return $this->parentClass;
147
    }
148
149
    /**
150
     * Sets the parent type object.
151
     *
152
     * @param ASTFieldDeclaration|ASTFormalParameter|null $parent
153
     */
154
    public function setParent(?ASTNode $parent): void
155
    {
156
        $this->parentClass = $parent;
157
    }
158
}
159