Passed
Pull Request — master (#57)
by Matthew
07:36
created

FibonacciWorker   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 46
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Dtc\QueueBundle\Tests;
4
5
use Dtc\QueueBundle\Model\Worker;
6
7
class FibonacciWorker extends Worker
8
{
9
    private $filename;
10
11
    public function __construct()
12
    {
13
        $this->filename = '/tmp/fib-result.txt';
14
    }
15
16
    public function fibonacciFile($n)
17
    {
18
        $feb = $this->fibonacci($n);
19
        file_put_contents($this->filename, "{$n}: {$feb}");
20
    }
21
22
    public function fibonacci($n)
23
    {
24
        if (0 == $n) {
25
            return 0;
26
        } //F0
27
        elseif (1 == $n) {
28
            return 1;
29
        } //F1
30
        else {
31
            return $this->fibonacci($n - 1) + $this->fibonacci($n - 2);
32
        }
33
    }
34
35
    public function getName()
36
    {
37
        return 'fibonacci';
38
    }
39
40
    public function exceptionThrown()
41
    {
42
        throw new \Exception('error...');
43
    }
44
45
    /**
46
     * @return string The filename
47
     */
48
    public function getFilename()
49
    {
50
        return $this->filename;
51
    }
52
}
53