RoundRobin   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 92.31%

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 37
ccs 12
cts 13
cp 0.9231
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getNextServer() 0 8 2
A distribute() 0 9 3
1
<?php
2
namespace Aoe\Asdis\Domain\Model\DistributionAlgorithm;
3
4
use Aoe\Asdis\Domain\Model\Asset\Collection as AssetCollection;
5
use Aoe\Asdis\Domain\Model\DistributionAlgorithm\DistributionAlgorithmInterface;
6
use Aoe\Asdis\Domain\Model\Server\Collection as ServerCollection;
7
8
/**
9
 * RoundRobin implementation of a distribution algorithm.
10
 */
11
class RoundRobin implements DistributionAlgorithmInterface
12
{
13
    /**
14
     * @var \Aoe\Asdis\Domain\Model\Server\Collection
15
     */
16
    private $servers;
17
18
    /**
19
     * Distributes the given assets to the given servers.
20
     *
21
     * @param \Aoe\Asdis\Domain\Model\Asset\Collection $assets
22
     * @param \Aoe\Asdis\Domain\Model\Server\Collection $servers
23
     * @return void
24
     */
25 1
    public function distribute(AssetCollection $assets, ServerCollection $servers)
26
    {
27 1
        if ($servers->count() < 1) {
28
            return;
29
        }
30 1
        $this->servers = $servers;
31 1
        foreach($assets as $asset) {
32
            /** @var \Aoe\Asdis\Domain\Model\Asset $asset */
33 1
            $asset->setServer($this->getNextServer());
34
        }
35 1
    }
36
37
    /**
38
     * @return \Aoe\Asdis\Domain\Model\Server
39
     */
40 1
    private function getNextServer()
41
    {
42 1
        $server = $this->servers->current();
43 1
        $this->servers->next();
44 1
        if (false === $this->servers->valid()) {
45 1
            $this->servers->rewind();
46
        }
47 1
        return $server;
48
    }
49
}