Skip to content

Commit f2fede5

Browse files
committedSep 10, 2023
Deduplicate ParentNode and ChildNode interface implementations using @implementation-alias
The entry points are duplicated: they add bloat and make it easier to forget to change something. Make maintenance easier by using @implementation-alias. Also, this has the nice side-effect of slightly reducing the amount of code and binary size. Closes GH-12158.
1 parent 6993749 commit f2fede5

File tree

5 files changed

+50
-188
lines changed

5 files changed

+50
-188
lines changed
 

‎ext/dom/characterdata.c

-59
Original file line numberDiff line numberDiff line change
@@ -325,63 +325,4 @@ PHP_METHOD(DOMCharacterData, replaceData)
325325
}
326326
/* }}} end dom_characterdata_replace_data */
327327

328-
PHP_METHOD(DOMCharacterData, remove)
329-
{
330-
dom_object *intern;
331-
332-
if (zend_parse_parameters_none() == FAILURE) {
333-
RETURN_THROWS();
334-
}
335-
336-
DOM_GET_THIS_INTERN(intern);
337-
338-
dom_child_node_remove(intern);
339-
RETURN_NULL();
340-
}
341-
342-
PHP_METHOD(DOMCharacterData, after)
343-
{
344-
uint32_t argc = 0;
345-
zval *args;
346-
dom_object *intern;
347-
348-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "*", &args, &argc) == FAILURE) {
349-
RETURN_THROWS();
350-
}
351-
352-
DOM_GET_THIS_INTERN(intern);
353-
354-
dom_parent_node_after(intern, args, argc);
355-
}
356-
357-
PHP_METHOD(DOMCharacterData, before)
358-
{
359-
uint32_t argc = 0;
360-
zval *args;
361-
dom_object *intern;
362-
363-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "*", &args, &argc) == FAILURE) {
364-
RETURN_THROWS();
365-
}
366-
367-
DOM_GET_THIS_INTERN(intern);
368-
369-
dom_parent_node_before(intern, args, argc);
370-
}
371-
372-
PHP_METHOD(DOMCharacterData, replaceWith)
373-
{
374-
uint32_t argc = 0;
375-
zval *args;
376-
dom_object *intern;
377-
378-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "*", &args, &argc) == FAILURE) {
379-
RETURN_THROWS();
380-
}
381-
382-
DOM_GET_THIS_INTERN(intern);
383-
384-
dom_child_replace_with(intern, args, argc);
385-
}
386-
387328
#endif

‎ext/dom/document.c

-38
Original file line numberDiff line numberDiff line change
@@ -2082,44 +2082,6 @@ PHP_METHOD(DOMDocument, registerNodeClass)
20822082
}
20832083
/* }}} */
20842084

2085-
/* {{{ URL: https://dom.spec.whatwg.org/#dom-parentnode-append
2086-
Since: DOM Living Standard (DOM4)
2087-
*/
2088-
PHP_METHOD(DOMDocument, append)
2089-
{
2090-
uint32_t argc = 0;
2091-
zval *args;
2092-
dom_object *intern;
2093-
2094-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "*", &args, &argc) == FAILURE) {
2095-
RETURN_THROWS();
2096-
}
2097-
2098-
DOM_GET_THIS_INTERN(intern);
2099-
2100-
dom_parent_node_append(intern, args, argc);
2101-
}
2102-
/* }}} */
2103-
2104-
/* {{{ URL: https://dom.spec.whatwg.org/#dom-parentnode-prepend
2105-
Since: DOM Living Standard (DOM4)
2106-
*/
2107-
PHP_METHOD(DOMDocument, prepend)
2108-
{
2109-
uint32_t argc = 0;
2110-
zval *args;
2111-
dom_object *intern;
2112-
2113-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "*", &args, &argc) == FAILURE) {
2114-
RETURN_THROWS();
2115-
}
2116-
2117-
DOM_GET_THIS_INTERN(intern);
2118-
2119-
dom_parent_node_prepend(intern, args, argc);
2120-
}
2121-
/* }}} */
2122-
21232085
/* {{{ URL: https://dom.spec.whatwg.org/#dom-parentnode-replacechildren
21242086
Since:
21252087
*/

‎ext/dom/documentfragment.c

-57
Original file line numberDiff line numberDiff line change
@@ -93,61 +93,4 @@ PHP_METHOD(DOMDocumentFragment, appendXML) {
9393
}
9494
/* }}} */
9595

96-
/* {{{ URL: https://dom.spec.whatwg.org/#dom-parentnode-append
97-
Since: DOM Living Standard (DOM4)
98-
*/
99-
PHP_METHOD(DOMDocumentFragment, append)
100-
{
101-
uint32_t argc = 0;
102-
zval *args;
103-
dom_object *intern;
104-
105-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "*", &args, &argc) == FAILURE) {
106-
RETURN_THROWS();
107-
}
108-
109-
DOM_GET_THIS_INTERN(intern);
110-
111-
dom_parent_node_append(intern, args, argc);
112-
}
113-
/* }}} */
114-
115-
/* {{{ URL: https://dom.spec.whatwg.org/#dom-parentnode-prepend
116-
Since: DOM Living Standard (DOM4)
117-
*/
118-
PHP_METHOD(DOMDocumentFragment, prepend)
119-
{
120-
uint32_t argc = 0;
121-
zval *args;
122-
dom_object *intern;
123-
124-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "*", &args, &argc) == FAILURE) {
125-
RETURN_THROWS();
126-
}
127-
128-
DOM_GET_THIS_INTERN(intern);
129-
130-
dom_parent_node_prepend(intern, args, argc);
131-
}
132-
/* }}} */
133-
134-
/* {{{ URL: https://dom.spec.whatwg.org/#dom-parentnode-replacechildren
135-
Since:
136-
*/
137-
PHP_METHOD(DOMDocumentFragment, replaceChildren)
138-
{
139-
uint32_t argc = 0;
140-
zval *args;
141-
dom_object *intern;
142-
143-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "*", &args, &argc) == FAILURE) {
144-
RETURN_THROWS();
145-
}
146-
147-
DOM_GET_THIS_INTERN(intern);
148-
149-
dom_parent_node_replace_children(intern, args, argc);
150-
}
151-
/* }}} */
152-
15396
#endif

‎ext/dom/php_dom.stub.php

+33-8
Original file line numberDiff line numberDiff line change
@@ -480,13 +480,22 @@ public function __construct() {}
480480
/** @tentative-return-type */
481481
public function appendXML(string $data): bool {}
482482

483-
/** @param DOMNode|string $nodes */
483+
/**
484+
* @param DOMNode|string $nodes
485+
* @implementation-alias DOMElement::append
486+
*/
484487
public function append(...$nodes): void {}
485488

486-
/** @param DOMNode|string $nodes */
489+
/**
490+
* @param DOMNode|string $nodes
491+
* @implementation-alias DOMElement::prepend
492+
*/
487493
public function prepend(...$nodes): void {}
488494

489-
/** @param DOMNode|string $nodes */
495+
/**
496+
* @param DOMNode|string $nodes
497+
* @implementation-alias DOMDocument::replaceChildren
498+
*/
490499
public function replaceChildren(...$nodes): void {}
491500
}
492501

@@ -532,15 +541,25 @@ public function deleteData(int $offset, int $count): bool {}
532541
/** @tentative-return-type */
533542
public function replaceData(int $offset, int $count, string $data): bool {}
534543

535-
/** @param DOMNode|string $nodes */
544+
/**
545+
* @param DOMNode|string $nodes
546+
* @implementation-alias DOMElement::replaceWith
547+
*/
536548
public function replaceWith(...$nodes): void {}
537549

550+
/** @implementation-alias DOMElement::remove */
538551
public function remove(): void {}
539552

540-
/** @param DOMNode|string $nodes */
553+
/**
554+
* @param DOMNode|string $nodes
555+
* @implementation-alias DOMElement::before
556+
*/
541557
public function before(... $nodes): void {}
542558

543-
/** @param DOMNode|string $nodes */
559+
/**
560+
* @param DOMNode|string $nodes
561+
* @implementation-alias DOMElement::after
562+
*/
544563
public function after(...$nodes): void {}
545564
}
546565

@@ -838,10 +857,16 @@ public function xinclude(int $options = 0): int|false {}
838857
/** @tentative-return-type */
839858
public function adoptNode(DOMNode $node): DOMNode|false {}
840859

841-
/** @param DOMNode|string $nodes */
860+
/**
861+
* @param DOMNode|string $nodes
862+
* @implementation-alias DOMElement::append
863+
*/
842864
public function append(...$nodes): void {}
843865

844-
/** @param DOMNode|string $nodes */
866+
/**
867+
* @param DOMNode|string $nodes
868+
* @implementation-alias DOMElement::prepend
869+
*/
845870
public function prepend(...$nodes): void {}
846871

847872
/** @param DOMNode|string $nodes */

‎ext/dom/php_dom_arginfo.h

+17-26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.