Code Duplication    Length = 24-24 lines in 2 locations

src/voku/helper/HtmlDomParser.php 1 location

@@ 414-437 (lines=24) @@
411
   *
412
   * @return SimpleHtmlDomNode|SimpleHtmlDomNode[]|SimpleHtmlDomNodeBlank
413
   */
414
  public function getElementsByTagName($name, $idx = null)
415
  {
416
    $nodesList = $this->document->getElementsByTagName($name);
417
418
    $elements = new SimpleHtmlDomNode();
419
420
    foreach ($nodesList as $node) {
421
      $elements[] = new SimpleHtmlDom($node);
422
    }
423
424
    if (null === $idx) {
425
      return $elements;
426
    } else {
427
      if ($idx < 0) {
428
        $idx = count($elements) + $idx;
429
      }
430
    }
431
432
    if (isset($elements[$idx])) {
433
      return $elements[$idx];
434
    } else {
435
      return new SimpleHtmlDomNodeBlank();
436
    }
437
  }
438
439
  /**
440
   * Find list of nodes with a CSS selector.

src/voku/helper/SimpleHtmlDom.php 1 location

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