Test Failed
Branch master (9dd5cd)
by Blackred
03:57
created

ProxySelector   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 1
cbo 1
dl 0
loc 26
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getHTTPProxy() 0 10 2
1
<?php declare(strict_types=1);
2
3
namespace Wolnosciowiec\WebProxy\Service\Proxy;
4
5
use Wolnosciowiec\WebProxy\Entity\ProxyServerAddress;
6
use Wolnosciowiec\WebProxy\Providers\Proxy\ProxyProviderInterface;
7
8
/**
9
 * Selects a HTTP/HTTPS proxy from provider
10
 * ----------------------------------------
11
 *
12
 * @package Wolnosciowiec\WebProxy\Service\Proxy
13
 */
14
class ProxySelector
15
{
16
    /**
17
     * @var ProxyServerAddress[] $addresses
18
     */
19
    private $addresses;
20
21
    public function __construct(ProxyProviderInterface $provider)
22
    {
23
        $this->addresses = $provider->collectAddresses();
24
    }
25
26
    /**
27
     * @return string
28
     */
29
    public function getHTTPProxy(): string
30
    {
31
        shuffle($this->addresses);
32
33
        foreach ($this->addresses as $address) {
34
            return $address->getFormatted();
35
        }
36
37
        return '';
38
    }
39
}
40