Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 31 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
NodeFilter | |
0.00% |
0 / 31 |
|
0.00% |
0 / 4 |
90 | |
0.00% |
0 / 1 |
_getMissingProp | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
12 | |||
_setMissingProp | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
12 | |||
__invoke | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
cast | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | // AUTOMATICALLY GENERATED. DO NOT EDIT. |
4 | // Use `composer build` to regenerate. |
5 | |
6 | namespace Wikimedia\IDLeDOM\Helper; |
7 | |
8 | use Wikimedia\IDLeDOM\Node; |
9 | |
10 | trait NodeFilter { |
11 | |
12 | // Underscore is used to avoid conflicts with DOM-reserved names |
13 | // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
14 | // phpcs:disable MediaWiki.NamingConventions.LowerCamelFunctionsName.FunctionName |
15 | |
16 | /** |
17 | * Handle an attempt to get a non-existing property on this |
18 | * object. The default implementation raises an exception |
19 | * but the implementor can choose a different behavior: |
20 | * return null (like JavaScript), dynamically create the |
21 | * property, etc. |
22 | * @param string $prop the name of the property requested |
23 | * @return mixed |
24 | */ |
25 | protected function _getMissingProp( string $prop ) { |
26 | $trace = debug_backtrace(); |
27 | while ( |
28 | count( $trace ) > 0 && |
29 | $trace[0]['function'] !== "__get" |
30 | ) { |
31 | array_shift( $trace ); |
32 | } |
33 | trigger_error( |
34 | 'Undefined property' . |
35 | ' via ' . ( $trace[0]['function'] ?? '' ) . '(): ' . $prop . |
36 | ' in ' . ( $trace[0]['file'] ?? '' ) . |
37 | ' on line ' . ( $trace[0]['line'] ?? '' ), |
38 | E_USER_NOTICE |
39 | ); |
40 | return null; |
41 | } |
42 | |
43 | /** |
44 | * Handle an attempt to set a non-existing property on this |
45 | * object. The default implementation raises an exception |
46 | * but the implementor can choose a different behavior: |
47 | * ignore the operation (like JavaScript), dynamically create |
48 | * the property, etc. |
49 | * @param string $prop the name of the property requested |
50 | * @param mixed $value the value to set |
51 | */ |
52 | protected function _setMissingProp( string $prop, $value ): void { |
53 | $trace = debug_backtrace(); |
54 | while ( |
55 | count( $trace ) > 0 && |
56 | $trace[0]['function'] !== "__set" |
57 | ) { |
58 | array_shift( $trace ); |
59 | } |
60 | trigger_error( |
61 | 'Undefined property' . |
62 | ' via ' . ( $trace[0]['function'] ?? '' ) . '(): ' . $prop . |
63 | ' in ' . ( $trace[0]['file'] ?? '' ) . |
64 | ' on line ' . ( $trace[0]['line'] ?? '' ), |
65 | E_USER_NOTICE |
66 | ); |
67 | } |
68 | |
69 | // phpcs:enable |
70 | |
71 | /** |
72 | * Make this callback interface callable. |
73 | * @param mixed ...$args |
74 | * @return int |
75 | */ |
76 | public function __invoke( ...$args ) { |
77 | '@phan-var \Wikimedia\IDLeDOM\NodeFilter $this'; |
78 | // @var \Wikimedia\IDLeDOM\NodeFilter $this |
79 | return $this->acceptNode( $args[0] ); |
80 | } |
81 | |
82 | /** |
83 | * Create a NodeFilter from a callable. |
84 | * |
85 | * @param callable|\Wikimedia\IDLeDOM\NodeFilter $f |
86 | * @return \Wikimedia\IDLeDOM\NodeFilter |
87 | */ |
88 | public static function cast( $f ) { |
89 | if ( $f instanceof \Wikimedia\IDLeDOM\NodeFilter ) { |
90 | return $f; |
91 | } |
92 | return new class( $f ) implements \Wikimedia\IDLeDOM\NodeFilter { |
93 | use NodeFilter; |
94 | |
95 | /** @var callable */ |
96 | private $f; |
97 | |
98 | /** |
99 | * @param callable $f |
100 | */ |
101 | public function __construct( $f ) { |
102 | $this->f = $f; |
103 | } |
104 | |
105 | /** |
106 | * @param Node $node |
107 | * @return int |
108 | */ |
109 | public function acceptNode( /* Node */ $node ): int { |
110 | $f = $this->f; |
111 | return $f( $node ); |
112 | } |
113 | }; |
114 | } |
115 | } |