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

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