Completed
Push — master ( e67b12...6841f1 )
by Ilias
05:15
created

Manager   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 6
Bugs 0 Features 0
Metric Value
wmc 6
c 6
b 0
f 0
lcom 1
cbo 7
dl 0
loc 73
ccs 26
cts 26
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A stats() 0 7 1
A peek() 0 7 1
A tubes() 0 14 2
A __toString() 0 4 1
1
<?php
2
3
4
namespace Beanie;
5
6
7
use Beanie\Command\CommandFactory;
8
use Beanie\Command\CommandInterface;
9
use Beanie\Job\JobFactory;
10
use Beanie\Server\Server;
11
use Beanie\Tube\Tube;
12
13
class Manager
14
{
15
    /** @var Server */
16
    protected $server;
17
18
    /** @var CommandFactory */
19
    protected $commandFactory;
20
21
    /** @var JobFactory */
22
    protected $jobFactory;
23
24
    /**
25
     * @param Server $server
26
     */
27 6
    public function __construct(Server $server)
28
    {
29 6
        $this->server = $server;
30 6
        $this->commandFactory = CommandFactory::instance();
31 6
        $this->jobFactory = JobFactory::instance();
32 6
    }
33
34
    /**
35
     * @return array
36
     * @throws Exception\InvalidArgumentException
37
     */
38 1
    public function stats()
39
    {
40 1
        return $this->server
41 1
            ->dispatchCommand($this->commandFactory->create(CommandInterface::COMMAND_STATS))
42 1
            ->invoke()
43 1
            ->getData();
44
    }
45
46
    /**
47
     * @param int $jobId
48
     * @return Job\Job|null
49
     * @throws Exception\InvalidArgumentException
50
     */
51 2
    public function peek($jobId)
52
    {
53 2
        return $this->jobFactory->createFromCommand(
54 2
            $this->commandFactory->create(CommandInterface::COMMAND_PEEK, [$jobId]),
55 2
            $this->server
56 2
        )->invoke();
57
    }
58
59
    /**
60
     * @return Tube[]
61
     * @throws Exception\InvalidArgumentException
62
     */
63 1
    public function tubes()
64
    {
65 1
        $tubes = [];
66
67
        foreach (
68 1
            $this->server->dispatchCommand(
69 1
                $this->commandFactory->create(CommandInterface::COMMAND_LIST_TUBES)
70 1
            )->invoke()->getData() as $tubeName
71 1
        ) {
72 1
            $tubes[] = new Tube($tubeName, $this->server);
73 1
        }
74
75 1
        return $tubes;
76
    }
77
78
    /**
79
     * @return string
80
     */
81 1
    public function __toString()
82
    {
83 1
        return (string)$this->server;
84
    }
85
}
86