@@ -1380,10 +1380,15 @@ public function upgradeRelTagToCategory(DOMElement $el) {
13801380 /**
13811381 * Kicks off the parsing routine
13821382 * @param bool $convertClassic whether to do backcompat parsing on microformats1. Defaults to true.
1383- * @param DOMElement $context optionally specify an element from which to parse microformats
1383+ * @param ? DOMElement $context optionally specify an element from which to parse microformats
13841384 * @return array An array containing all the microformats found in the current document
13851385 */
1386- public function parse ($ convertClassic = true , DOMElement $ context = null ) {
1386+ public function parse ($ convertClassic = true ) {
1387+ $ context = func_num_args () > 1 ? func_get_arg (1 ) : null ;
1388+ if ($ context !== null && !$ context instanceof DOMElement) {
1389+ throw new \InvalidArgumentException (__METHOD__ . ': Argument #1 ($context) must be of type ?DOMElement, ' . gettype ($ context ) . ' given ' );
1390+ }
1391+
13871392 $ this ->convertClassic = $ convertClassic ;
13881393 $ mfs = $ this ->parse_recursive ($ context );
13891394
@@ -1407,11 +1412,21 @@ public function parse($convertClassic = true, DOMElement $context = null) {
14071412 /**
14081413 * Parse microformats recursively
14091414 * Keeps track of whether inside a backcompat root or not
1410- * @param DOMElement $context: node to start with
1415+ * @param ? DOMElement $context: node to start with
14111416 * @param int $depth: recursion depth
14121417 * @return array
14131418 */
1414- public function parse_recursive (DOMElement $ context = null , $ depth = 0 ) {
1419+ public function parse_recursive () {
1420+ $ numArgs = func_num_args ();
1421+ $ context = $ numArgs > 0 ? func_get_arg (0 ) : null ;
1422+ $ depth = $ numArgs > 1 ? func_get_arg (1 ) : 0 ;
1423+ if ($ context !== null && !$ context instanceof DOMElement) {
1424+ throw new \InvalidArgumentException (__METHOD__ . ': Argument #0 ($context) must be of type ?DOMElement, ' . gettype ($ context ) . ' given ' );
1425+ }
1426+ if ($ depth !== null && !is_int ($ depth )) {
1427+ throw new \InvalidArgumentException (__METHOD__ . ': Argument #1 ($depth) must be of type int, ' . gettype ($ depth ) . ' given ' );
1428+ }
1429+
14151430 $ mfs = array ();
14161431 $ mfElements = $ this ->getRootMF ($ context );
14171432
@@ -1513,10 +1528,15 @@ public function parseFromId($id, $convertClassic=true) {
15131528
15141529 /**
15151530 * Get the root microformat elements
1516- * @param DOMElement $context
1531+ * @param ? DOMElement $context
15171532 * @return DOMNodeList
15181533 */
1519- public function getRootMF (DOMElement $ context = null ) {
1534+ public function getRootMF () {
1535+ $ context = func_num_args () > 0 ? func_get_arg (0 ) : null ;
1536+ if ($ context !== null && !$ context instanceof DOMElement) {
1537+ throw new \InvalidArgumentException (__METHOD__ . ': Argument #0 ($context) must be of type ?DOMElement, ' . gettype ($ context ) . ' given ' );
1538+ }
1539+
15201540 // start with mf2 root class name xpath
15211541 $ xpaths = array (
15221542 '(php:function(" \\Mf2 \\classHasMf2RootClassname", normalize-space(@class))) '
0 commit comments