comparison vendor/nikic/php-parser/lib/PhpParser/Builder/Interface_.php @ 13:5fb285c0d0e3

Update Drupal core to 8.4.7 via Composer. Security update; I *think* we've been lucky to get away with this so far, as we don't support self-registration which seems to be used by the so-called "drupalgeddon 2" attack that 8.4.5 was vulnerable to.
author Chris Cannam
date Mon, 23 Apr 2018 09:33:26 +0100
parents 4c8ae668cc8c
children
comparison
equal deleted inserted replaced
12:7a779792577d 13:5fb285c0d0e3
1 <?php 1 <?php declare(strict_types=1);
2 2
3 namespace PhpParser\Builder; 3 namespace PhpParser\Builder;
4 4
5 use PhpParser; 5 use PhpParser;
6 use PhpParser\BuilderHelpers;
6 use PhpParser\Node\Name; 7 use PhpParser\Node\Name;
7 use PhpParser\Node\Stmt; 8 use PhpParser\Node\Stmt;
8 9
9 class Interface_ extends Declaration 10 class Interface_ extends Declaration
10 { 11 {
11 protected $name; 12 protected $name;
12 protected $extends = array(); 13 protected $extends = [];
13 protected $constants = array(); 14 protected $constants = [];
14 protected $methods = array(); 15 protected $methods = [];
15 16
16 /** 17 /**
17 * Creates an interface builder. 18 * Creates an interface builder.
18 * 19 *
19 * @param string $name Name of the interface 20 * @param string $name Name of the interface
20 */ 21 */
21 public function __construct($name) { 22 public function __construct(string $name) {
22 $this->name = $name; 23 $this->name = $name;
23 } 24 }
24 25
25 /** 26 /**
26 * Extends one or more interfaces. 27 * Extends one or more interfaces.
27 * 28 *
28 * @param Name|string ...$interfaces Names of interfaces to extend 29 * @param Name|string ...$interfaces Names of interfaces to extend
29 * 30 *
30 * @return $this The builder instance (for fluid interface) 31 * @return $this The builder instance (for fluid interface)
31 */ 32 */
32 public function extend() { 33 public function extend(...$interfaces) {
33 foreach (func_get_args() as $interface) { 34 foreach ($interfaces as $interface) {
34 $this->extends[] = $this->normalizeName($interface); 35 $this->extends[] = BuilderHelpers::normalizeName($interface);
35 } 36 }
36 37
37 return $this; 38 return $this;
38 } 39 }
39 40
43 * @param Stmt|PhpParser\Builder $stmt The statement to add 44 * @param Stmt|PhpParser\Builder $stmt The statement to add
44 * 45 *
45 * @return $this The builder instance (for fluid interface) 46 * @return $this The builder instance (for fluid interface)
46 */ 47 */
47 public function addStmt($stmt) { 48 public function addStmt($stmt) {
48 $stmt = $this->normalizeNode($stmt); 49 $stmt = BuilderHelpers::normalizeNode($stmt);
49 50
50 $type = $stmt->getType(); 51 if ($stmt instanceof Stmt\ClassConst) {
51 switch ($type) { 52 $this->constants[] = $stmt;
52 case 'Stmt_ClassConst': 53 } elseif ($stmt instanceof Stmt\ClassMethod) {
53 $this->constants[] = $stmt; 54 // we erase all statements in the body of an interface method
54 break; 55 $stmt->stmts = null;
55 56 $this->methods[] = $stmt;
56 case 'Stmt_ClassMethod': 57 } else {
57 // we erase all statements in the body of an interface method 58 throw new \LogicException(sprintf('Unexpected node of type "%s"', $stmt->getType()));
58 $stmt->stmts = null;
59 $this->methods[] = $stmt;
60 break;
61
62 default:
63 throw new \LogicException(sprintf('Unexpected node of type "%s"', $type));
64 } 59 }
65 60
66 return $this; 61 return $this;
67 } 62 }
68 63
69 /** 64 /**
70 * Returns the built interface node. 65 * Returns the built interface node.
71 * 66 *
72 * @return Stmt\Interface_ The built interface node 67 * @return Stmt\Interface_ The built interface node
73 */ 68 */
74 public function getNode() { 69 public function getNode() : PhpParser\Node {
75 return new Stmt\Interface_($this->name, array( 70 return new Stmt\Interface_($this->name, [
76 'extends' => $this->extends, 71 'extends' => $this->extends,
77 'stmts' => array_merge($this->constants, $this->methods), 72 'stmts' => array_merge($this->constants, $this->methods),
78 ), $this->attributes); 73 ], $this->attributes);
79 } 74 }
80 } 75 }