Issues (46)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/PSolr/Request/Highlight.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace PSolr\Request;
4
5
/**
6
 * @see http://wiki.apache.org/solr/HighlightingParameters
7
 */
8
class Highlight extends SolrRequest implements ComponentInterface
9
{
10
    const FORMATTER_SIMPLE = 'formatter';
11
12
    /**
13
     * {@inheritDoc}
14
     *
15
     * Sets the query that is used in the base query.
16
     */
17
    public function preMergeParams(SolrRequest $request)
18
    {
19 View Code Duplication
        if (isset($request['q']) && !isset($this['hl.q'])) {
0 ignored issues
show
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...
20
            $this['hl.q'] = $request['q'];
21
        }
22
    }
23
24
    /**
25
     * {@inheritDoc}
26
     *
27
     * Enables highlighting.
28
     */
29
    public function init()
30
    {
31
        $this->highlight();
32
    }
33
34
    /**
35
     * @param bool $highlight
36
     *
37
     * @return \Psolr\Component\Highlight
38
     *
39
     * @see http://wiki.apache.org/solr/HighlightingParameters#hl
40
     */
41
    public function highlight($highlight = true)
0 ignored issues
show
Coding Style Best Practice introduced by
Please use __construct() instead of a PHP4-style constructor that is named after the class.
Loading history...
42
    {
43
        return $this->set('highlight', $highlight);
44
    }
45
46
    /**
47
     * @param string $query
48
     *
49
     * @return \Psolr\Component\Highlight
50
     *
51
     * @see http://wiki.apache.org/solr/HighlightingParameters#hl.q
52
     */
53
    public function setQuery($query)
54
    {
55
        return $this->set('hl.q', $query);
56
    }
57
58
    /**
59
     * @param int $snippets
60
     *
61
     * @return \Psolr\Component\Highlight
62
     *
63
     * @see http://wiki.apache.org/solr/HighlightingParameters#hl.snippets
64
     */
65
    public function setSnippets($snippets)
66
    {
67
        return $this->set('hl.snippets', $snippets);
68
    }
69
70
    /**
71
     * @param int $fragsize
72
     *
73
     * @return \Psolr\Component\Highlight
74
     *
75
     * @see http://wiki.apache.org/solr/HighlightingParameters#hl.fragsize
76
     */
77
    public function setFragsize($fragsize)
78
    {
79
        return $this->set('hl.fragsize', $fragsize);
80
    }
81
82
    /**
83
     * @param bool $merge
84
     *
85
     * @return \Psolr\Component\Highlight
86
     *
87
     * @see http://wiki.apache.org/solr/HighlightingParameters#hl.mergeContiguous
88
     */
89
    public function mergeContiguous($merge = true)
90
    {
91
        return $this->set('hl.mergeContiguous', $merge);
92
    }
93
94
    /**
95
     * @param bool $require
96
     *
97
     * @return \Psolr\Component\Highlight
98
     *
99
     * @see http://wiki.apache.org/solr/HighlightingParameters#hl.requireFieldMatch
100
     */
101
    public function requireFieldMatch($require = true)
102
    {
103
        return $this->set('hl.requireFieldMatch', $require);
104
    }
105
106
    /**
107
     * @param int $chars
108
     *
109
     * @return \Psolr\Component\Highlight
110
     *
111
     * @see http://wiki.apache.org/solr/HighlightingParameters#hl.maxAnalyzedChars
112
     */
113
    public function setMaxAnalyzedChars($chars)
114
    {
115
        return $this->set('hl.maxAnalyzedChars', $chars);
116
    }
117
118
    /**
119
     * @param string $field
120
     *
121
     * @return \Psolr\Component\Highlight
122
     *
123
     * @see http://wiki.apache.org/solr/HighlightingParameters#hl.alternateField
124
     */
125
    public function setAlternateField($field)
126
    {
127
        return $this->set('hl.alternateField', $field);
128
    }
129
130
    /**
131
     * @param int $length
132
     *
133
     * @return \Psolr\Component\Highlight
134
     *
135
     * @see http://wiki.apache.org/solr/HighlightingParameters#hl.maxAlternateFieldLength
136
     */
137
    public function setMaxAlternateFieldLength($length)
138
    {
139
        return $this->set('hl.maxAlternateFieldLength', $length);
140
    }
141
142
    /**
143
     * @param bool $preserve
144
     *
145
     * @return \Psolr\Component\Highlight
146
     *
147
     * @see http://wiki.apache.org/solr/HighlightingParameters#hl.preserveMulti
148
     */
149
    public function preserveMulti($preserve = true)
150
    {
151
        return $this->set('hl.preserveMulti', $preserve);
152
    }
153
154
    /**
155
     * @param int $max
156
     *
157
     * @return \Psolr\Component\Highlight
158
     *
159
     * @see http://wiki.apache.org/solr/HighlightingParameters#hl.maxMultiValuedToExamine
160
     */
161
    public function setMaxMultiValuedToExamine($max)
162
    {
163
        return $this->set('hl.maxMultiValuedToExamine', $max);
164
    }
165
166
    /**
167
     * @param int $max
168
     *
169
     * @return \Psolr\Component\Highlight
170
     *
171
     * @see http://wiki.apache.org/solr/HighlightingParameters#hl.maxMultiValuedToMatch
172
     */
173
    public function setMaxMultiValuedToMatch($max)
174
    {
175
        return $this->set('hl.maxMultiValuedToMatch', $max);
176
    }
177
178
    /**
179
     * @param string $formatter
180
     *
181
     * @return \Psolr\Component\Highlight
182
     *
183
     * @see http://wiki.apache.org/solr/HighlightingParameters#hl.formatter
184
     */
185
    public function setFormatter($formatter)
186
    {
187
        return $this->set('hl.formatter', $formatter);
188
    }
189
190
    /**
191
     * @param string $text
192
     *
193
     * @return \Psolr\Component\Highlight
194
     *
195
     * @see http://wiki.apache.org/solr/HighlightingParameters#hl.simple.pre.2Fhl.simple.post
196
     */
197
    public function setSimplePre($text)
198
    {
199
        return $this->set('hl.simple.pre', $text);
200
    }
201
202
    /**
203
     * @param string $text
204
     *
205
     * @return \Psolr\Component\Highlight
206
     *
207
     * @see http://wiki.apache.org/solr/HighlightingParameters#hl.simple.pre.2Fhl.simple.post
208
     */
209
    public function setSimplePost($text)
210
    {
211
        return $this->set('hl.simple.post', $text);
212
    }
213
214
    /**
215
     * Sets the html element used for highlighting, e.g. "em"
216
     *
217
     * @param string $element
218
     *
219
     * @return \Psolr\Component\Highlight
220
     *
221
     * @see \Psolr\Component\Highlight::setFormatter()
222
     * @see \Psolr\Component\Highlight::setSimplePre()
223
     * @see \Psolr\Component\Highlight::setSimplePost()
224
     */
225
    public function setHighlighterElement($element)
226
    {
227
        return $this
0 ignored issues
show
It seems like you code against a specific sub-type and not the parent class Guzzle\Common\Collection as the method setSimplePre() does only exist in the following sub-classes of Guzzle\Common\Collection: PSolr\Request\Highlight. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
228
            ->setFormatter(self::FORMATTER_SIMPLE)
229
            ->setSimplePre('<' . $element . '>')
230
            ->setSimplePost('</' . $element . '>')
231
        ;
232
    }
233
234
    /**
235
     * @param string $fragmenter
236
     *
237
     * @return \Psolr\Component\Highlight
238
     *
239
     * @see http://wiki.apache.org/solr/HighlightingParameters#hl.fragmenter
240
     */
241
    public function setFragmenter($fragmenter)
242
    {
243
        return $this->set('hl.fragmenter', $fragmenter);
244
    }
245
246
    /**
247
     * @param string $builder
248
     *
249
     * @return \Psolr\Component\Highlight
250
     *
251
     * @see http://wiki.apache.org/solr/HighlightingParameters#hl.fragListBuilder
252
     */
253
    public function setFragListBuilder($builder)
254
    {
255
        return $this->set('hl.fragListBuilder', $builder);
256
    }
257
258
    /**
259
     * @param string $scanner
260
     *
261
     * @return \Psolr\Component\Highlight
262
     *
263
     * @see http://wiki.apache.org/solr/HighlightingParameters#hl.boundaryScanner
264
     */
265
    public function setBoundaryScanner($scanner)
266
    {
267
        return $this->set('hl.boundaryScanner', $scanner);
268
    }
269
270
    /**
271
     * @param string $builder
272
     *
273
     * @return \Psolr\Component\Highlight
274
     *
275
     * @see http://wiki.apache.org/solr/HighlightingParameters#hl.fragmentsBuilder
276
     */
277
    public function setFragmentsBuilder($builder)
278
    {
279
        return $this->set('hl.fragmentsBuilder', $builder);
280
    }
281
282
    /**
283
     * @param int $maxScan
284
     *
285
     * @return \Psolr\Component\Highlight
286
     *
287
     * @see http://wiki.apache.org/solr/HighlightingParameters#hl.bs.maxScan
288
     */
289
    public function setBoundaryScannerMaxScan($maxScan)
290
    {
291
        return $this->set('hl.bs.maxScan', $maxScan);
292
    }
293
294
    /**
295
     * @param string $chars
296
     *
297
     * @return \Psolr\Component\Highlight
298
     *
299
     * @see http://wiki.apache.org/solr/HighlightingParameters#hl.bs.chars
300
     */
301
    public function setBoundaryScannerChars($chars)
302
    {
303
        return $this->set('hl.bs.chars', $chars);
304
    }
305
306
    /**
307
     * @param string $type
308
     *
309
     * @return \Psolr\Component\Highlight
310
     *
311
     * @see http://wiki.apache.org/solr/HighlightingParameters#hl.bs.type
312
     */
313
    public function setBoundaryScannerType($type)
314
    {
315
        return $this->set('hl.bs.type', $type);
316
    }
317
318
    /**
319
     * @param string $language
320
     *
321
     * @return \Psolr\Component\Highlight
322
     *
323
     * @see http://wiki.apache.org/solr/HighlightingParameters#hl.bs.language
324
     */
325
    public function setBoundaryScannerLanguage($language)
326
    {
327
        return $this->set('hl.bs.language', $language);
328
    }
329
330
    /**
331
     * @param string $country
332
     *
333
     * @return \Psolr\Component\Highlight
334
     *
335
     * @see http://wiki.apache.org/solr/HighlightingParameters#hl.bs.country
336
     */
337
    public function setBoundaryScannerCountry($country)
338
    {
339
        return $this->set('hl.bs.country', $country);
340
    }
341
342
    /**
343
     * @param bool $use
344
     *
345
     * @return \Psolr\Component\Highlight
346
     *
347
     * @see http://wiki.apache.org/solr/HighlightingParameters#hl.useFastVectorHighlighter
348
     */
349
    public function useFastVectorHighlighter($use = true)
350
    {
351
        return $this->set('hl.useFastVectorHighlighter', $use);
352
    }
353
354
    /**
355
     * @param bool $use
356
     *
357
     * @return \Psolr\Component\Highlight
358
     *
359
     * @see http://wiki.apache.org/solr/HighlightingParameters#hl.usePhraseHighlighter
360
     */
361
    public function usePhraseHighlighter($use = true)
362
    {
363
        return $this->set('hl.usePhraseHighlighter', $use);
364
    }
365
366
    /**
367
     * @param bool $multiTerm
368
     *
369
     * @return \Psolr\Component\Highlight
370
     *
371
     * @see http://wiki.apache.org/solr/HighlightingParameters#hl.highlightMultiTerm
372
     */
373
    public function highlightMultiTerm($multiTerm = true)
374
    {
375
        return $this->set('hl.highlightMultiTerm', $multiTerm);
376
    }
377
378
    /**
379
     * @param float $slop
380
     *
381
     * @return \Psolr\Component\Highlight
382
     *
383
     * @see http://wiki.apache.org/solr/HighlightingParameters#hl.regex.slop
384
     */
385
    public function setRegexSlop($slop)
386
    {
387
        return $this->set('hl.regex.slop', $slop);
388
    }
389
390
    /**
391
     * @param string $pattern
392
     *
393
     * @return \Psolr\Component\Highlight
394
     *
395
     * @see http://wiki.apache.org/solr/HighlightingParameters#hl.regex.pattern
396
     */
397
    public function setRegexPattern($pattern)
398
    {
399
        return $this->set('hl.regex.pattern', $pattern);
400
    }
401
402
    /**
403
     * @param int $max
404
     *
405
     * @return \Psolr\Component\Highlight
406
     *
407
     * @see http://wiki.apache.org/solr/HighlightingParameters#hl.regex.maxAnalyzedChars
408
     */
409
    public function setRegexMaxAnalyzedChars($max)
410
    {
411
        return $this->set('hl.regex.maxAnalyzedChars', $max);
412
    }
413
}
414