PheanstalkHandler   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 0
loc 36
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A createQueue() 0 4 1
A clear() 0 8 1
A configure() 0 4 1
A doClear() 0 9 3
1
<?php
2
3
/*
4
 * This file is part of the Phive Queue package.
5
 *
6
 * (c) Eugene Leonovich <[email protected]>
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 Phive\Queue\Tests\Handler;
13
14
use Pheanstalk\Exception\ServerException;
15
use Pheanstalk\Pheanstalk;
16
use Phive\Queue\PheanstalkQueue;
17
18
class PheanstalkHandler extends Handler
19
{
20
    /**
21
     * @var \Pheanstalk\PheanstalkInterface
22
     */
23
    private $pheanstalk;
24
25
    public function createQueue()
26
    {
27
        return new PheanstalkQueue($this->pheanstalk, $this->getOption('tube_name'));
28
    }
29
30
    public function clear()
31
    {
32
        $tubeName = $this->getOption('tube_name');
33
34
        $this->doClear($tubeName, 'ready');
35
        $this->doClear($tubeName, 'buried');
36
        $this->doClear($tubeName, 'delayed');
37
    }
38
39
    protected function configure()
40
    {
41
        $this->pheanstalk = new Pheanstalk($this->getOption('host'), $this->getOption('port'));
42
    }
43
44
    private function doClear($tubeName, $state)
45
    {
46
        try {
47
            while ($item = $this->pheanstalk->{'peek'.$state}($tubeName)) {
48
                $this->pheanstalk->delete($item);
49
            }
50
        } catch (ServerException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
51
        }
52
    }
53
}
54