Completed
Pull Request — master (#430)
by
unknown
02:43
created
php-scoper/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/StaticVar.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -7,31 +7,31 @@
 block discarded – undo
7 7
 
8 8
 class StaticVar extends Node\Stmt
9 9
 {
10
-    /** @var Expr\Variable Variable */
11
-    public $var;
12
-    /** @var null|Node\Expr Default value */
13
-    public $default;
10
+	/** @var Expr\Variable Variable */
11
+	public $var;
12
+	/** @var null|Node\Expr Default value */
13
+	public $default;
14 14
 
15
-    /**
16
-     * Constructs a static variable node.
17
-     *
18
-     * @param Expr\Variable  $var         Name
19
-     * @param null|Node\Expr $default    Default value
20
-     * @param array          $attributes Additional attributes
21
-     */
22
-    public function __construct(
23
-        Expr\Variable $var, ?Node\Expr $default = null, array $attributes = []
24
-    ) {
25
-        $this->attributes = $attributes;
26
-        $this->var = $var;
27
-        $this->default = $default;
28
-    }
15
+	/**
16
+	 * Constructs a static variable node.
17
+	 *
18
+	 * @param Expr\Variable  $var         Name
19
+	 * @param null|Node\Expr $default    Default value
20
+	 * @param array          $attributes Additional attributes
21
+	 */
22
+	public function __construct(
23
+		Expr\Variable $var, ?Node\Expr $default = null, array $attributes = []
24
+	) {
25
+		$this->attributes = $attributes;
26
+		$this->var = $var;
27
+		$this->default = $default;
28
+	}
29 29
 
30
-    public function getSubNodeNames() : array {
31
-        return ['var', 'default'];
32
-    }
30
+	public function getSubNodeNames() : array {
31
+		return ['var', 'default'];
32
+	}
33 33
     
34
-    public function getType() : string {
35
-        return 'Stmt_StaticVar';
36
-    }
34
+	public function getType() : string {
35
+		return 'Stmt_StaticVar';
36
+	}
37 37
 }
Please login to merge, or discard this patch.
php-scoper/vendor/nikic/php-parser/lib/PhpParser/Node/FunctionLike.php 2 patches
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -6,38 +6,38 @@
 block discarded – undo
6 6
 
7 7
 interface FunctionLike extends Node
8 8
 {
9
-    /**
10
-     * Whether to return by reference
11
-     *
12
-     * @return bool
13
-     */
14
-    public function returnsByRef() : bool;
9
+	/**
10
+	 * Whether to return by reference
11
+	 *
12
+	 * @return bool
13
+	 */
14
+	public function returnsByRef() : bool;
15 15
 
16
-    /**
17
-     * List of parameters
18
-     *
19
-     * @return Param[]
20
-     */
21
-    public function getParams() : array;
16
+	/**
17
+	 * List of parameters
18
+	 *
19
+	 * @return Param[]
20
+	 */
21
+	public function getParams() : array;
22 22
 
23
-    /**
24
-     * Get the declared return type or null
25
-     *
26
-     * @return null|Identifier|Name|ComplexType
27
-     */
28
-    public function getReturnType();
23
+	/**
24
+	 * Get the declared return type or null
25
+	 *
26
+	 * @return null|Identifier|Name|ComplexType
27
+	 */
28
+	public function getReturnType();
29 29
 
30
-    /**
31
-     * The function body
32
-     *
33
-     * @return Stmt[]|null
34
-     */
35
-    public function getStmts();
30
+	/**
31
+	 * The function body
32
+	 *
33
+	 * @return Stmt[]|null
34
+	 */
35
+	public function getStmts();
36 36
 
37
-    /**
38
-     * Get PHP attribute groups.
39
-     *
40
-     * @return AttributeGroup[]
41
-     */
42
-    public function getAttrGroups() : array;
37
+	/**
38
+	 * Get PHP attribute groups.
39
+	 *
40
+	 * @return AttributeGroup[]
41
+	 */
42
+	public function getAttrGroups() : array;
43 43
 }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -4,8 +4,7 @@
 block discarded – undo
4 4
 
5 5
 use PhpParser\Node;
6 6
 
7
-interface FunctionLike extends Node
8
-{
7
+interface FunctionLike extends Node {
9 8
     /**
10 9
      * Whether to return by reference
11 10
      *
Please login to merge, or discard this patch.
vendor-bin/php-scoper/vendor/nikic/php-parser/lib/PhpParser/Node/Param.php 2 patches
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -6,55 +6,55 @@
 block discarded – undo
6 6
 
7 7
 class Param extends NodeAbstract
8 8
 {
9
-    /** @var null|Identifier|Name|ComplexType Type declaration */
10
-    public $type;
11
-    /** @var bool Whether parameter is passed by reference */
12
-    public $byRef;
13
-    /** @var bool Whether this is a variadic argument */
14
-    public $variadic;
15
-    /** @var Expr\Variable|Expr\Error Parameter variable */
16
-    public $var;
17
-    /** @var null|Expr Default value */
18
-    public $default;
19
-    /** @var int */
20
-    public $flags;
21
-    /** @var AttributeGroup[] PHP attribute groups */
22
-    public $attrGroups;
9
+	/** @var null|Identifier|Name|ComplexType Type declaration */
10
+	public $type;
11
+	/** @var bool Whether parameter is passed by reference */
12
+	public $byRef;
13
+	/** @var bool Whether this is a variadic argument */
14
+	public $variadic;
15
+	/** @var Expr\Variable|Expr\Error Parameter variable */
16
+	public $var;
17
+	/** @var null|Expr Default value */
18
+	public $default;
19
+	/** @var int */
20
+	public $flags;
21
+	/** @var AttributeGroup[] PHP attribute groups */
22
+	public $attrGroups;
23 23
 
24
-    /**
25
-     * Constructs a parameter node.
26
-     *
27
-     * @param Expr\Variable|Expr\Error                $var        Parameter variable
28
-     * @param null|Expr                               $default    Default value
29
-     * @param null|string|Identifier|Name|ComplexType $type       Type declaration
30
-     * @param bool                                    $byRef      Whether is passed by reference
31
-     * @param bool                                    $variadic   Whether this is a variadic argument
32
-     * @param array                                   $attributes Additional attributes
33
-     * @param int                                     $flags      Optional visibility flags
34
-     * @param AttributeGroup[]                        $attrGroups PHP attribute groups
35
-     */
36
-    public function __construct(
37
-        $var, ?Expr $default = null, $type = null,
38
-        bool $byRef = false, bool $variadic = false,
39
-        array $attributes = [],
40
-        int $flags = 0,
41
-        array $attrGroups = []
42
-    ) {
43
-        $this->attributes = $attributes;
44
-        $this->type = \is_string($type) ? new Identifier($type) : $type;
45
-        $this->byRef = $byRef;
46
-        $this->variadic = $variadic;
47
-        $this->var = $var;
48
-        $this->default = $default;
49
-        $this->flags = $flags;
50
-        $this->attrGroups = $attrGroups;
51
-    }
24
+	/**
25
+	 * Constructs a parameter node.
26
+	 *
27
+	 * @param Expr\Variable|Expr\Error                $var        Parameter variable
28
+	 * @param null|Expr                               $default    Default value
29
+	 * @param null|string|Identifier|Name|ComplexType $type       Type declaration
30
+	 * @param bool                                    $byRef      Whether is passed by reference
31
+	 * @param bool                                    $variadic   Whether this is a variadic argument
32
+	 * @param array                                   $attributes Additional attributes
33
+	 * @param int                                     $flags      Optional visibility flags
34
+	 * @param AttributeGroup[]                        $attrGroups PHP attribute groups
35
+	 */
36
+	public function __construct(
37
+		$var, ?Expr $default = null, $type = null,
38
+		bool $byRef = false, bool $variadic = false,
39
+		array $attributes = [],
40
+		int $flags = 0,
41
+		array $attrGroups = []
42
+	) {
43
+		$this->attributes = $attributes;
44
+		$this->type = \is_string($type) ? new Identifier($type) : $type;
45
+		$this->byRef = $byRef;
46
+		$this->variadic = $variadic;
47
+		$this->var = $var;
48
+		$this->default = $default;
49
+		$this->flags = $flags;
50
+		$this->attrGroups = $attrGroups;
51
+	}
52 52
 
53
-    public function getSubNodeNames() : array {
54
-        return ['attrGroups', 'flags', 'type', 'byRef', 'variadic', 'var', 'default'];
55
-    }
53
+	public function getSubNodeNames() : array {
54
+		return ['attrGroups', 'flags', 'type', 'byRef', 'variadic', 'var', 'default'];
55
+	}
56 56
 
57
-    public function getType() : string {
58
-        return 'Param';
59
-    }
57
+	public function getType() : string {
58
+		return 'Param';
59
+	}
60 60
 }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -4,8 +4,7 @@
 block discarded – undo
4 4
 
5 5
 use PhpParser\NodeAbstract;
6 6
 
7
-class Param extends NodeAbstract
8
-{
7
+class Param extends NodeAbstract {
9 8
     /** @var null|Identifier|Name|ComplexType Type declaration */
10 9
     public $type;
11 10
     /** @var bool Whether parameter is passed by reference */
Please login to merge, or discard this patch.
vendor-bin/php-scoper/vendor/nikic/php-parser/lib/PhpParser/Node/Stmt.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -4,6 +4,5 @@
 block discarded – undo
4 4
 
5 5
 use PhpParser\NodeAbstract;
6 6
 
7
-abstract class Stmt extends NodeAbstract
8
-{
7
+abstract class Stmt extends NodeAbstract {
9 8
 }
Please login to merge, or discard this patch.
php-scoper/vendor/nikic/php-parser/lib/PhpParser/Node/MatchArm.php 2 patches
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -7,25 +7,25 @@
 block discarded – undo
7 7
 
8 8
 class MatchArm extends NodeAbstract
9 9
 {
10
-    /** @var null|Node\Expr[] */
11
-    public $conds;
12
-    /** @var Node\Expr */
13
-    public $body;
10
+	/** @var null|Node\Expr[] */
11
+	public $conds;
12
+	/** @var Node\Expr */
13
+	public $body;
14 14
 
15
-    /**
16
-     * @param null|Node\Expr[] $conds
17
-     */
18
-    public function __construct($conds, Node\Expr $body, array $attributes = []) {
19
-        $this->conds = $conds;
20
-        $this->body = $body;
21
-        $this->attributes = $attributes;
22
-    }
15
+	/**
16
+	 * @param null|Node\Expr[] $conds
17
+	 */
18
+	public function __construct($conds, Node\Expr $body, array $attributes = []) {
19
+		$this->conds = $conds;
20
+		$this->body = $body;
21
+		$this->attributes = $attributes;
22
+	}
23 23
 
24
-    public function getSubNodeNames() : array {
25
-        return ['conds', 'body'];
26
-    }
24
+	public function getSubNodeNames() : array {
25
+		return ['conds', 'body'];
26
+	}
27 27
 
28
-    public function getType() : string {
29
-        return 'MatchArm';
30
-    }
28
+	public function getType() : string {
29
+		return 'MatchArm';
30
+	}
31 31
 }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -5,8 +5,7 @@
 block discarded – undo
5 5
 use PhpParser\Node;
6 6
 use PhpParser\NodeAbstract;
7 7
 
8
-class MatchArm extends NodeAbstract
9
-{
8
+class MatchArm extends NodeAbstract {
10 9
     /** @var null|Node\Expr[] */
11 10
     public $conds;
12 11
     /** @var Node\Expr */
Please login to merge, or discard this patch.
vendor-bin/php-scoper/vendor/nikic/php-parser/lib/PhpParser/Node/Expr.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -4,6 +4,5 @@
 block discarded – undo
4 4
 
5 5
 use PhpParser\NodeAbstract;
6 6
 
7
-abstract class Expr extends NodeAbstract
8
-{
7
+abstract class Expr extends NodeAbstract {
9 8
 }
Please login to merge, or discard this patch.
php-scoper/vendor/nikic/php-parser/lib/PhpParser/Node/Attribute.php 2 patches
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -7,28 +7,28 @@
 block discarded – undo
7 7
 
8 8
 class Attribute extends NodeAbstract
9 9
 {
10
-    /** @var Name Attribute name */
11
-    public $name;
10
+	/** @var Name Attribute name */
11
+	public $name;
12 12
 
13
-    /** @var Arg[] Attribute arguments */
14
-    public $args;
13
+	/** @var Arg[] Attribute arguments */
14
+	public $args;
15 15
 
16
-    /**
17
-     * @param Node\Name $name       Attribute name
18
-     * @param Arg[]     $args       Attribute arguments
19
-     * @param array     $attributes Additional node attributes
20
-     */
21
-    public function __construct(Name $name, array $args = [], array $attributes = []) {
22
-        $this->attributes = $attributes;
23
-        $this->name = $name;
24
-        $this->args = $args;
25
-    }
16
+	/**
17
+	 * @param Node\Name $name       Attribute name
18
+	 * @param Arg[]     $args       Attribute arguments
19
+	 * @param array     $attributes Additional node attributes
20
+	 */
21
+	public function __construct(Name $name, array $args = [], array $attributes = []) {
22
+		$this->attributes = $attributes;
23
+		$this->name = $name;
24
+		$this->args = $args;
25
+	}
26 26
 
27
-    public function getSubNodeNames() : array {
28
-        return ['name', 'args'];
29
-    }
27
+	public function getSubNodeNames() : array {
28
+		return ['name', 'args'];
29
+	}
30 30
 
31
-    public function getType() : string {
32
-        return 'Attribute';
33
-    }
31
+	public function getType() : string {
32
+		return 'Attribute';
33
+	}
34 34
 }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -5,8 +5,7 @@
 block discarded – undo
5 5
 use PhpParser\Node;
6 6
 use PhpParser\NodeAbstract;
7 7
 
8
-class Attribute extends NodeAbstract
9
-{
8
+class Attribute extends NodeAbstract {
10 9
     /** @var Name Attribute name */
11 10
     public $name;
12 11
 
Please login to merge, or discard this patch.
php-scoper/vendor/nikic/php-parser/lib/PhpParser/Node/UnionType.php 2 patches
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -4,25 +4,25 @@
 block discarded – undo
4 4
 
5 5
 class UnionType extends ComplexType
6 6
 {
7
-    /** @var (Identifier|Name|IntersectionType)[] Types */
8
-    public $types;
7
+	/** @var (Identifier|Name|IntersectionType)[] Types */
8
+	public $types;
9 9
 
10
-    /**
11
-     * Constructs a union type.
12
-     *
13
-     * @param (Identifier|Name|IntersectionType)[] $types      Types
14
-     * @param array               $attributes Additional attributes
15
-     */
16
-    public function __construct(array $types, array $attributes = []) {
17
-        $this->attributes = $attributes;
18
-        $this->types = $types;
19
-    }
10
+	/**
11
+	 * Constructs a union type.
12
+	 *
13
+	 * @param (Identifier|Name|IntersectionType)[] $types      Types
14
+	 * @param array               $attributes Additional attributes
15
+	 */
16
+	public function __construct(array $types, array $attributes = []) {
17
+		$this->attributes = $attributes;
18
+		$this->types = $types;
19
+	}
20 20
 
21
-    public function getSubNodeNames() : array {
22
-        return ['types'];
23
-    }
21
+	public function getSubNodeNames() : array {
22
+		return ['types'];
23
+	}
24 24
     
25
-    public function getType() : string {
26
-        return 'UnionType';
27
-    }
25
+	public function getType() : string {
26
+		return 'UnionType';
27
+	}
28 28
 }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -2,8 +2,7 @@
 block discarded – undo
2 2
 
3 3
 namespace PhpParser\Node;
4 4
 
5
-class UnionType extends ComplexType
6
-{
5
+class UnionType extends ComplexType {
7 6
     /** @var (Identifier|Name|IntersectionType)[] Types */
8 7
     public $types;
9 8
 
Please login to merge, or discard this patch.
vendor-bin/php-scoper/vendor/nikic/php-parser/lib/PhpParser/Node/Name.php 2 patches
Indentation   +245 added lines, -245 removed lines patch added patch discarded remove patch
@@ -6,249 +6,249 @@
 block discarded – undo
6 6
 
7 7
 class Name extends NodeAbstract
8 8
 {
9
-    /**
10
-     * @var string[] Parts of the name
11
-     * @deprecated Use getParts() instead
12
-     */
13
-    public $parts;
14
-
15
-    private static $specialClassNames = [
16
-        'self'   => true,
17
-        'parent' => true,
18
-        'static' => true,
19
-    ];
20
-
21
-    /**
22
-     * Constructs a name node.
23
-     *
24
-     * @param string|string[]|self $name       Name as string, part array or Name instance (copy ctor)
25
-     * @param array                $attributes Additional attributes
26
-     */
27
-    public function __construct($name, array $attributes = []) {
28
-        $this->attributes = $attributes;
29
-        $this->parts = self::prepareName($name);
30
-    }
31
-
32
-    public function getSubNodeNames() : array {
33
-        return ['parts'];
34
-    }
35
-
36
-    /**
37
-     * Get parts of name (split by the namespace separator).
38
-     *
39
-     * @return string[] Parts of name
40
-     */
41
-    public function getParts(): array {
42
-        return $this->parts;
43
-    }
44
-
45
-    /**
46
-     * Gets the first part of the name, i.e. everything before the first namespace separator.
47
-     *
48
-     * @return string First part of the name
49
-     */
50
-    public function getFirst() : string {
51
-        return $this->parts[0];
52
-    }
53
-
54
-    /**
55
-     * Gets the last part of the name, i.e. everything after the last namespace separator.
56
-     *
57
-     * @return string Last part of the name
58
-     */
59
-    public function getLast() : string {
60
-        return $this->parts[count($this->parts) - 1];
61
-    }
62
-
63
-    /**
64
-     * Checks whether the name is unqualified. (E.g. Name)
65
-     *
66
-     * @return bool Whether the name is unqualified
67
-     */
68
-    public function isUnqualified() : bool {
69
-        return 1 === count($this->parts);
70
-    }
71
-
72
-    /**
73
-     * Checks whether the name is qualified. (E.g. Name\Name)
74
-     *
75
-     * @return bool Whether the name is qualified
76
-     */
77
-    public function isQualified() : bool {
78
-        return 1 < count($this->parts);
79
-    }
80
-
81
-    /**
82
-     * Checks whether the name is fully qualified. (E.g. \Name)
83
-     *
84
-     * @return bool Whether the name is fully qualified
85
-     */
86
-    public function isFullyQualified() : bool {
87
-        return false;
88
-    }
89
-
90
-    /**
91
-     * Checks whether the name is explicitly relative to the current namespace. (E.g. namespace\Name)
92
-     *
93
-     * @return bool Whether the name is relative
94
-     */
95
-    public function isRelative() : bool {
96
-        return false;
97
-    }
98
-
99
-    /**
100
-     * Returns a string representation of the name itself, without taking the name type into
101
-     * account (e.g., not including a leading backslash for fully qualified names).
102
-     *
103
-     * @return string String representation
104
-     */
105
-    public function toString() : string {
106
-        return implode('\\', $this->parts);
107
-    }
108
-
109
-    /**
110
-     * Returns a string representation of the name as it would occur in code (e.g., including
111
-     * leading backslash for fully qualified names.
112
-     *
113
-     * @return string String representation
114
-     */
115
-    public function toCodeString() : string {
116
-        return $this->toString();
117
-    }
118
-
119
-    /**
120
-     * Returns lowercased string representation of the name, without taking the name type into
121
-     * account (e.g., no leading backslash for fully qualified names).
122
-     *
123
-     * @return string Lowercased string representation
124
-     */
125
-    public function toLowerString() : string {
126
-        return strtolower(implode('\\', $this->parts));
127
-    }
128
-
129
-    /**
130
-     * Checks whether the identifier is a special class name (self, parent or static).
131
-     *
132
-     * @return bool Whether identifier is a special class name
133
-     */
134
-    public function isSpecialClassName() : bool {
135
-        return count($this->parts) === 1
136
-            && isset(self::$specialClassNames[strtolower($this->parts[0])]);
137
-    }
138
-
139
-    /**
140
-     * Returns a string representation of the name by imploding the namespace parts with the
141
-     * namespace separator.
142
-     *
143
-     * @return string String representation
144
-     */
145
-    public function __toString() : string {
146
-        return implode('\\', $this->parts);
147
-    }
148
-
149
-    /**
150
-     * Gets a slice of a name (similar to array_slice).
151
-     *
152
-     * This method returns a new instance of the same type as the original and with the same
153
-     * attributes.
154
-     *
155
-     * If the slice is empty, null is returned. The null value will be correctly handled in
156
-     * concatenations using concat().
157
-     *
158
-     * Offset and length have the same meaning as in array_slice().
159
-     *
160
-     * @param int      $offset Offset to start the slice at (may be negative)
161
-     * @param int|null $length Length of the slice (may be negative)
162
-     *
163
-     * @return static|null Sliced name
164
-     */
165
-    public function slice(int $offset, ?int $length = null) {
166
-        $numParts = count($this->parts);
167
-
168
-        $realOffset = $offset < 0 ? $offset + $numParts : $offset;
169
-        if ($realOffset < 0 || $realOffset > $numParts) {
170
-            throw new \OutOfBoundsException(sprintf('Offset %d is out of bounds', $offset));
171
-        }
172
-
173
-        if (null === $length) {
174
-            $realLength = $numParts - $realOffset;
175
-        } else {
176
-            $realLength = $length < 0 ? $length + $numParts - $realOffset : $length;
177
-            if ($realLength < 0 || $realLength > $numParts - $realOffset) {
178
-                throw new \OutOfBoundsException(sprintf('Length %d is out of bounds', $length));
179
-            }
180
-        }
181
-
182
-        if ($realLength === 0) {
183
-            // Empty slice is represented as null
184
-            return null;
185
-        }
186
-
187
-        return new static(array_slice($this->parts, $realOffset, $realLength), $this->attributes);
188
-    }
189
-
190
-    /**
191
-     * Concatenate two names, yielding a new Name instance.
192
-     *
193
-     * The type of the generated instance depends on which class this method is called on, for
194
-     * example Name\FullyQualified::concat() will yield a Name\FullyQualified instance.
195
-     *
196
-     * If one of the arguments is null, a new instance of the other name will be returned. If both
197
-     * arguments are null, null will be returned. As such, writing
198
-     *     Name::concat($namespace, $shortName)
199
-     * where $namespace is a Name node or null will work as expected.
200
-     *
201
-     * @param string|string[]|self|null $name1      The first name
202
-     * @param string|string[]|self|null $name2      The second name
203
-     * @param array                     $attributes Attributes to assign to concatenated name
204
-     *
205
-     * @return static|null Concatenated name
206
-     */
207
-    public static function concat($name1, $name2, array $attributes = []) {
208
-        if (null === $name1 && null === $name2) {
209
-            return null;
210
-        } elseif (null === $name1) {
211
-            return new static(self::prepareName($name2), $attributes);
212
-        } elseif (null === $name2) {
213
-            return new static(self::prepareName($name1), $attributes);
214
-        } else {
215
-            return new static(
216
-                array_merge(self::prepareName($name1), self::prepareName($name2)), $attributes
217
-            );
218
-        }
219
-    }
220
-
221
-    /**
222
-     * Prepares a (string, array or Name node) name for use in name changing methods by converting
223
-     * it to an array.
224
-     *
225
-     * @param string|string[]|self $name Name to prepare
226
-     *
227
-     * @return string[] Prepared name
228
-     */
229
-    private static function prepareName($name) : array {
230
-        if (\is_string($name)) {
231
-            if ('' === $name) {
232
-                throw new \InvalidArgumentException('Name cannot be empty');
233
-            }
234
-
235
-            return explode('\\', $name);
236
-        } elseif (\is_array($name)) {
237
-            if (empty($name)) {
238
-                throw new \InvalidArgumentException('Name cannot be empty');
239
-            }
240
-
241
-            return $name;
242
-        } elseif ($name instanceof self) {
243
-            return $name->parts;
244
-        }
245
-
246
-        throw new \InvalidArgumentException(
247
-            'Expected string, array of parts or Name instance'
248
-        );
249
-    }
250
-
251
-    public function getType() : string {
252
-        return 'Name';
253
-    }
9
+	/**
10
+	 * @var string[] Parts of the name
11
+	 * @deprecated Use getParts() instead
12
+	 */
13
+	public $parts;
14
+
15
+	private static $specialClassNames = [
16
+		'self'   => true,
17
+		'parent' => true,
18
+		'static' => true,
19
+	];
20
+
21
+	/**
22
+	 * Constructs a name node.
23
+	 *
24
+	 * @param string|string[]|self $name       Name as string, part array or Name instance (copy ctor)
25
+	 * @param array                $attributes Additional attributes
26
+	 */
27
+	public function __construct($name, array $attributes = []) {
28
+		$this->attributes = $attributes;
29
+		$this->parts = self::prepareName($name);
30
+	}
31
+
32
+	public function getSubNodeNames() : array {
33
+		return ['parts'];
34
+	}
35
+
36
+	/**
37
+	 * Get parts of name (split by the namespace separator).
38
+	 *
39
+	 * @return string[] Parts of name
40
+	 */
41
+	public function getParts(): array {
42
+		return $this->parts;
43
+	}
44
+
45
+	/**
46
+	 * Gets the first part of the name, i.e. everything before the first namespace separator.
47
+	 *
48
+	 * @return string First part of the name
49
+	 */
50
+	public function getFirst() : string {
51
+		return $this->parts[0];
52
+	}
53
+
54
+	/**
55
+	 * Gets the last part of the name, i.e. everything after the last namespace separator.
56
+	 *
57
+	 * @return string Last part of the name
58
+	 */
59
+	public function getLast() : string {
60
+		return $this->parts[count($this->parts) - 1];
61
+	}
62
+
63
+	/**
64
+	 * Checks whether the name is unqualified. (E.g. Name)
65
+	 *
66
+	 * @return bool Whether the name is unqualified
67
+	 */
68
+	public function isUnqualified() : bool {
69
+		return 1 === count($this->parts);
70
+	}
71
+
72
+	/**
73
+	 * Checks whether the name is qualified. (E.g. Name\Name)
74
+	 *
75
+	 * @return bool Whether the name is qualified
76
+	 */
77
+	public function isQualified() : bool {
78
+		return 1 < count($this->parts);
79
+	}
80
+
81
+	/**
82
+	 * Checks whether the name is fully qualified. (E.g. \Name)
83
+	 *
84
+	 * @return bool Whether the name is fully qualified
85
+	 */
86
+	public function isFullyQualified() : bool {
87
+		return false;
88
+	}
89
+
90
+	/**
91
+	 * Checks whether the name is explicitly relative to the current namespace. (E.g. namespace\Name)
92
+	 *
93
+	 * @return bool Whether the name is relative
94
+	 */
95
+	public function isRelative() : bool {
96
+		return false;
97
+	}
98
+
99
+	/**
100
+	 * Returns a string representation of the name itself, without taking the name type into
101
+	 * account (e.g., not including a leading backslash for fully qualified names).
102
+	 *
103
+	 * @return string String representation
104
+	 */
105
+	public function toString() : string {
106
+		return implode('\\', $this->parts);
107
+	}
108
+
109
+	/**
110
+	 * Returns a string representation of the name as it would occur in code (e.g., including
111
+	 * leading backslash for fully qualified names.
112
+	 *
113
+	 * @return string String representation
114
+	 */
115
+	public function toCodeString() : string {
116
+		return $this->toString();
117
+	}
118
+
119
+	/**
120
+	 * Returns lowercased string representation of the name, without taking the name type into
121
+	 * account (e.g., no leading backslash for fully qualified names).
122
+	 *
123
+	 * @return string Lowercased string representation
124
+	 */
125
+	public function toLowerString() : string {
126
+		return strtolower(implode('\\', $this->parts));
127
+	}
128
+
129
+	/**
130
+	 * Checks whether the identifier is a special class name (self, parent or static).
131
+	 *
132
+	 * @return bool Whether identifier is a special class name
133
+	 */
134
+	public function isSpecialClassName() : bool {
135
+		return count($this->parts) === 1
136
+			&& isset(self::$specialClassNames[strtolower($this->parts[0])]);
137
+	}
138
+
139
+	/**
140
+	 * Returns a string representation of the name by imploding the namespace parts with the
141
+	 * namespace separator.
142
+	 *
143
+	 * @return string String representation
144
+	 */
145
+	public function __toString() : string {
146
+		return implode('\\', $this->parts);
147
+	}
148
+
149
+	/**
150
+	 * Gets a slice of a name (similar to array_slice).
151
+	 *
152
+	 * This method returns a new instance of the same type as the original and with the same
153
+	 * attributes.
154
+	 *
155
+	 * If the slice is empty, null is returned. The null value will be correctly handled in
156
+	 * concatenations using concat().
157
+	 *
158
+	 * Offset and length have the same meaning as in array_slice().
159
+	 *
160
+	 * @param int      $offset Offset to start the slice at (may be negative)
161
+	 * @param int|null $length Length of the slice (may be negative)
162
+	 *
163
+	 * @return static|null Sliced name
164
+	 */
165
+	public function slice(int $offset, ?int $length = null) {
166
+		$numParts = count($this->parts);
167
+
168
+		$realOffset = $offset < 0 ? $offset + $numParts : $offset;
169
+		if ($realOffset < 0 || $realOffset > $numParts) {
170
+			throw new \OutOfBoundsException(sprintf('Offset %d is out of bounds', $offset));
171
+		}
172
+
173
+		if (null === $length) {
174
+			$realLength = $numParts - $realOffset;
175
+		} else {
176
+			$realLength = $length < 0 ? $length + $numParts - $realOffset : $length;
177
+			if ($realLength < 0 || $realLength > $numParts - $realOffset) {
178
+				throw new \OutOfBoundsException(sprintf('Length %d is out of bounds', $length));
179
+			}
180
+		}
181
+
182
+		if ($realLength === 0) {
183
+			// Empty slice is represented as null
184
+			return null;
185
+		}
186
+
187
+		return new static(array_slice($this->parts, $realOffset, $realLength), $this->attributes);
188
+	}
189
+
190
+	/**
191
+	 * Concatenate two names, yielding a new Name instance.
192
+	 *
193
+	 * The type of the generated instance depends on which class this method is called on, for
194
+	 * example Name\FullyQualified::concat() will yield a Name\FullyQualified instance.
195
+	 *
196
+	 * If one of the arguments is null, a new instance of the other name will be returned. If both
197
+	 * arguments are null, null will be returned. As such, writing
198
+	 *     Name::concat($namespace, $shortName)
199
+	 * where $namespace is a Name node or null will work as expected.
200
+	 *
201
+	 * @param string|string[]|self|null $name1      The first name
202
+	 * @param string|string[]|self|null $name2      The second name
203
+	 * @param array                     $attributes Attributes to assign to concatenated name
204
+	 *
205
+	 * @return static|null Concatenated name
206
+	 */
207
+	public static function concat($name1, $name2, array $attributes = []) {
208
+		if (null === $name1 && null === $name2) {
209
+			return null;
210
+		} elseif (null === $name1) {
211
+			return new static(self::prepareName($name2), $attributes);
212
+		} elseif (null === $name2) {
213
+			return new static(self::prepareName($name1), $attributes);
214
+		} else {
215
+			return new static(
216
+				array_merge(self::prepareName($name1), self::prepareName($name2)), $attributes
217
+			);
218
+		}
219
+	}
220
+
221
+	/**
222
+	 * Prepares a (string, array or Name node) name for use in name changing methods by converting
223
+	 * it to an array.
224
+	 *
225
+	 * @param string|string[]|self $name Name to prepare
226
+	 *
227
+	 * @return string[] Prepared name
228
+	 */
229
+	private static function prepareName($name) : array {
230
+		if (\is_string($name)) {
231
+			if ('' === $name) {
232
+				throw new \InvalidArgumentException('Name cannot be empty');
233
+			}
234
+
235
+			return explode('\\', $name);
236
+		} elseif (\is_array($name)) {
237
+			if (empty($name)) {
238
+				throw new \InvalidArgumentException('Name cannot be empty');
239
+			}
240
+
241
+			return $name;
242
+		} elseif ($name instanceof self) {
243
+			return $name->parts;
244
+		}
245
+
246
+		throw new \InvalidArgumentException(
247
+			'Expected string, array of parts or Name instance'
248
+		);
249
+	}
250
+
251
+	public function getType() : string {
252
+		return 'Name';
253
+	}
254 254
 }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -4,8 +4,7 @@
 block discarded – undo
4 4
 
5 5
 use PhpParser\NodeAbstract;
6 6
 
7
-class Name extends NodeAbstract
8
-{
7
+class Name extends NodeAbstract {
9 8
     /**
10 9
      * @var string[] Parts of the name
11 10
      * @deprecated Use getParts() instead
Please login to merge, or discard this patch.