PluginProbe
WPIDE – File Manager & Code Editor / 3.5.9
WPIDE – File Manager & Code Editor v3.5.9
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 3.3 All 55 releases
wpide / vendor / nikic / php-parser / lib / PhpParser / Builder / TraitUse.php

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

65 lines 1.5 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\Builder;
6 use PhpParser\BuilderHelpers;
7 use PhpParser\Node;
8 use PhpParser\Node\Stmt;
9
10 class TraitUse implements Builder
11 {
12 protected $traits = [];
13 protected $adaptations = [];
14
15 /**
16 * Creates a trait use builder.
17 *
18 * @param Node\Name|string ...$traits Names of used traits
19 */
20 public function __construct(...$traits) {
21 foreach ($traits as $trait) {
22 $this->and($trait);
23 }
24 }
25
26 /**
27 * Adds used trait.
28 *
29 * @param Node\Name|string $trait Trait name
30 *
31 * @return $this The builder instance (for fluid interface)
32 */
33 public function and($trait) {
34 $this->traits[] = BuilderHelpers::normalizeName($trait);
35 return $this;
36 }
37
38 /**
39 * Adds trait adaptation.
40 *
41 * @param Stmt\TraitUseAdaptation|Builder\TraitUseAdaptation $adaptation Trait adaptation
42 *
43 * @return $this The builder instance (for fluid interface)
44 */
45 public function with($adaptation) {
46 $adaptation = BuilderHelpers::normalizeNode($adaptation);
47
48 if (!$adaptation instanceof Stmt\TraitUseAdaptation) {
49 throw new \LogicException('Adaptation must have type TraitUseAdaptation');
50 }
51
52 $this->adaptations[] = $adaptation;
53 return $this;
54 }
55
56 /**
57 * Returns the built node.
58 *
59 * @return Node The built node
60 */
61 public function getNode() : Node {
62 return new Stmt\TraitUse($this->traits, $this->adaptations);
63 }
64 }
65