Code Duplication    Length = 20-23 lines in 2 locations

PHPDaemon/Network/Connection.php 2 locations

@@ 579-598 (lines=20) @@
576
    {
577
        $this->type = 'udp';
578
        $pton = @inet_pton($host);
579
        if ($pton === false) { // dirty check
580
            \PHPDaemon\Clients\DNS\Pool::getInstance()->resolve($host, function ($result) use ($host, $port) {
581
                if (!$result) {
582
                    Daemon::log(get_class($this) . '->connectUdp : unable to resolve hostname: ' . $host);
583
                    $this->onStateEv($this->bev, \EventBufferEvent::ERROR);
584
                    return;
585
                }
586
                // @todo stack of addrs
587
                if (is_array($result)) {
588
                    srand(Daemon::$process->getPid());
589
                    $real = $result[rand(0, sizeof($result) - 1)];
590
                    srand();
591
                } else {
592
                    $real = $result;
593
                }
594
                $this->connectUdp($real, $port);
595
            });
596
            return true;
597
        }
598
        $this->hostReal = $host;
599
        if ($this->host === null) {
600
            $this->host = $this->hostReal;
601
        }
@@ 637-659 (lines=23) @@
634
        $this->type = 'tcp';
635
        $pton = @inet_pton($host);
636
        $fd = null;
637
        if ($pton === false) { // dirty check
638
            \PHPDaemon\Clients\DNS\Pool::getInstance()->resolve($this->host, function ($result) use ($host, $port) {
639
                if (!$result) {
640
                    Daemon::log(get_class($this) . '->connectTcp : unable to resolve hostname: ' . $host);
641
                    $this->onStateEv($this->bev, \EventBufferEvent::ERROR);
642
                    return;
643
                }
644
                // @todo stack of addrs
645
                if (is_array($result)) {
646
                    if (!sizeof($result)) {
647
                        return;
648
                    }
649
                    srand(Daemon::$process->getPid());
650
                    $real = $result[rand(0, sizeof($result) - 1)];
651
                    srand();
652
                } else {
653
                    $real = $result;
654
                }
655
                $this->connectTcp($real, $port);
656
            });
657
            return true;
658
        }
659
        $this->hostReal = $host;
660
        if ($this->host === null) {
661
            $this->host = $this->hostReal;
662
        }