Debian Codegraph @

vendor/mck89/peast/lib/Peast/Selector/Node/Part/PseudoSelector.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\Selector\Matches;
13 use Peast\Selector\Node\Selector;
14 use Peast\Syntax\Node\Node;
15
16 /**
17 * Selector part selector pseudo class
18 *
19 * @author Marco Marchiò <[email protected]>
20 */
21 class PseudoSelector extends Pseudo
22 {
23 /**
24 * Priority
25 *
26 * @var int
27 */
28 protected $priority = 1;
29
30 /**
31 * Selector
32 *
33 * @var Selector
34 */
35 protected $selector;
36
37 /**
38 * Sets the selector
39 *
40 * @param Selector $selector Selector
41 *
42 * @return $this
43 */
44 public function setSelector(Selector $selector)
45 {
46 $this->selector = $selector;
47 return $this;
48 }
49
50 /**
51 * Returns true if the selector part matches the given node,
52 * false otherwise
53 *
54 * @param Node $node Node
55 * @param Node $parent Parent node
56 *
57 * @return bool
58 */
59 public function check(Node $node, $parent = null)
60 {
61 $match = new Matches();
62 $match->addMatch($node, $parent);
63 $res = $this->selector->exec($match)->count();
64 return $this->name === "not" ? $res === 0 : $res !== 0;
65 }
66 }