Completed
Pull Request — develop (#24)
by Ben
06:57 queued 04:18
created

Object   C

Complexity

Total Complexity 1

Size/Duplication

Total Lines 231
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 26

Importance

Changes 0
Metric Value
wmc 1
lcom 1
cbo 26
dl 0
loc 231
rs 5
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B init() 0 177 1
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 31 and the first side effect is on line 263.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
use GroupByInc\API\Model\BannerZone;
4
use GroupByInc\API\Model\Cluster;
5
use GroupByInc\API\Model\ClusterRecord;
6
use GroupByInc\API\Model\ContentZone;
7
use GroupByInc\API\Model\CustomUrlParam;
8
use GroupByInc\API\Model\Metadata;
9
use GroupByInc\API\Model\Navigation;
10
use GroupByInc\API\Model\PageInfo;
11
use GroupByInc\API\Model\Record;
12
use GroupByInc\API\Model\RecordZone;
13
use GroupByInc\API\Model\RefinementMatch;
14
use GroupByInc\API\Model\RefinementRange;
15
use GroupByInc\API\Model\RefinementsResult;
16
use GroupByInc\API\Model\RefinementValue;
17
use GroupByInc\API\Model\Results;
18
use GroupByInc\API\Model\RichContentZone;
19
use GroupByInc\API\Model\Sort;
20
use GroupByInc\API\Model\Template;
21
use GroupByInc\API\Model\Zone;
22
use GroupByInc\API\Request\Bias;
23
use GroupByInc\API\Request\Bias\Strength;
24
use GroupByInc\API\Request\Biasing;
25
use GroupByInc\API\Request\MatchStrategy;
26
use GroupByInc\API\Request\PartialMatchRule;
27
use GroupByInc\API\Request\RefinementsRequest;
28
use GroupByInc\API\Request\Request;
29
use GroupByInc\API\Request\RestrictNavigation;
30
31
class Object
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...
32
{
33
    /** @var Metadata */
34
    public static $METADATA;
35
    /** @var PageInfo */
36
    public static $PAGE_INFO;
37
    /** @var Cluster */
38
    public static $CLUSTER;
39
    /** @var ClusterRecord */
40
    public static $CLUSTER_RECORD;
41
    /** @var RefinementRange */
42
    public static $REFINEMENT_RANGE;
43
    /** @var RefinementValue */
44
    public static $REFINEMENT_VALUE;
45
    /** @var Navigation */
46
    public static $NAVIGATION;
47
    /** @var ContentZone */
48
    public static $CONTENT_ZONE;
49
    /** @var BannerZone */
50
    public static $BANNER_ZONE;
51
    /** @var RichContentZone */
52
    public static $RICH_CONTENT_ZONE;
53
    /** @var RecordZone */
54
    public static $RECORD_ZONE;
55
    /** @var RefinementMatch\Value */
56
    public static $REFINEMENT_MATCH_VALUE;
57
    /** @var RefinementMatch */
58
    public static $REFINEMENT_MATCH;
59
    /** @var Record */
60
    public static $RECORD;
61
    /** @var Template */
62
    public static $TEMPLATE;
63
    /** @var CustomUrlParam */
64
    public static $CUSTOM_URL_PARAM;
65
    /** @var Biasing */
66
    public static $BIASING;
67
    /** @var Request */
68
    public static $REQUEST;
69
    /** @var RefinementsRequest */
70
    public static $REFINEMENTS_REQUEST;
71
    /** @var Sort */
72
    public static $SORT;
73
    /** @var RestrictNavigation */
74
    public static $RESTRICT_NAVIGATION;
75
    /** @var PartialMatchRule */
76
    public static $PARTIAL_MATCH_RULE;
77
    /** @var MatchStrategy */
78
    public static $MATCH_STRATEGY;
79
    /** @var Results */
80
    public static $RESULTS;
81
    /** @var RefinementsResult */
82
    public static $REFINEMENTS_RESULT;
83
84
    public static function init()
85
    {
86
        self::$METADATA = new Metadata();
87
        self::$METADATA->setKey("orange")->setValue("apple");
88
89
        self::$PAGE_INFO = new PageInfo();
90
        self::$PAGE_INFO->setRecordStart(20)
91
            ->setRecordEnd(50);
92
93
        self::$CLUSTER_RECORD = new ClusterRecord();
94
        self::$CLUSTER_RECORD->setTitle("fubar")
95
            ->setUrl("example.com")
96
            ->setSnippet("itty bit");
97
98
        self::$CLUSTER = new Cluster();
99
        self::$CLUSTER->setRecords(array(self::$CLUSTER_RECORD))
100
            ->setTerm("some");
101
102
        self::$REFINEMENT_RANGE = new RefinementRange();
103
        self::$REFINEMENT_RANGE->setId("342h9582hh4")
104
            ->setCount(14)
105
            ->setHigh("delicious")
106
            ->setLow("atrocious")
107
            ->setExclude(true);
108
109
        self::$REFINEMENT_VALUE = new RefinementValue();
110
        self::$REFINEMENT_VALUE->setId("fadfs89y10j")
111
            ->setCount(987)
112
            ->setValue("malaise")
113
            ->setExclude(false);
114
115
        self::$SORT = new Sort();
116
        self::$SORT->setOrder(Sort\Order::Descending)
117
            ->setField("price");
118
119
        self::$NAVIGATION = new Navigation();
120
        self::$NAVIGATION->setName("green")
121
            ->setDisplayName("GReeN")
122
            ->setId("081h29n81f")
123
            ->setOr(false)
124
            ->setType(Navigation\Type::Range_Date)
125
            ->setRange(true)
126
            ->setSort(self::$SORT)
127
            ->setMetadata(array(self::$METADATA))
128
            ->setRefinements(array(self::$REFINEMENT_RANGE, self::$REFINEMENT_VALUE))
129
            ->setMoreRefinements(true)
130
            ->setIgnored(true);
131
132
        self::$REFINEMENT_MATCH_VALUE = new RefinementMatch\Value();
133
        self::$REFINEMENT_MATCH_VALUE->setValue('adverb')
134
            ->setCount(43);
135
136
        self::$REFINEMENT_MATCH = new RefinementMatch();
137
        self::$REFINEMENT_MATCH->setName('grapheme')
138
            ->setValues(array(self::$REFINEMENT_MATCH_VALUE));
139
140
        self::$RECORD = new Record();
141
        self::$RECORD->setId("fw90314jh289t")
142
            ->setTitle("Periwinkle")
143
            ->setSnippet("Curator")
144
            ->setUrl("exemplar.com")
145
            ->setAllMeta(array(
0 ignored issues
show
Documentation introduced by
array('look' => 'at', 'a...are', 'the', 'values')) is of type array<string,string|arra...",\"3\":\"string\"}>"}>, but the function expects a array<integer,object>.

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...
146
                "look" => "at",
147
                "all" => "my",
148
                "keys" => array("we", "are", "the", "values")
149
            ))
150
            ->setRefinementMatches(array(self::$REFINEMENT_MATCH));
151
152
        self::$CONTENT_ZONE = new ContentZone();
153
        self::$CONTENT_ZONE->setId("23425n89hr")
154
            ->setName("porcelain")
155
            ->setContent("mushy");
156
157
        self::$BANNER_ZONE = new BannerZone();
158
        self::$BANNER_ZONE->setId("asf0j2380jf")
159
            ->setName("vitruvian")
160
            ->setBannerUrl("man");
161
162
        self::$RICH_CONTENT_ZONE = new RichContentZone();
163
        self::$RICH_CONTENT_ZONE->setId("f90j1e1rf")
164
            ->setName("appalled")
165
            ->setRichContent("crestfallen");
166
167
        self::$RECORD_ZONE = new RecordZone();
168
        self::$RECORD_ZONE->setId("1240jfw9s8")
169
            ->setName("gorbachev")
170
            ->setQuery("searchTerms")
171
            ->setRecords(array(self::$RECORD));
172
173
        self::$TEMPLATE = new Template();
174
        self::$TEMPLATE->setId("fad87g114")
175
            ->setName("bulbous")
176
            ->setRuleName("carmageddon")
177
            ->setZones(array(
178
                "content_zone" => self::$CONTENT_ZONE,
179
                "record_zone" => self::$RECORD_ZONE
180
            ));
181
182
        self::$CUSTOM_URL_PARAM = new CustomUrlParam();
183
        self::$CUSTOM_URL_PARAM->setKey("guava")->setValue("mango");
184
185
        self::$RESTRICT_NAVIGATION = new RestrictNavigation();
186
        self::$RESTRICT_NAVIGATION->setCount(2)
187
            ->setName("categories");
188
189
        self::$PARTIAL_MATCH_RULE = new PartialMatchRule();
190
        self::$PARTIAL_MATCH_RULE->setMustMatch(4)
191
            ->setTerms(2)
192
            ->setTermsGreaterThan(45)
193
            ->setPercentage(true);
194
195
        self::$MATCH_STRATEGY = new MatchStrategy();
196
        self::$MATCH_STRATEGY->setRules(array(self::$PARTIAL_MATCH_RULE));
197
198
        self::$BIASING = new Biasing();
199
        self::$BIASING->setBringToTop(["1314", "1425", "5153"]);
200
        self::$BIASING->setAugmentBiases(true);
201
        self::$BIASING->setInfluence(8.0);
202
        self::$BIASING->setBiases(array(
203
            (new Bias())->setName("keys")->setContent("values")->setStrength(Strength::Strong_Increase),
204
            (new Bias())->setName("all")->setContent("my")->setStrength(Strength::Strong_Decrease)
205
        ));
206
207
        self::$REQUEST = new Request();
208
        self::$REQUEST->clientKey = "adf7h8er7h2r";
209
        self::$REQUEST->userId = "farmer";
210
        self::$REQUEST->collection = "ducks";
211
        self::$REQUEST->area = "surface";
212
        self::$REQUEST->skip = 12;
213
        self::$REQUEST->pageSize = 30;
214
        self::$REQUEST->biasingProfile = "ballooning";
215
        self::$REQUEST->language = "en";
216
        self::$REQUEST->pruneRefinements = true;
217
        self::$REQUEST->returnBinary = false;
218
        self::$REQUEST->query = "cantaloupe";
219
        self::$REQUEST->refinementQuery = "cranberry";
220
        self::$REQUEST->sort = array(self::$SORT);
0 ignored issues
show
Documentation Bug introduced by
It seems like array(self::$SORT) of type array<integer,object<Gro...c\\API\\Model\\Sort>"}> is incompatible with the declared type array<integer,object<Gro...yInc\API\Request\Sort>> of property $sort.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
221
        self::$REQUEST->fields = array("pineapple", "grape", "clementine");
222
        self::$REQUEST->orFields = array("pumpernickel", "rye");
223
        self::$REQUEST->includedNavigations = array("height");
224
        self::$REQUEST->excludedNavigations = array("rating");
225
        self::$REQUEST->refinements = array(self::$REFINEMENT_RANGE, self::$REFINEMENT_VALUE);
0 ignored issues
show
Documentation Bug introduced by
It seems like array(self::$REFINEMENT_...elf::$REFINEMENT_VALUE) of type array<integer,object<Gro...el\\RefinementValue>"}> is incompatible with the declared type array<integer,object<Gro...st\SelectedRefinement>> of property $refinements.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
226
        self::$REQUEST->customUrlParams = array(self::$CUSTOM_URL_PARAM);
227
        self::$REQUEST->wildcardSearchEnabled = true;
228
        self::$REQUEST->restrictNavigation = self::$RESTRICT_NAVIGATION;
229
        self::$REQUEST->matchStrategy = self::$MATCH_STRATEGY;
230
        self::$REQUEST->biasing = self::$BIASING;
231
232
        self::$REFINEMENTS_REQUEST = new RefinementsRequest();
233
        self::$REFINEMENTS_REQUEST->originalQuery = self::$REQUEST;
234
        self::$REFINEMENTS_REQUEST->navigationName = "height";
235
236
        self::$RESULTS = new Results();
237
        self::$RESULTS->setId("1321asb");
238
        self::$RESULTS->setArea("christmas");
239
        self::$RESULTS->setBiasingProfile("unbiased");
240
        self::$RESULTS->setAvailableNavigation(array(Object::$NAVIGATION));
241
        self::$RESULTS->setDidYouMean(array("square", "skewer"));
242
        self::$RESULTS->setErrors("criminey!");
243
        self::$RESULTS->setPageInfo(Object::$PAGE_INFO);
244
        self::$RESULTS->setQuery("skwuare");
245
        self::$RESULTS->setOriginalQuery("skwuare---");
246
        self::$RESULTS->setCorrectedQuery("square");
247
        self::$RESULTS->setRecords(array(Object::$RECORD));
248
        self::$RESULTS->setRedirect("/to/the/moon.html");
249
        self::$RESULTS->setSelectedNavigation(array(Object::$NAVIGATION));
250
        self::$RESULTS->setTemplate(Object::$TEMPLATE);
251
        self::$RESULTS->setSiteParams(array(Object::$METADATA));
252
        self::$RESULTS->setRelatedQueries(array("squawk", "ask"));
253
        self::$RESULTS->setRewrites(array("Synonym", "Antonym", "Homonym"));
254
        self::$RESULTS->setTotalRecordCount(34);
255
        self::$RESULTS->setWarnings(array("Selected refinement field 'nonRefinable' must have 'refinable:true' in the upload configuration."));
256
257
        self::$REFINEMENTS_RESULT = new RefinementsResult();
258
        self::$REFINEMENTS_RESULT->setErrors("Could not load");
259
        self::$REFINEMENTS_RESULT->setNavigation(Object::$NAVIGATION);
260
    }
261
}
262
263
Object::init();
264