Code Duplication    Length = 24-24 lines in 2 locations

src/voku/helper/SimpleHtmlDom.php 1 location

@@ 320-343 (lines=24) @@
317
   *
318
   * @return SimpleHtmlDomNode|SimpleHtmlDomNode[]|SimpleHtmlDomNodeBlank
319
   */
320
  public function getElementsByTagName($name, $idx = null)
321
  {
322
    $nodesList = $this->node->getElementsByTagName($name);
323
324
    $elements = new SimpleHtmlDomNode();
325
326
    foreach ($nodesList as $node) {
327
      $elements[] = new self($node);
328
    }
329
330
    if (null === $idx) {
331
      return $elements;
332
    } else {
333
      if ($idx < 0) {
334
        $idx = count($elements) + $idx;
335
      }
336
    }
337
338
    if (isset($elements[$idx])) {
339
      return $elements[$idx];
340
    } else {
341
      return new SimpleHtmlDomNodeBlank();
342
    }
343
  }
344
345
  /**
346
   * Create a new "HtmlDomParser"-object from the current context.

src/voku/helper/HtmlDomParser.php 1 location

@@ 435-458 (lines=24) @@
432
   *
433
   * @return SimpleHtmlDomNode|SimpleHtmlDomNode[]|SimpleHtmlDomNodeBlank
434
   */
435
  public function getElementsByTagName($name, $idx = null)
436
  {
437
    $nodesList = $this->document->getElementsByTagName($name);
438
439
    $elements = new SimpleHtmlDomNode();
440
441
    foreach ($nodesList as $node) {
442
      $elements[] = new SimpleHtmlDom($node);
443
    }
444
445
    if (null === $idx) {
446
      return $elements;
447
    } else {
448
      if ($idx < 0) {
449
        $idx = count($elements) + $idx;
450
      }
451
    }
452
453
    if (isset($elements[$idx])) {
454
      return $elements[$idx];
455
    } else {
456
      return new SimpleHtmlDomNodeBlank();
457
    }
458
  }
459
460
  /**
461
   * Find list of nodes with a CSS selector.