AbstractRead   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 39
c 0
b 0
f 0
wmc 5
lcom 0
cbo 3
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A callback() 0 8 2
A generatePhpDoc() 0 6 1
A getPhpDocHint() 0 6 2
1
<?php
2
3
namespace Saxulum\Accessor\Accessors;
4
5
use Saxulum\Accessor\CallbackBag;
6
use Saxulum\Accessor\Prop;
7
8
abstract class AbstractRead extends AbstractAccessor
9
{
10
    /**
11
     * @param  CallbackBag $callbackBag
12
     * @return mixed
13
     */
14
    public function callback(CallbackBag $callbackBag)
15
    {
16
        if (count($callbackBag->getArguments()) !== 0) {
17
            throw new \InvalidArgumentException($this->getPrefix() . ' accessor allows no argument!');
18
        }
19
20
        return $callbackBag->getProperty();
21
    }
22
23
    /**
24
     * @param  Prop   $prop
25
     * @param  string $namespace
26
     * @return string
27
     */
28
    public static function generatePhpDoc(Prop $prop, $namespace)
29
    {
30
        $name = $prop->getName();
31
32
        return '* @method ' . static::getPhpDocHint($prop, $namespace) . static::PREFIX . ucfirst($name) . '()';
33
    }
34
35
    /**
36
     * @param  Prop   $prop
37
     * @param  string $namespace
38
     * @return string
39
     */
40
    protected static function getPhpDocHint(Prop $prop, $namespace)
41
    {
42
        $hint = $prop->getPhpDocHint($namespace);
43
44
        return '' !== $hint ? $hint . ' ' : '';
45
    }
46
}
47