Completed
Push — master ( 1d9aa7...03d576 )
by Henri
10:00
created

ConceptSearchParameters::getParentLimit()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 2
eloc 2
nc 2
nop 0
1
<?php
2
3
/**
4
 * ConceptSearchParameters is used for search parameters.
5
 */
6
class ConceptSearchParameters
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
9
    private $config;
10
    private $request;
11
    private $vocabs;
12
    private $rest;
13
    private $hidden;
14
    private $unique;
15
16
    public function __construct($request, $config, $rest = false) 
17
    {
18
        $this->request = $request;
19
        $this->config = $config;
20
        $this->rest = $rest;
21
        $this->hidden = true;
22
        $this->unique = $request->getQueryParamBoolean('unique', false);
23
    }
24
25
    public function getLang() 
26
    {
27
        if ($this->rest && $this->request->getQueryParam('labellang')) {
28
            return $this->request->getQueryParam('labellang');
29
        }
30
        return $this->request->getLang();
31
    } 
32
33
    public function getVocabs() 
34
    {
35
        if ($this->vocabs) {
36
            return $this->vocabs;
37
        }
38
        return array($this->request->getVocab());
39
    } 
40
41
    public function getVocabIds()
42
    {
43 View Code Duplication
        if ($this->rest) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
44
            $vocabs = $this->request->getQueryParam('vocab');
45
            return ($vocabs !== null && $vocabs !== '') ? explode(' ', $vocabs) : null;
46
        }
47 View Code Duplication
        if ($this->request->getQueryParam('vocabs')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
48
            $vocabs = $this->request->getQueryParam('vocabs'); 
49
            return ($vocabs !== null && $vocabs !== '') ? explode(' ', $vocabs) : null;
50
        }
51
        return array(reset($this->getVocabs())->getId());
0 ignored issues
show
Bug introduced by
$this->getVocabs() cannot be passed to reset() as the parameter $array expects a reference.
Loading history...
52
    }
53
54
    public function setVocabularies($vocabs) 
55
    {
56
        $this->vocabs = $vocabs;
57
    }
58
    
59
    public function getArrayClass() 
60
    {
61
        if (sizeof($this->getVocabIds()) == 1) { // search within vocabulary
62
            return reset($this->getVocabs())->getConfig()->getArrayClassURI();
0 ignored issues
show
Bug introduced by
$this->getVocabs() cannot be passed to reset() as the parameter $array expects a reference.
Loading history...
63
        }
64
        return null;
65
    }
66
    
67
    public function getSearchTerm() 
68
    {
69
        $term = $this->request->getQueryParam('q') ? $this->request->getQueryParam('q') : $this->request->getQueryParam('query');
70
        if (!$term && $this->rest)
71
            $term = $this->request->getQueryParam('label');
72
        $term = trim($term); // surrounding whitespace is not considered significant
73
        return strpos($term, "*") === false ? $term . "*" : $term; // default to prefix search
74
    }
75
    
76
    public function getContentLang() 
77
    {
78
        return $this->request->getContentLang();
79
    }
80
        
81
    public function getConceptGroups() 
82
    {
83
        return $this->vocab->listConceptGroups($content_lang);
0 ignored issues
show
Bug introduced by
The property vocab does not seem to exist. Did you mean vocabs?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
Bug introduced by
The variable $content_lang does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
84
    }
85
    
86
    public function getSearchLang() 
87
    {
88
        if ($this->rest) {
89
            return $this->request->getQueryParam('lang');
90
        }
91
        return $this->request->getQueryParam('anylang') ? '' : $this->getContentLang();
92
    }
93
94
    public function getTypeLimit() 
95
    {
96
        $type = $this->request->getQueryParam('type') !== '' ? $this->request->getQueryParam('type') : null;
97
        if ($type && strpos($type, '+')) {
98
            $type = explode('+', $type);
99
        } else if ($type && !is_array($type)) {
100
            // if only one type param given place it into an array regardless
101
            $type = array($type);
102
        }
103
        if ($type === null) {
104
            $type = array('skos:Concept');
105
        }
106
        return $type;
107
    }
108
109
    public function getGroupLimit() 
110
    {
111
        return $this->request->getQueryParam('group') !== '' ? $this->request->getQueryParam('group') : null;
112
    }
113
    
114
    public function getParentLimit() 
115
    {
116
        return $this->request->getQueryParam('parent') !== '' ? $this->request->getQueryParam('parent') : null;
117
    }
118
119
    public function getOffset() 
120
    {
121
        return ($this->request->getQueryParam('offset') && is_numeric($this->request->getQueryParam('offset')) && $this->request->getQueryParam('offset') >= 0) ? $this->request->getQueryParam('offset') : 0;
122
    }
123
124
    public function getSearchLimit()
125
    {
126
        return $this->config->getDefaultSearchLimit();
127
    }
128
129
    public function getUnique() {
130
        return $this->unique;
131
    }
132
133
    public function setUnique($unique) {
134
        $this->unique = $unique;
135
    }
136
137
    public function getAdditionalFields() {
138
        return $this->request->getQueryParam('fields') ? explode(' ', $request->getQueryParam('fields')) : null;
0 ignored issues
show
Bug introduced by
The variable $request does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
139
    }
140
    
141
    public function getHidden() {
142
        return $this->hidden;
143
    }
144
    
145
    public function setHidden($hidden) {
146
        $this->hidden = $hidden;
147
    }
148
    
149
    public function setAdditionalFields($fields) {
150
        $this->fields = $fields;
0 ignored issues
show
Bug introduced by
The property fields does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
151
    }
152
153
}
154