Mercurial > hg > cmmr2012-drupal-site
comparison vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Class_.php @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c75dbcec494b |
---|---|
1 <?php declare(strict_types=1); | |
2 | |
3 namespace PhpParser\Node\Stmt; | |
4 | |
5 use PhpParser\Error; | |
6 use PhpParser\Node; | |
7 | |
8 class Class_ extends ClassLike | |
9 { | |
10 const MODIFIER_PUBLIC = 1; | |
11 const MODIFIER_PROTECTED = 2; | |
12 const MODIFIER_PRIVATE = 4; | |
13 const MODIFIER_STATIC = 8; | |
14 const MODIFIER_ABSTRACT = 16; | |
15 const MODIFIER_FINAL = 32; | |
16 | |
17 const VISIBILITY_MODIFIER_MASK = 7; // 1 | 2 | 4 | |
18 | |
19 /** @var int Type */ | |
20 public $flags; | |
21 /** @var null|Node\Name Name of extended class */ | |
22 public $extends; | |
23 /** @var Node\Name[] Names of implemented interfaces */ | |
24 public $implements; | |
25 | |
26 /** | |
27 * Constructs a class node. | |
28 * | |
29 * @param string|Node\Identifier|null $name Name | |
30 * @param array $subNodes Array of the following optional subnodes: | |
31 * 'flags' => 0 : Flags | |
32 * 'extends' => null : Name of extended class | |
33 * 'implements' => array(): Names of implemented interfaces | |
34 * 'stmts' => array(): Statements | |
35 * @param array $attributes Additional attributes | |
36 */ | |
37 public function __construct($name, array $subNodes = [], array $attributes = []) { | |
38 parent::__construct($attributes); | |
39 $this->flags = $subNodes['flags'] ?? $subNodes['type'] ?? 0; | |
40 $this->name = \is_string($name) ? new Node\Identifier($name) : $name; | |
41 $this->extends = $subNodes['extends'] ?? null; | |
42 $this->implements = $subNodes['implements'] ?? []; | |
43 $this->stmts = $subNodes['stmts'] ?? []; | |
44 } | |
45 | |
46 public function getSubNodeNames() : array { | |
47 return ['flags', 'name', 'extends', 'implements', 'stmts']; | |
48 } | |
49 | |
50 /** | |
51 * Whether the class is explicitly abstract. | |
52 * | |
53 * @return bool | |
54 */ | |
55 public function isAbstract() : bool { | |
56 return (bool) ($this->flags & self::MODIFIER_ABSTRACT); | |
57 } | |
58 | |
59 /** | |
60 * Whether the class is final. | |
61 * | |
62 * @return bool | |
63 */ | |
64 public function isFinal() : bool { | |
65 return (bool) ($this->flags & self::MODIFIER_FINAL); | |
66 } | |
67 | |
68 /** | |
69 * Whether the class is anonymous. | |
70 * | |
71 * @return bool | |
72 */ | |
73 public function isAnonymous() : bool { | |
74 return null === $this->name; | |
75 } | |
76 | |
77 /** | |
78 * @internal | |
79 */ | |
80 public static function verifyModifier($a, $b) { | |
81 if ($a & self::VISIBILITY_MODIFIER_MASK && $b & self::VISIBILITY_MODIFIER_MASK) { | |
82 throw new Error('Multiple access type modifiers are not allowed'); | |
83 } | |
84 | |
85 if ($a & self::MODIFIER_ABSTRACT && $b & self::MODIFIER_ABSTRACT) { | |
86 throw new Error('Multiple abstract modifiers are not allowed'); | |
87 } | |
88 | |
89 if ($a & self::MODIFIER_STATIC && $b & self::MODIFIER_STATIC) { | |
90 throw new Error('Multiple static modifiers are not allowed'); | |
91 } | |
92 | |
93 if ($a & self::MODIFIER_FINAL && $b & self::MODIFIER_FINAL) { | |
94 throw new Error('Multiple final modifiers are not allowed'); | |
95 } | |
96 | |
97 if ($a & 48 && $b & 48) { | |
98 throw new Error('Cannot use the final modifier on an abstract class member'); | |
99 } | |
100 } | |
101 | |
102 public function getType() : string { | |
103 return 'Stmt_Class'; | |
104 } | |
105 } |