Completed
Pull Request — master (#1125)
by
unknown
09:35
created

ConceptPropertyValueLiteral::getContainsHtml()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Class for handling concept property values.
5
 */
6
class ConceptPropertyValueLiteral extends VocabularyDataObject
7
{
8
    /** the literal object for the property value */
9
    private $literal;
10
    /** property type */
11
    private $type;
12
13
    public function __construct($model, $vocab, $resource, $literal, $prop)
14
    {
15
        parent::__construct($model, $vocab, $resource);
16
        $this->literal = $literal;
17
        $this->type = $prop;
18
    }
19
20
    public function __toString()
21
    {
22
        if ($this->getLabel() === null) {
23
            return "";
24
        }
25
26
        return $this->getLabel();
27
    }
28
29
    public function getLang()
30
    {
31
        return $this->literal->getLang();
32
    }
33
34
    public function getType()
35
    {
36
        return $this->type;
37
    }
38
39
    public function getLabel()
40
    {
41
        // if the property is a date object converting it to a human readable representation.
42
        if ($this->literal instanceof EasyRdf\Literal\Date) {
43
            try {
44
                $val = $this->literal->getValue();
45
                return Punic\Calendar::formatDate($val, 'short');
46
            } catch (Exception $e) {
47
                trigger_error($e->getMessage(), E_USER_WARNING);
48
                return (string) $this->literal;
49
            }
50
        }
51
        return $this->literal->getValue();
52
    }
53
54
    public function getUri()
55
    {
56
        return null;
57
    }
58
59
    public function getNotation()
60
    {
61
        return null;
62
    }
63
64
    public function hasXlProperties()
65
    {
66
        $graph = $this->resource->getGraph();
67
        $resources = $graph->resourcesMatching('skosxl:literalForm', $this->literal);
68
        return !empty($resources);
69
    }
70
71
    public function getXlProperties()
72
    {
73
        $ret = array();
74
        $graph = $this->resource->getGraph();
75
        $resources = $graph->resourcesMatching('skosxl:literalForm', $this->literal);
76
        foreach ($resources as $xlres) {
77
            foreach ($xlres->properties() as $prop) {
0 ignored issues
show
Bug introduced by
The method properties cannot be called on $xlres (of type resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
78
                foreach($graph->allLiterals($xlres, $prop) as $val) {
0 ignored issues
show
Documentation introduced by
$xlres is of type resource, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
79
                    if ($prop !== 'rdf:type') {
80
                        $ret[$prop] = $val;
81
                    }
82
                }
83
            }
84
        }
85
        return $ret;
86
    }
87
88
}
89