IdentifierRenderer::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
namespace rtens\domin\delivery\web\renderers;
3
4
use rtens\domin\delivery\Renderer;
5
use rtens\domin\delivery\web\renderers\link\LinkPrinter;
6
use rtens\domin\parameters\Identifier;
7
use rtens\domin\delivery\web\Element;
8
9
class IdentifierRenderer implements Renderer {
10
11
    /** @var LinkPrinter */
12
    private $links;
13
14
    public function __construct(LinkPrinter $links) {
15
        $this->links = $links;
16
    }
17
18
    /**
19
     * @param mixed $value
20
     * @return bool
21
     */
22
    public function handles($value) {
23
        return $value instanceof Identifier;
24
    }
25
26
    /**
27
     * @param Identifier $value
28
     * @return mixed
29
     */
30
    public function render($value) {
31
        $caption = (new \ReflectionClass($value->getTarget()))->getShortName();
32
        $out = $value->getId();
33
34
        $dropDown = $this->links->createDropDown($value, $caption);
35
        if ($dropDown) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $dropDown of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
36
            $out .= new Element('span', ['class' => 'pull-right'], $dropDown);
37
        }
38
39
        return $out;
40
    }
41
}