Gravatar   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 50
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setParameter() 0 13 2
A setParameterFromColumn() 0 4 1
A toString() 0 9 2
1
<?php
2
3
namespace ZfcDatagrid\Column\DataPopulation\Object;
4
5
use ZfcDatagrid\Column\DataPopulation\ObjectAwareInterface;
6
7
class Gravatar implements ObjectAwareInterface
8
{
9
    /** @var string */
10
    protected $email;
11
12
    /**
13
     * @param string $name
14
     * @param mixed  $value
15
     *
16
     * @throws \Exception
17
     */
18
    private function setParameter($name, $value)
19
    {
20
        switch ($name) {
21
22
            case 'email':
23
                $this->email = (string) $value;
24
                break;
25
26
            default:
27
                throw new \InvalidArgumentException('Not allowed parameter: '.$name);
28
                break;
0 ignored issues
show
Unused Code introduced by
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
29
        }
30
    }
31
32
    /**
33
     * (non-PHPdoc).
34
     *
35
     * @see \ZfcDatagrid\Column\DataPopulation\ObjectAwareInterface::setParameterFromColumn()
36
     */
37
    public function setParameterFromColumn($name, $value)
38
    {
39
        $this->setParameter($name, $value);
40
    }
41
42
    /**
43
     * (non-PHPdoc).
44
     *
45
     * @see \ZfcDatagrid\Column\DataPopulation\ObjectAwareInterface::toString()
46
     */
47
    public function toString()
48
    {
49
        $hash = '';
50
        if ($this->email != '') {
51
            $hash = md5($this->email);
52
        }
53
54
        return 'http://www.gravatar.com/avatar/'.$hash;
55
    }
56
}
57