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

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