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

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