AbstractRead::getPhpDocHint()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
rs 9.4285
cc 2
eloc 3
nc 2
nop 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