Completed
Push — master ( d3db5d...0f1d78 )
by Henri
02:25
created

ConceptPropertyValueLiteral   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A __toString() 0 8 2
A getLang() 0 4 1
A getType() 0 4 1
A getContainsHtml() 0 3 1
A getLabel() 0 14 3
A getUri() 0 4 1
A getNotation() 0 4 1
A hasXlProperties() 0 7 1
B getXlProperties() 0 16 5
1
<?php
2
3
/**
4
 * Class for handling concept property values.
5
 */
6
class ConceptPropertyValueLiteral extends VocabularyDataObject
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
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 getContainsHtml() {
40
        return preg_match("/\/[a-z]*>/i", $this->literal->getValue()) != 0;
41
    }
42
43
    public function getLabel()
44
    {
45
        // if the property is a date object converting it to a human readable representation.
46
        if ($this->literal instanceof EasyRdf\Literal\Date) {
47
            try {
48
                $val = $this->literal->getValue();
49
                return Punic\Calendar::formatDate($val, 'short');
50
            } catch (Exception $e) {
51
                trigger_error($e->getMessage(), E_USER_WARNING);
52
                return (string) $this->literal;
53
            }
54
        }
55
        return $this->literal->getValue();
56
    }
57
58
    public function getUri()
59
    {
60
        return null;
61
    }
62
63
    public function getNotation()
64
    {
65
        return null;
66
    }
67
68
    public function hasXlProperties()
69
    {
70
        $ret = array();
0 ignored issues
show
Unused Code introduced by
$ret is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
71
        $graph = $this->resource->getGraph();
72
        $resources = $graph->resourcesMatching('skosxl:literalForm', $this->literal);
73
        return !empty($resources);
74
    }
75
76
    public function getXlProperties()
77
    {
78
        $ret = array();
79
        $graph = $this->resource->getGraph();
80
        $resources = $graph->resourcesMatching('skosxl:literalForm', $this->literal);
81
        foreach ($resources as $xlres) {
82
            foreach ($xlres->properties() as $prop) {
83
                foreach($graph->allLiterals($xlres, $prop) as $val) {
84
                    if ($prop !== 'rdf:type') {
85
                        $ret[$prop] = $val;
86
                    }
87
                }
88
            }
89
        }
90
        return $ret;
91
    }
92
93
}
94