ProxybonanzaGetRandomProxyCommand::execute()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 35
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 20
nc 1
nop 2
dl 0
loc 35
rs 8.8571
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the wow-apps/symfony-proxybonanza project
4
 * https://github.com/wow-apps/symfony-proxybonanza
5
 *
6
 * (c) 2016 WoW-Apps
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WowApps\ProxybonanzaBundle\Command;
13
14
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
15
use Symfony\Component\Console\Input\InputInterface;
16
use Symfony\Component\Console\Output\OutputInterface;
17
use Symfony\Component\Console\Style\SymfonyStyle;
18
use WowApps\ProxybonanzaBundle\Service\ProxyBonanza;
19
use WowApps\ProxybonanzaBundle\Traits\HelperTrait;
20
21
/**
22
 * Class ProxybonanzaGetRandomProxyCommand
23
 * @author Alexey Samara <[email protected]>
24
 * @package wow-apps/symfony-proxybonanza
25
 */
26
class ProxybonanzaGetRandomProxyCommand extends ContainerAwareCommand
27
{
28
    use HelperTrait;
29
30
    protected function configure()
31
    {
32
        $this
33
            ->setName('wowapps:proxybonanza:random')
34
            ->setDescription('View random proxy')
35
        ;
36
    }
37
38
    /**
39
     * @param InputInterface $input
40
     * @param OutputInterface $output
41
     * @return int|null|void
42
     */
43
    protected function execute(InputInterface $input, OutputInterface $output)
44
    {
45
        $timeStart = microtime(true);
46
47
        /** @var ProxyBonanza $proxyBonanza */
48
        $proxyBonanza = $this->getContainer()->get('wowapps.proxybonanza');
49
50
        $symfonyStyle = new SymfonyStyle($input, $output);
51
        $symfonyStyle->title(' P R O X Y   B O N A N Z A   R A N D O M   P R O X Y ');
52
53
        $randomProxy = $proxyBonanza->getRandomProxy(
54
            $proxyBonanza->getLocalProxies()
55
        );
56
57
        $header = ['ip', 'http port', 'socks port', 'login', 'password', 'region'];
58
59
        $body[] = [
0 ignored issues
show
Comprehensibility Best Practice introduced by
$body was never initialized. Although not strictly required by PHP, it is generally a good practice to add $body = array(); before regardless.
Loading history...
60
            $randomProxy->getProxyId(),
61
            $randomProxy->getProxyPortHttp(),
62
            $randomProxy->getProxyPortSocks(),
63
            $randomProxy->getPlan()->getLogin(),
64
            $randomProxy->getPlan()->getPassword(),
65
            $randomProxy->getProxyRegionCountryName()
66
        ];
67
68
        $symfonyStyle->table($header, $body);
69
70
        $symfonyStyle->note(
71
            sprintf(
72
                'Command is executed in %s seconds',
73
                $this->formatSpentTime($timeStart)
74
            )
75
        );
76
77
        $symfonyStyle->newLine(2);
78
    }
79
}
80