Code Duplication    Length = 24-24 lines in 2 locations

src/voku/helper/SimpleHtmlDom.php 1 location

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

src/voku/helper/HtmlDomParser.php 1 location

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