Code Duplication    Length = 25-25 lines in 2 locations

src/Address/IPv4.php 1 location

@@ 408-432 (lines=25) @@
405
     *
406
     * @see \IPLib\Address\AddressInterface::getAddressAtOffset()
407
     */
408
    public function getAddressAtOffset($n)
409
    {
410
        if (!is_int($n)) {
411
            return null;
412
        }
413
414
        $boundary = 256;
415
        $mod = $n;
416
        $bytes = $this->getBytes();
417
        for ($i = count($bytes) - 1; $i >= 0; $i--) {
418
            $tmp = ($bytes[$i] + $mod) % $boundary;
419
            $mod = (int) floor(($bytes[$i] + $mod) / $boundary);
420
            if ($tmp < 0) {
421
                $tmp += $boundary;
422
            }
423
424
            $bytes[$i] = $tmp;
425
        }
426
427
        if ($mod !== 0) {
428
            return null;
429
        }
430
431
        return static::fromBytes($bytes);
432
    }
433
434
    /**
435
     * {@inheritdoc}

src/Address/IPv6.php 1 location

@@ 511-535 (lines=25) @@
508
     *
509
     * @see \IPLib\Address\AddressInterface::getAddressAtOffset()
510
     */
511
    public function getAddressAtOffset($n)
512
    {
513
        if (!is_int($n)) {
514
            return null;
515
        }
516
517
        $boundary = 0x10000;
518
        $mod = $n;
519
        $words = $this->getWords();
520
        for ($i = count($words) - 1; $i >= 0; $i--) {
521
            $tmp = ($words[$i] + $mod) % $boundary;
522
            $mod = (int) floor(($words[$i] + $mod) / $boundary);
523
            if ($tmp < 0) {
524
                $tmp += $boundary;
525
            }
526
527
            $words[$i] = $tmp;
528
        }
529
530
        if ($mod !== 0) {
531
            return null;
532
        }
533
534
        return static::fromWords($words);
535
    }
536
537
    /**
538
     * {@inheritdoc}