11<?php
2- declare (strict_types = 1 );
2+
3+ declare (strict_types=1 );
4+
35namespace MsgMe \tools ;
46
57function isItSafeToOnlyUseFirstFormInputMatch (\DOMDocument $ domd , \DOMNode $ form = NULL ): bool
@@ -18,7 +20,8 @@ function isItSafeToOnlyUseFirstFormInputMatch(\DOMDocument $domd, \DOMNode $form
1820 return true ;
1921}
2022
21- function return_var_dump (/*...*/ ){
23+ function return_var_dump (/*...*/ )
24+ {
2225 $ args = func_get_args ();
2326 ob_start ();
2427 call_user_func_array ('var_dump ' , $ args );
@@ -28,7 +31,7 @@ function return_var_dump(/*...*/){
2831function getDOMDocumentFormInputs (\DOMDocument $ domd , bool $ getOnlyFirstMatches = false , bool $ getElements = true ): array
2932{
3033 // :DOMNodeList?
31- if (! $ getOnlyFirstMatches && ! $ getElements ) {
34+ if (!$ getOnlyFirstMatches && !$ getElements ) {
3235 throw new \InvalidArgumentException ('!$getElements is currently only implemented for $getOnlyFirstMatches (cus im lazy and nobody has written the code yet) ' );
3336 }
3437 $ forms = $ domd ->getElementsByTagName ('form ' );
@@ -71,11 +74,11 @@ function getDOMDocumentFormInputs(\DOMDocument $domd, bool $getOnlyFirstMatches
7174 // echo "inputs with no name are ignored when submitted by mainstream browsers (presumably because of specs)... follow suite?", PHP_EOL;
7275 continue ;
7376 }
74- if (! $ isDescendantOf ($ input , $ form ) && $ form ->getAttribute ("id " ) !== '' && $ input ->getAttribute ("form " ) !== $ form ->getAttribute ("id " )) {
77+ if (!$ isDescendantOf ($ input , $ form ) && $ form ->getAttribute ("id " ) !== '' && $ input ->getAttribute ("form " ) !== $ form ->getAttribute ("id " )) {
7578 // echo "this input does not belong to this form.", PHP_EOL;
7679 continue ;
7780 }
78- if (! array_key_exists ($ name , $ ret )) {
81+ if (!array_key_exists ($ name , $ ret )) {
7982 $ ret [$ name ] = array (
8083 $ input
8184 );
@@ -94,12 +97,12 @@ function getDOMDocumentFormInputs(\DOMDocument $domd, bool $getOnlyFirstMatches
9497 $ hasName = false ;
9598 }
9699 }
97- if (! $ hasName ) {
100+ if (!$ hasName ) {
98101 $ parsedForms [] = array (
99102 $ inputs
100103 );
101104 } else {
102- if (! array_key_exists ($ name , $ parsedForms )) {
105+ if (!array_key_exists ($ name , $ parsedForms )) {
103106 $ parsedForms [$ name ] = array (
104107 $ inputs
105108 );
@@ -136,7 +139,7 @@ function getDOMDocumentFormInputs(\DOMDocument $domd, bool $getOnlyFirstMatches
136139function loadHTML_noemptywhitespace (string $ html , int $ extra_flags = 0 , int $ exclude_flags = 0 ): \DOMDocument
137140{
138141 $ flags = LIBXML_HTML_NODEFDTD | LIBXML_NOBLANKS | LIBXML_NONET ;
139- $ flags = ($ flags | $ extra_flags ) & ~ $ exclude_flags ;
142+ $ flags = ($ flags | $ extra_flags ) & ~$ exclude_flags ;
140143
141144 $ domd = new \DOMDocument ();
142145 $ domd ->preserveWhiteSpace = false ;
@@ -145,11 +148,11 @@ function loadHTML_noemptywhitespace(string $html, int $extra_flags = 0, int $exc
145148 if ($ node ->hasChildNodes ()) {
146149 // Warning: it's important to do it backwards; if you do it forwards, the index for DOMNodeList might become invalidated;
147150 // that's why i don't use foreach() - don't change it (unless you know what you're doing, ofc)
148- for ($ i = $ node ->childNodes ->length - 1 ; $ i >= 0 ; -- $ i ) {
151+ for ($ i = $ node ->childNodes ->length - 1 ; $ i >= 0 ; --$ i ) {
149152 $ removeAnnoyingWhitespaceTextNodes ($ node ->childNodes ->item ($ i ));
150153 }
151154 }
152- if ($ node ->nodeType === XML_TEXT_NODE && ! $ node ->hasChildNodes () && ! $ node ->hasAttributes () && ! strlen (trim ($ node ->textContent ))) {
155+ if ($ node ->nodeType === XML_TEXT_NODE && !$ node ->hasChildNodes () && !$ node ->hasAttributes () && !strlen (trim ($ node ->textContent ))) {
153156 // echo "Removing annoying POS";
154157 // var_dump($node);
155158 $ node ->parentNode ->removeChild ($ node );
@@ -161,7 +164,7 @@ function loadHTML_noemptywhitespace(string $html, int $extra_flags = 0, int $exc
161164function loadHTML (string $ html , int $ extra_flags = 0 , int $ exclude_flags = 0 ): \DOMDocument
162165{
163166 $ flags = LIBXML_HTML_NODEFDTD | LIBXML_NONET ;
164- $ flags = ($ flags | $ extra_flags ) & ~ $ exclude_flags ;
167+ $ flags = ($ flags | $ extra_flags ) & ~$ exclude_flags ;
165168
166169 $ domd = new \DOMDocument ();
167170 //$domd->preserveWhiteSpace = false;
@@ -176,4 +179,13 @@ function prettify_html(string $html): string
176179 $ domd ->preserveWhiteSpace = false ;
177180 $ domd ->formatOutput = true ;
178181 return $ domd ->saveHTML ();
179- }
182+ }
183+
184+ function dd (...$ args ): void /*: never */
185+ {
186+ $ trace = debug_backtrace (0 , 2 )[1 ];
187+ echo "<pre> \ndd() called from " , $ trace ['file ' ], ": " , $ trace ['line ' ], "\n" ;
188+ var_dump (...$ args );
189+ echo "</pre> \n" ;
190+ die (1 );
191+ }
0 commit comments