Removed modules/contrib/media module to allow update to the core media module
[yaffs-website] / vendor / nikic / php-parser / lib / PhpParser / Builder / Trait_.php
1 <?php declare(strict_types=1);
2
3 namespace PhpParser\Builder;
4
5 use PhpParser;
6 use PhpParser\BuilderHelpers;
7 use PhpParser\Node\Stmt;
8
9 class Trait_ extends Declaration
10 {
11     protected $name;
12     protected $uses = [];
13     protected $properties = [];
14     protected $methods = [];
15
16     /**
17      * Creates an interface builder.
18      *
19      * @param string $name Name of the interface
20      */
21     public function __construct(string $name) {
22         $this->name = $name;
23     }
24
25     /**
26      * Adds a statement.
27      *
28      * @param Stmt|PhpParser\Builder $stmt The statement to add
29      *
30      * @return $this The builder instance (for fluid interface)
31      */
32     public function addStmt($stmt) {
33         $stmt = BuilderHelpers::normalizeNode($stmt);
34
35         if ($stmt instanceof Stmt\Property) {
36             $this->properties[] = $stmt;
37         } elseif ($stmt instanceof Stmt\ClassMethod) {
38             $this->methods[] = $stmt;
39         } elseif ($stmt instanceof Stmt\TraitUse) {
40             $this->uses[] = $stmt;
41         } else {
42             throw new \LogicException(sprintf('Unexpected node of type "%s"', $stmt->getType()));
43         }
44
45         return $this;
46     }
47
48     /**
49      * Returns the built trait node.
50      *
51      * @return Stmt\Trait_ The built interface node
52      */
53     public function getNode() : PhpParser\Node {
54         return new Stmt\Trait_(
55             $this->name, [
56                 'stmts' => array_merge($this->uses, $this->properties, $this->methods)
57             ], $this->attributes
58         );
59     }
60 }