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