Debian Codegraph @

vendor/mck89/peast/lib/Peast/Selector/Node/Part/PseudoSimple.php

raw
1 <?php
2 /**
3 * This file is part of the Peast package
4 *
5 * (c) Marco Marchiò <[email protected]>
6 *
7 * For the full copyright and license information refer to the LICENSE file
8 * distributed with this source code
9 */
10 namespace Peast\Selector\Node\Part;
11
12 use Peast\Syntax\Node\Node;
13 use Peast\Syntax\Node\Pattern;
14 use Peast\Syntax\Node\Statement;
15 use Peast\Syntax\Node\Expression;
16 use Peast\Syntax\Node\Declaration;
17 use Peast\Syntax\Utils;
18
19 /**
20 * Selector part simple pseudo class
21 *
22 * @author Marco Marchiò <[email protected]>
23 */
24 class PseudoSimple extends Pseudo
25 {
26 /**
27 * Priority
28 *
29 * @var int
30 */
31 protected $priority = 3;
32
33 /**
34 * Returns true if the selector part matches the given node,
35 * false otherwise
36 *
37 * @param Node $node Node
38 * @param Node $parent Parent node
39 *
40 * @return bool
41 */
42 public function check(Node $node, $parent = null)
43 {
44 switch ($this->name) {
45 case "pattern":
46 return $node instanceof Pattern;
47 case "statement":
48 return $node instanceof Statement;
49 case "expression":
50 return $node instanceof Expression;
51 case "declaration":
52 return $node instanceof Declaration;
53 case "last-child":
54 case "first-child":
55 $first = $this->name === "first-child";
56 $props = Utils::getExpandedNodeProperties($parent);
57 return count($props) > 0 && (
58 $first ? $props[0] === $node : array_pop($props) === $node
59 );
60 }
61 }
62 }