@@ -1380,10 +1380,15 @@ public function upgradeRelTagToCategory(DOMElement $el) {
1380
1380
/**
1381
1381
* Kicks off the parsing routine
1382
1382
* @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
1384
1384
* @return array An array containing all the microformats found in the current document
1385
1385
*/
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
+
1387
1392
$ this ->convertClassic = $ convertClassic ;
1388
1393
$ mfs = $ this ->parse_recursive ($ context );
1389
1394
@@ -1407,11 +1412,21 @@ public function parse($convertClassic = true, DOMElement $context = null) {
1407
1412
/**
1408
1413
* Parse microformats recursively
1409
1414
* 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
1411
1416
* @param int $depth: recursion depth
1412
1417
* @return array
1413
1418
*/
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
+
1415
1430
$ mfs = array ();
1416
1431
$ mfElements = $ this ->getRootMF ($ context );
1417
1432
@@ -1513,10 +1528,15 @@ public function parseFromId($id, $convertClassic=true) {
1513
1528
1514
1529
/**
1515
1530
* Get the root microformat elements
1516
- * @param DOMElement $context
1531
+ * @param ? DOMElement $context
1517
1532
* @return DOMNodeList
1518
1533
*/
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
+
1520
1540
// start with mf2 root class name xpath
1521
1541
$ xpaths = array (
1522
1542
'(php:function(" \\Mf2 \\classHasMf2RootClassname", normalize-space(@class))) '
0 commit comments