PluginProbe
WPIDE – File Manager & Code Editor / 3.5.10
WPIDE – File Manager & Code Editor v3.5.10
3.5.10 3.5.9 3.5.8 3.5.7 2.0.14 2.0.15 2.0.16 2.0.2 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1 2.2 2.3 2.3.1 2.3.2 2.4.0 2.5 2.6 3.0 3.1 3.2 All 56 releases
wpide / vendor / nikic / php-parser / lib / PhpParser / Builder / Trait_.php

Trait_.php in WPIDE – File Manager & Code Editor 3.5.10, at vendor/nikic/php-parser/lib/PhpParser/Builder/Trait_.php

79 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php declare(strict_types=1);
2
3 namespace PhpParser\Builder;
4
5 use PhpParser;
6 use PhpParser\BuilderHelpers;
7 use PhpParser\Node;
8 use PhpParser\Node\Stmt;
9
10 class Trait_ extends Declaration
11 {
12 protected $name;
13 protected $uses = [];
14 protected $properties = [];
15 protected $methods = [];
16
17 /** @var Node\AttributeGroup[] */
18 protected $attributeGroups = [];
19
20 /**
21 * Creates an interface builder.
22 *
23 * @param string $name Name of the interface
24 */
25 public function __construct(string $name) {
26 $this->name = $name;
27 }
28
29 /**
30 * Adds a statement.
31 *
32 * @param Stmt|PhpParser\Builder $stmt The statement to add
33 *
34 * @return $this The builder instance (for fluid interface)
35 */
36 public function addStmt($stmt) {
37 $stmt = BuilderHelpers::normalizeNode($stmt);
38
39 if ($stmt instanceof Stmt\Property) {
40 $this->properties[] = $stmt;
41 } elseif ($stmt instanceof Stmt\ClassMethod) {
42 $this->methods[] = $stmt;
43 } elseif ($stmt instanceof Stmt\TraitUse) {
44 $this->uses[] = $stmt;
45 } else {
46 throw new \LogicException(sprintf('Unexpected node of type "%s"', $stmt->getType()));
47 }
48
49 return $this;
50 }
51
52 /**
53 * Adds an attribute group.
54 *
55 * @param Node\Attribute|Node\AttributeGroup $attribute
56 *
57 * @return $this The builder instance (for fluid interface)
58 */
59 public function addAttribute($attribute) {
60 $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute);
61
62 return $this;
63 }
64
65 /**
66 * Returns the built trait node.
67 *
68 * @return Stmt\Trait_ The built interface node
69 */
70 public function getNode() : PhpParser\Node {
71 return new Stmt\Trait_(
72 $this->name, [
73 'stmts' => array_merge($this->uses, $this->properties, $this->methods),
74 'attrGroups' => $this->attributeGroups,
75 ], $this->attributes
76 );
77 }
78 }
79