Completed
Pull Request — master (#324)
by Juliette
02:01
created

getFunctionCallParameters()   D

Complexity

Conditions 15
Paths 25

Size

Total Lines 83
Code Lines 45

Duplication

Lines 3
Ratio 3.61 %

Importance

Changes 0
Metric Value
dl 3
loc 83
rs 4.9121
c 0
b 0
f 0
cc 15
eloc 45
nc 25
nop 2

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * PHPCompatibility_Sniff.
4
 *
5
 * PHP version 5.6
6
 *
7
 * @category  PHP
8
 * @package   PHPCompatibility
9
 * @author    Wim Godden <[email protected]>
10
 * @copyright 2014 Cu.be Solutions bvba
11
 */
12
13
/**
14
 * PHPCompatibility_Sniff.
15
 *
16
 * @category  PHP
17
 * @package   PHPCompatibility
18
 * @author    Wim Godden <[email protected]>
19
 * @version   1.1.0
20
 * @copyright 2014 Cu.be Solutions bvba
21
 */
22
abstract class PHPCompatibility_Sniff implements PHP_CodeSniffer_Sniff
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...
23
{
24
25
    const REGEX_COMPLEX_VARS = '`(?:(\{)?(?<!\\\\)\$)?(\{)?(?<!\\\\)\$(\{)?(?P<varname>[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)(?:->\$?(?P>varname)|\[[^\]]+\]|::\$?(?P>varname)|\([^\)]*\))*(?(3)\}|)(?(2)\}|)(?(1)\}|)`';
26
27
    /**
28
     * List of functions using hash algorithm as parameter (always the first parameter).
29
     *
30
     * Used by the new/removed hash algorithm sniffs.
31
     * Key is the function name, value is the 1-based parameter position in the function call.
32
     *
33
     * @var array
34
     */
35
    protected $hashAlgoFunctions = array(
36
        'hash_file'      => 1,
37
        'hash_hmac_file' => 1,
38
        'hash_hmac'      => 1,
39
        'hash_init'      => 1,
40
        'hash_pbkdf2'    => 1,
41
        'hash'           => 1,
42
    );
43
44
45
    /**
46
     * List of functions which take an ini directive as parameter (always the first parameter).
47
     *
48
     * Used by the new/removed ini directives sniffs.
49
     * Key is the function name, value is the 1-based parameter position in the function call.
50
     *
51
     * @var array
52
     */
53
    protected $iniFunctions = array(
54
        'ini_get' => 1,
55
        'ini_set' => 1,
56
    );
57
58
59
/* The testVersion configuration variable may be in any of the following formats:
60
 * 1) Omitted/empty, in which case no version is specified.  This effectively
61
 *    disables all the checks provided by this standard.
62
 * 2) A single PHP version number, e.g. "5.4" in which case the standard checks that
63
 *    the code will run on that version of PHP (no deprecated features or newer
64
 *    features being used).
65
 * 3) A range, e.g. "5.0-5.5", in which case the standard checks the code will run
66
 *    on all PHP versions in that range, and that it doesn't use any features that
67
 *    were deprecated by the final version in the list, or which were not available
68
 *    for the first version in the list.
69
 * PHP version numbers should always be in Major.Minor format.  Both "5", "5.3.2"
70
 * would be treated as invalid, and ignored.
71
 * This standard doesn't support checking against PHP4, so the minimum version that
72
 * is recognised is "5.0".
73
 */
74
75
    private function getTestVersion()
76
    {
77
        /**
78
         * var $arrTestVersions will hold an array containing min/max version of PHP
79
         *   that we are checking against (see above).  If only a single version
80
         *   number is specified, then this is used as both the min and max.
81
         */
82
        static $arrTestVersions = array();
83
84
        $testVersion = trim(PHP_CodeSniffer::getConfigData('testVersion'));
85
86
        if (!isset($arrTestVersions[$testVersion]) && !empty($testVersion)) {
87
88
            $arrTestVersions[$testVersion] = array(null, null);
89
            if (preg_match('/^\d+\.\d+$/', $testVersion)) {
90
                $arrTestVersions[$testVersion] = array($testVersion, $testVersion);
91
            }
92
            elseif (preg_match('/^(\d+\.\d+)\s*-\s*(\d+\.\d+)$/', $testVersion,
93
                               $matches))
94
            {
95
                if (version_compare($matches[1], $matches[2], '>')) {
96
                    trigger_error("Invalid range in testVersion setting: '"
97
                                  . $testVersion . "'", E_USER_WARNING);
98
                }
99
                else {
100
                    $arrTestVersions[$testVersion] = array($matches[1], $matches[2]);
101
                }
102
            }
103
            elseif (!$testVersion == '') {
104
                trigger_error("Invalid testVersion setting: '" . $testVersion
105
                              . "'", E_USER_WARNING);
106
            }
107
        }
108
109
        if (isset($arrTestVersions[$testVersion])) {
110
            return $arrTestVersions[$testVersion];
111
        }
112
        else {
113
            return array(null, null);
114
        }
115
    }
116
117 View Code Duplication
    public function supportsAbove($phpVersion)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
118
    {
119
        $testVersion = $this->getTestVersion();
120
        $testVersion = $testVersion[1];
121
122
        if (is_null($testVersion)
123
            || version_compare($testVersion, $phpVersion) >= 0
124
        ) {
125
            return true;
126
        } else {
127
            return false;
128
        }
129
    }//end supportsAbove()
130
131 View Code Duplication
    public function supportsBelow($phpVersion)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
132
    {
133
        $testVersion = $this->getTestVersion();
134
        $testVersion = $testVersion[0];
135
136
        if (!is_null($testVersion)
137
            && version_compare($testVersion, $phpVersion) <= 0
138
        ) {
139
            return true;
140
        } else {
141
            return false;
142
        }
143
    }//end supportsBelow()
144
145
146
    /**
147
     * Add a PHPCS message to the output stack as either a warning or an error.
148
     *
149
     * @param PHP_CodeSniffer_File $phpcsFile The file the message applies to.
150
     * @param string               $message   The message.
151
     * @param int                  $stackPtr  The position of the token
152
     *                                        the message relates to.
153
     * @param bool                 $isError   Whether to report the message as an
154
     *                                        'error' or 'warning'.
155
     *                                        Defaults to true (error).
156
     * @param string               $code      The error code for the message.
157
     *                                        Defaults to 'Found'.
158
     * @param array                $data      Optional input for the data replacements.
159
     *
160
     * @return void
161
     */
162
    public function addMessage($phpcsFile, $message, $stackPtr, $isError, $code = 'Found', $data = array())
163
    {
164
        if ($isError === true) {
165
            $phpcsFile->addError($message, $stackPtr, $code, $data);
166
        } else {
167
            $phpcsFile->addWarning($message, $stackPtr, $code, $data);
168
        }
169
    }
170
171
172
    /**
173
     * Convert an arbitrary string to an alphanumeric string with underscores.
174
     *
175
     * Pre-empt issues with arbitrary strings being used as error codes in XML and PHP.
176
     *
177
     * @param string $baseString Arbitrary string.
178
     *
179
     * @return string
180
     */
181
    public function stringToErrorCode($baseString)
182
    {
183
        return preg_replace('`[^a-z0-9_]`i', '_', strtolower($baseString));
184
    }
185
186
187
    /**
188
     * Strip quotes surrounding an arbitrary string.
189
     *
190
     * Intended for use with the content of a T_CONSTANT_ENCAPSED_STRING / T_DOUBLE_QUOTED_STRING.
191
     *
192
     * @param string $string The raw string.
193
     *
194
     * @return string String without quotes around it.
195
     */
196
    public function stripQuotes($string) {
197
        return preg_replace('`^([\'"])(.*)\1$`Ds', '$2', $string);
198
    }
199
200
201
    /**
202
     * Strip variables from an arbitrary double quoted string.
203
     *
204
     * Intended for use with the content of a T_DOUBLE_QUOTED_STRING.
205
     *
206
     * @param string $string The raw string.
207
     *
208
     * @return string String without variables in it.
209
     */
210
    public function stripVariables($string) {
211
        if (strpos($string, '$') === false) {
212
            return $string;
213
        }
214
215
        return preg_replace( self::REGEX_COMPLEX_VARS, '', $string );
216
    }
217
218
219
    /**
220
     * Make all top level array keys in an array lowercase.
221
     *
222
     * @param array $array Initial array.
223
     *
224
     * @return array Same array, but with all lowercase top level keys.
225
     */
226
    public function arrayKeysToLowercase($array)
227
    {
228
        $keys = array_keys($array);
229
        $keys = array_map('strtolower', $keys);
230
        return array_combine($keys, $array);
231
    }
232
233
234
    /**
235
     * Returns the name(s) of the interface(s) that the specified class implements.
236
     *
237
     * Returns FALSE on error or if there are no implemented interface names.
238
     *
239
     * {@internal Duplicate of same method as introduced in PHPCS 2.7.
240
     * Once the minimum supported PHPCS version for this sniff library goes beyond
241
     * that, this method can be removed and call to it replaced with
242
     * `$phpcsFile->findImplementedInterfaceNames($stackPtr)` calls.}}
243
     *
244
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
245
     * @param int                  $stackPtr  The position of the class token.
246
     *
247
     * @return array|false
248
     */
249
    public function findImplementedInterfaceNames(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
250
    {
251
        if (method_exists($phpcsFile, 'findImplementedInterfaceNames')) {
252
            return $phpcsFile->findImplementedInterfaceNames($stackPtr);
253
        }
254
255
        $tokens = $phpcsFile->getTokens();
256
257
        // Check for the existence of the token.
258
        if (isset($tokens[$stackPtr]) === false) {
259
            return false;
260
        }
261
262
        if ($tokens[$stackPtr]['code'] !== T_CLASS) {
263
            return false;
264
        }
265
266
        if (isset($tokens[$stackPtr]['scope_closer']) === false) {
267
            return false;
268
        }
269
270
        $classOpenerIndex = $tokens[$stackPtr]['scope_opener'];
271
        $implementsIndex  = $phpcsFile->findNext(T_IMPLEMENTS, $stackPtr, $classOpenerIndex);
272
        if ($implementsIndex === false) {
273
            return false;
274
        }
275
276
        $find = array(
277
                 T_NS_SEPARATOR,
278
                 T_STRING,
279
                 T_WHITESPACE,
280
                 T_COMMA,
281
                );
282
283
        $end  = $phpcsFile->findNext($find, ($implementsIndex + 1), ($classOpenerIndex + 1), true);
284
        $name = $phpcsFile->getTokensAsString(($implementsIndex + 1), ($end - $implementsIndex - 1));
285
        $name = trim($name);
286
287
        if ($name === '') {
288
            return false;
289
        } else {
290
            $names = explode(',', $name);
291
            $names = array_map('trim', $names);
292
            return $names;
293
        }
294
295
    }//end findImplementedInterfaceNames()
296
297
298
    /**
299
     * Checks if a function call has parameters.
300
     *
301
     * Expects to be passed the T_STRING stack pointer for the function call.
302
     * If passed a T_STRING which is *not* a function call, the behaviour is unreliable.
303
     *
304
     * Extra feature: If passed an T_ARRAY or T_OPEN_SHORT_ARRAY stack pointer, it
305
     * will detect whether the array has values or is empty.
306
     *
307
     * @link https://github.com/wimg/PHPCompatibility/issues/120
308
     * @link https://github.com/wimg/PHPCompatibility/issues/152
309
     *
310
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
311
     * @param int                  $stackPtr  The position of the function call token.
312
     *
313
     * @return bool
314
     */
315
    public function doesFunctionCallHaveParameters(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
316
    {
317
        $tokens = $phpcsFile->getTokens();
318
319
        // Check for the existence of the token.
320
        if (isset($tokens[$stackPtr]) === false) {
321
            return false;
322
        }
323
324
        // Is this one of the tokens this function handles ?
325
        if (in_array($tokens[$stackPtr]['code'], array(T_STRING, T_ARRAY, T_OPEN_SHORT_ARRAY), true) === false) {
326
            return false;
327
        }
328
329
        $nextNonEmpty = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true);
330
331
        // Deal with short array syntax.
332
        if ($tokens[$stackPtr]['code'] === T_OPEN_SHORT_ARRAY) {
333
            if (isset($tokens[$stackPtr]['bracket_closer']) === false) {
334
                return false;
335
            }
336
337
            if ($nextNonEmpty === $tokens[$stackPtr]['bracket_closer']) {
338
                // No parameters.
339
                return false;
340
            }
341
            else {
342
                return true;
343
            }
344
        }
345
346
        // Deal with function calls & long arrays.
347
        // Next non-empty token should be the open parenthesis.
348
        if ($nextNonEmpty === false && $tokens[$nextNonEmpty]['code'] !== T_OPEN_PARENTHESIS) {
349
            return false;
350
        }
351
352
        if (isset($tokens[$nextNonEmpty]['parenthesis_closer']) === false) {
353
            return false;
354
        }
355
356
        $closeParenthesis = $tokens[$nextNonEmpty]['parenthesis_closer'];
357
        $nextNextNonEmpty = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $nextNonEmpty + 1, $closeParenthesis + 1, true);
358
359
        if ($nextNextNonEmpty === $closeParenthesis) {
360
            // No parameters.
361
            return false;
362
        }
363
364
        return true;
365
    }
366
367
368
    /**
369
     * Count the number of parameters a function call has been passed.
370
     *
371
     * Expects to be passed the T_STRING stack pointer for the function call.
372
     * If passed a T_STRING which is *not* a function call, the behaviour is unreliable.
373
     *
374
     * Extra feature: If passed an T_ARRAY or T_OPEN_SHORT_ARRAY stack pointer,
375
     * it will return the number of values in the array.
376
     *
377
     * @link https://github.com/wimg/PHPCompatibility/issues/111
378
     * @link https://github.com/wimg/PHPCompatibility/issues/114
379
     * @link https://github.com/wimg/PHPCompatibility/issues/151
380
     *
381
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
382
     * @param int                  $stackPtr  The position of the function call token.
383
     *
384
     * @return int
385
     */
386
    public function getFunctionCallParameterCount(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
387
    {
388
        if ($this->doesFunctionCallHaveParameters($phpcsFile, $stackPtr) === false) {
389
            return 0;
390
        }
391
392
        return count($this->getFunctionCallParameters($phpcsFile, $stackPtr));
393
    }
394
395
396
    /**
397
     * Get information on all parameters passed to a function call.
398
     *
399
     * Expects to be passed the T_STRING stack pointer for the function call.
400
     * If passed a T_STRING which is *not* a function call, the behaviour is unreliable.
401
     *
402
     * Will return an multi-dimentional array with the start token pointer, end token
403
     * pointer and raw parameter value for all parameters. Index will be 1-based.
404
     * If no parameters are found, will return an empty array.
405
     *
406
     * Extra feature: If passed an T_ARRAY or T_OPEN_SHORT_ARRAY stack pointer,
407
     * it will tokenize the values / key/value pairs contained in the array call.
408
     *
409
     * @param PHP_CodeSniffer_File $phpcsFile     The file being scanned.
410
     * @param int                  $stackPtr      The position of the function call token.
411
     *
412
     * @return array
413
     */
414
    public function getFunctionCallParameters(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
415
    {
416
        if ($this->doesFunctionCallHaveParameters($phpcsFile, $stackPtr) === false) {
417
            return array();
418
        }
419
420
        // Ok, we know we have a T_STRING, T_ARRAY or T_OPEN_SHORT_ARRAY with parameters
421
        // and valid open & close brackets/parenthesis.
422
        $tokens = $phpcsFile->getTokens();
423
424
        // Mark the beginning and end tokens.
425
        if ($tokens[$stackPtr]['code'] === T_OPEN_SHORT_ARRAY) {
426
            $opener = $stackPtr;
427
            $closer = $tokens[$stackPtr]['bracket_closer'];
428
429
            $nestedParenthesisCount = 0;
430
        }
431
        else {
432
            $opener = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true);
433
            $closer = $tokens[$opener]['parenthesis_closer'];
434
435
            $nestedParenthesisCount = 1;
436
        }
437
438
        // Which nesting level is the one we are interested in ?
439 View Code Duplication
        if (isset($tokens[$opener]['nested_parenthesis'])) {
1 ignored issue
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...
440
            $nestedParenthesisCount += count($tokens[$opener]['nested_parenthesis']);
441
        }
442
443
        $parameters = array();
444
        $nextComma  = $opener;
445
        $paramStart = $opener + 1;
446
        $cnt        = 1;
447
        while ($nextComma = $phpcsFile->findNext(array(T_COMMA, $tokens[$closer]['code'], T_OPEN_SHORT_ARRAY), $nextComma + 1, $closer + 1)) {
448
            // Ignore anything within short array definition brackets.
449
            if (
450
                $tokens[$nextComma]['type'] === 'T_OPEN_SHORT_ARRAY'
451
                &&
452
                ( isset($tokens[$nextComma]['bracket_opener']) && $tokens[$nextComma]['bracket_opener'] === $nextComma )
453
                &&
454
                isset($tokens[$nextComma]['bracket_closer'])
455
            ) {
456
                // Skip forward to the end of the short array definition.
457
                $nextComma = $tokens[$nextComma]['bracket_closer'];
458
                continue;
459
            }
460
461
            // Ignore comma's at a lower nesting level.
462
            if (
463
                $tokens[$nextComma]['type'] === 'T_COMMA'
464
                &&
465
                isset($tokens[$nextComma]['nested_parenthesis'])
466
                &&
467
                count($tokens[$nextComma]['nested_parenthesis']) !== $nestedParenthesisCount
468
            ) {
469
                continue;
470
            }
471
472
            // Ignore closing parenthesis/bracket if not 'ours'.
473
            if ($tokens[$nextComma]['type'] === $tokens[$closer]['type'] && $nextComma !== $closer) {
474
                continue;
475
            }
476
477
            // Ok, we've reached the end of the parameter.
478
            $parameters[$cnt]['start'] = $paramStart;
479
            $parameters[$cnt]['end']   = $nextComma - 1;
480
            $parameters[$cnt]['raw']   = trim($phpcsFile->getTokensAsString($paramStart, ($nextComma - $paramStart)));
481
482
            // Check if there are more tokens before the closing parenthesis.
483
            // Prevents code like the following from setting a third parameter:
484
            // functionCall( $param1, $param2, );
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
485
            $hasNextParam = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $nextComma + 1, $closer, true, null, true);
486
            if ($hasNextParam === false) {
487
                break;
488
            }
489
490
            // Prepare for the next parameter.
491
            $paramStart = $nextComma + 1;
492
            $cnt++;
493
        }
494
495
        return $parameters;
496
    }
497
498
499
    /**
500
     * Get information on a specific parameter passed to a function call.
501
     *
502
     * Expects to be passed the T_STRING stack pointer for the function call.
503
     * If passed a T_STRING which is *not* a function call, the behaviour is unreliable.
504
     *
505
     * Will return a array with the start token pointer, end token pointer and the raw value
506
     * of the parameter at a specific offset.
507
     * If the specified parameter is not found, will return false.
508
     *
509
     * @param PHP_CodeSniffer_File $phpcsFile   The file being scanned.
510
     * @param int                  $stackPtr    The position of the function call token.
511
     * @param int                  $paramOffset The 1-based index position of the parameter to retrieve.
512
     *
513
     * @return array|false
514
     */
515
    public function getFunctionCallParameter(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $paramOffset)
516
    {
517
        $parameters = $this->getFunctionCallParameters($phpcsFile, $stackPtr);
518
519
        if (isset($parameters[$paramOffset]) === false) {
520
            return false;
521
        }
522
        else {
523
            return $parameters[$paramOffset];
524
        }
525
    }
526
527
528
    /**
529
     * Verify whether a token is within a scoped condition.
530
     *
531
     * If the optional $validScopes parameter has been passed, the function
532
     * will check that the token has at least one condition which is of a
533
     * type defined in $validScopes.
534
     *
535
     * @param PHP_CodeSniffer_File $phpcsFile   The file being scanned.
536
     * @param int                  $stackPtr    The position of the token.
537
     * @param array|int            $validScopes Optional. Array of valid scopes
538
     *                                          or int value of a valid scope.
539
     *                                          Pass the T_.. constant(s) for the
540
     *                                          desired scope to this parameter.
541
     *
542
     * @return bool Without the optional $scopeTypes: True if within a scope, false otherwise.
543
     *              If the $scopeTypes are set: True if *one* of the conditions is a
544
     *              valid scope, false otherwise.
545
     */
546
    public function tokenHasScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $validScopes = null)
547
    {
548
        $tokens = $phpcsFile->getTokens();
549
550
        // Check for the existence of the token.
551
        if (isset($tokens[$stackPtr]) === false) {
552
            return false;
553
        }
554
555
        // No conditions = no scope.
556
        if (empty($tokens[$stackPtr]['conditions'])) {
557
            return false;
558
        }
559
560
        // Ok, there are conditions, do we have to check for specific ones ?
561
        if (isset($validScopes) === false) {
562
            return true;
563
        }
564
565
        if (is_int($validScopes)) {
566
            // Received an integer, so cast to array.
567
            $validScopes = (array) $validScopes;
568
        }
569
570
        if (empty($validScopes) || is_array($validScopes) === false) {
571
            // No valid scope types received, so will not comply.
572
            return false;
573
        }
574
575
        // Check for required scope types.
576
        foreach ($tokens[$stackPtr]['conditions'] as $pointer => $tokenCode) {
577
            if (in_array($tokenCode, $validScopes, true)) {
578
                return true;
579
            }
580
        }
581
582
        return false;
583
    }
584
585
586
    /**
587
     * Verify whether a token is within a class scope.
588
     *
589
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
590
     * @param int                  $stackPtr  The position of the token.
591
     * @param bool                 $strict    Whether to strictly check for the T_CLASS
592
     *                                        scope or also accept interfaces and traits
593
     *                                        as scope.
594
     *
595
     * @return bool True if within class scope, false otherwise.
596
     */
597
    public function inClassScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $strict = true)
598
    {
599
        $validScopes = array(T_CLASS);
600
        if ($strict === false) {
601
            $validScopes[] = T_INTERFACE;
602
            $validScopes[] = T_TRAIT;
603
        }
604
605
        return $this->tokenHasScope($phpcsFile, $stackPtr, $validScopes);
606
    }
607
608
609
    /**
610
     * Verify whether a token is within a scoped use statement.
611
     *
612
     * PHPCS cross-version compatibility method.
613
     *
614
     * In PHPCS 1.x no conditions are set for a scoped use statement.
615
     * This method works around that limitation.
616
     *
617
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
618
     * @param int                  $stackPtr  The position of the token.
619
     *
620
     * @return bool True if within use scope, false otherwise.
621
     */
622
    public function inUseScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
623
    {
624
        static $isLowPHPCS, $ignoreTokens;
625
626
        if (isset($isLowPHPCS) === false) {
627
            $isLowPHPCS = version_compare(PHP_CodeSniffer::VERSION, '2.0', '<');
628
        }
629
        if (isset($ignoreTokens) === false) {
630
            $ignoreTokens              = PHP_CodeSniffer_Tokens::$emptyTokens;
631
            $ignoreTokens[T_STRING]    = T_STRING;
632
            $ignoreTokens[T_AS]        = T_AS;
633
            $ignoreTokens[T_PUBLIC]    = T_PUBLIC;
634
            $ignoreTokens[T_PROTECTED] = T_PROTECTED;
635
            $ignoreTokens[T_PRIVATE]   = T_PRIVATE;
636
        }
637
638
        // PHPCS 2.0.
639
        if ($isLowPHPCS === false) {
640
            return $this->tokenHasScope($phpcsFile, $stackPtr, T_USE);
641
        } else {
642
            // PHPCS 1.x.
643
            $tokens         = $phpcsFile->getTokens();
644
            $maybeCurlyOpen = $phpcsFile->findPrevious($ignoreTokens, ($stackPtr - 1), null, true);
645
            if ($tokens[$maybeCurlyOpen]['code'] === T_OPEN_CURLY_BRACKET) {
646
                $maybeUseStatement = $phpcsFile->findPrevious($ignoreTokens, ($maybeCurlyOpen - 1), null, true);
647
                if ($tokens[$maybeUseStatement]['code'] === T_USE) {
648
                    return true;
649
                }
650
            }
651
            return false;
652
        }
653
    }
654
655
656
    /**
657
     * Returns the fully qualified class name for a new class instantiation.
658
     *
659
     * Returns an empty string if the class name could not be reliably inferred.
660
     *
661
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
662
     * @param int                  $stackPtr  The position of a T_NEW token.
663
     *
664
     * @return string
665
     */
666
    public function getFQClassNameFromNewToken(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
667
    {
668
        $tokens = $phpcsFile->getTokens();
669
670
        // Check for the existence of the token.
671
        if (isset($tokens[$stackPtr]) === false) {
672
            return '';
673
        }
674
675
        if ($tokens[$stackPtr]['code'] !== T_NEW) {
676
            return '';
677
        }
678
679
        $find = array(
680
                 T_NS_SEPARATOR,
681
                 T_STRING,
682
                 T_NAMESPACE,
683
                 T_WHITESPACE,
684
                );
685
686
        $start = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true);
687
        // Bow out if the next token is a variable as we don't know where it was defined.
688
        if ($tokens[$start]['code'] === T_VARIABLE) {
689
            return '';
690
        }
691
692
        $end       = $phpcsFile->findNext($find, ($start + 1), null, true, null, true);
693
        $className = $phpcsFile->getTokensAsString($start, ($end - $start));
694
        $className = trim($className);
695
696
        return $this->getFQName($phpcsFile, $stackPtr, $className);
697
    }
698
699
700
    /**
701
     * Returns the fully qualified name of the class that the specified class extends.
702
     *
703
     * Returns an empty string if the class does not extend another class or if
704
     * the class name could not be reliably inferred.
705
     *
706
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
707
     * @param int                  $stackPtr  The position of a T_CLASS token.
708
     *
709
     * @return string
710
     */
711
    public function getFQExtendedClassName(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
712
    {
713
        $tokens = $phpcsFile->getTokens();
714
715
        // Check for the existence of the token.
716
        if (isset($tokens[$stackPtr]) === false) {
717
            return '';
718
        }
719
720
        if ($tokens[$stackPtr]['code'] !== T_CLASS) {
721
            return '';
722
        }
723
724
        $extends = $phpcsFile->findExtendedClassName($stackPtr);
725
        if (empty($extends) || is_string($extends) === false) {
726
            return '';
727
        }
728
729
        return $this->getFQName($phpcsFile, $stackPtr, $extends);
730
    }
731
732
733
    /**
734
     * Returns the class name for the static usage of a class.
735
     * This can be a call to a method, the use of a property or constant.
736
     *
737
     * Returns an empty string if the class name could not be reliably inferred.
738
     *
739
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
740
     * @param int                  $stackPtr  The position of a T_NEW token.
741
     *
742
     * @return string
743
     */
744
    public function getFQClassNameFromDoubleColonToken(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
745
    {
746
        $tokens = $phpcsFile->getTokens();
747
748
        // Check for the existence of the token.
749
        if (isset($tokens[$stackPtr]) === false) {
750
            return '';
751
        }
752
753
        if ($tokens[$stackPtr]['code'] !== T_DOUBLE_COLON) {
754
            return '';
755
        }
756
757
        // Nothing to do if previous token is a variable as we don't know where it was defined.
758
        if ($tokens[$stackPtr - 1]['code'] === T_VARIABLE) {
759
            return '';
760
        }
761
762
        // Nothing to do if 'parent' or 'static' as we don't know how far the class tree extends.
763
        if (in_array($tokens[$stackPtr - 1]['code'], array(T_PARENT, T_STATIC), true)) {
764
            return '';
765
        }
766
767
        // Get the classname from the class declaration if self is used.
768
        if ($tokens[$stackPtr - 1]['code'] === T_SELF) {
769
            $classDeclarationPtr = $phpcsFile->findPrevious(T_CLASS, $stackPtr - 1);
770
            if ($classDeclarationPtr === false) {
771
                return '';
772
            }
773
            $className = $phpcsFile->getDeclarationName($classDeclarationPtr);
774
            return $this->getFQName($phpcsFile, $classDeclarationPtr, $className);
775
        }
776
777
        $find = array(
778
                 T_NS_SEPARATOR,
779
                 T_STRING,
780
                 T_NAMESPACE,
781
                 T_WHITESPACE,
782
                );
783
784
        $start     = ($phpcsFile->findPrevious($find, $stackPtr - 1, null, true, null, true) + 1);
785
        $className = $phpcsFile->getTokensAsString($start, ($stackPtr - $start));
786
        $className = trim($className);
787
788
        return $this->getFQName($phpcsFile, $stackPtr, $className);
789
    }
790
791
792
    /**
793
     * Get the Fully Qualified name for a class/function/constant etc.
794
     *
795
     * Checks if a class/function/constant name is already fully qualified and
796
     * if not, enrich it with the relevant namespace information.
797
     *
798
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
799
     * @param int                  $stackPtr  The position of the token.
800
     * @param string               $name      The class / function / constant name.
801
     *
802
     * @return string
803
     */
804
    public function getFQName(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $name)
805
    {
806
        if (strpos($name, '\\' ) === 0) {
807
            // Already fully qualified.
808
            return $name;
809
        }
810
811
        // Remove the namespace keyword if used.
812
        if (strpos($name, 'namespace\\') === 0) {
813
            $name = substr($name, 10);
814
        }
815
816
        $namespace = $this->determineNamespace($phpcsFile, $stackPtr);
817
818
        if ($namespace === '') {
819
            return '\\' . $name;
820
        }
821
        else {
822
            return '\\' . $namespace . '\\' . $name;
823
        }
824
    }
825
826
827
    /**
828
     * Is the class/function/constant name namespaced or global ?
829
     *
830
     * @param string $FQName Fully Qualified name of a class, function etc.
831
     *                       I.e. should always start with a `\` !
832
     *
833
     * @return bool True if namespaced, false if global.
834
     */
835
    public function isNamespaced($FQName) {
836
        if (strpos($FQName, '\\') !== 0) {
837
            throw new PHP_CodeSniffer_Exception('$FQName must be a fully qualified name');
838
        }
839
840
        return (strpos(substr($FQName, 1), '\\') !== false);
841
    }
842
843
844
    /**
845
     * Determine the namespace name an arbitrary token lives in.
846
     *
847
     * @param PHP_CodeSniffer_File $phpcsFile Instance of phpcsFile.
848
     * @param int                  $stackPtr  The token position for which to determine the namespace.
849
     *
850
     * @return string Namespace name or empty string if it couldn't be determined or no namespace applies.
851
     */
852
    public function determineNamespace(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
853
    {
854
        $tokens = $phpcsFile->getTokens();
855
856
        // Check for the existence of the token.
857
        if (isset($tokens[$stackPtr]) === false) {
858
            return '';
859
        }
860
861
        // Check for scoped namespace {}.
862
        if (empty($tokens[$stackPtr]['conditions']) === false) {
863
            foreach ($tokens[$stackPtr]['conditions'] as $pointer => $type) {
864
                if ($type === T_NAMESPACE) {
865
                    $namespace = $this->getDeclaredNamespaceName($phpcsFile, $pointer);
866
                    if ($namespace !== false) {
867
                        return $namespace;
868
                    }
869
                    break; // Nested namespaces is not possible.
870
                }
871
            }
872
        }
873
874
        /*
875
         * Not in a scoped namespace, so let's see if we can find a non-scoped namespace instead.
876
         * Keeping in mind that:
877
         * - there can be multiple non-scoped namespaces in a file (bad practice, but it happens).
878
         * - the namespace keyword can also be used as part of a function/method call and such.
879
         * - that a non-named namespace resolves to the global namespace.
880
         */
881
        $previousNSToken = $stackPtr;
882
        $namespace       = false;
883
        do {
884
            $previousNSToken = $phpcsFile->findPrevious(T_NAMESPACE, $previousNSToken -1);
885
886
            // Stop if we encounter a scoped namespace declaration as we already know we're not in one.
887
            if (empty($tokens[$previousNSToken]['scope_condition']) === false && $tokens[$previousNSToken]['scope_condition'] = $previousNSToken) {
888
                break;
889
            }
890
            $namespace = $this->getDeclaredNamespaceName($phpcsFile, $previousNSToken);
891
892
        } while ($namespace === false && $previousNSToken !== false);
893
894
        // If we still haven't got a namespace, return an empty string.
895
        if ($namespace === false) {
896
            return '';
897
        }
898
        else {
899
            return $namespace;
900
        }
901
    }
902
903
    /**
904
     * Get the complete namespace name for a namespace declaration.
905
     *
906
     * For hierarchical namespaces, the name will be composed of several tokens,
907
     * i.e. MyProject\Sub\Level which will be returned together as one string.
908
     *
909
     * @param PHP_CodeSniffer_File $phpcsFile Instance of phpcsFile.
910
     * @param int|bool             $stackPtr  The position of a T_NAMESPACE token.
911
     *
912
     * @return string|false Namespace name or false if not a namespace declaration.
913
     *                      Namespace name can be an empty string for global namespace declaration.
914
     */
915
    public function getDeclaredNamespaceName(PHP_CodeSniffer_File $phpcsFile, $stackPtr )
916
    {
917
        $tokens = $phpcsFile->getTokens();
918
919
        // Check for the existence of the token.
920
        if ($stackPtr === false || isset($tokens[$stackPtr]) === false) {
921
            return false;
922
        }
923
924
        if ($tokens[$stackPtr]['code'] !== T_NAMESPACE) {
925
            return false;
926
        }
927
928
        if ($tokens[$stackPtr + 1]['code'] === T_NS_SEPARATOR) {
929
            // Not a namespace declaration, but use of, i.e. namespace\someFunction();
930
            return false;
931
        }
932
933
        $nextToken = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true);
934
        if ($tokens[$nextToken]['code'] === T_OPEN_CURLY_BRACKET) {
935
            // Declaration for global namespace when using multiple namespaces in a file.
936
            // I.e.: namespace {}
937
            return '';
938
        }
939
940
        // Ok, this should be a namespace declaration, so get all the parts together.
941
        $validTokens = array(
942
                        T_STRING,
943
                        T_NS_SEPARATOR,
944
                        T_WHITESPACE,
945
                       );
946
947
        $namespaceName = '';
948
        while(in_array($tokens[$nextToken]['code'], $validTokens, true) === true) {
949
            $namespaceName .= trim($tokens[$nextToken]['content']);
950
            $nextToken++;
951
        }
952
953
        return $namespaceName;
954
    }
955
956
957
    /**
958
     * Returns the method parameters for the specified T_FUNCTION token.
959
     *
960
     * Each parameter is in the following format:
961
     *
962
     * <code>
963
     *   0 => array(
964
     *         'name'              => '$var',  // The variable name.
965
     *         'pass_by_reference' => false,   // Passed by reference.
966
     *         'type_hint'         => string,  // Type hint for array or custom type
967
     *         'nullable_type'     => bool,    // Whether the type given in the type hint is nullable
968
     *         'type_hint'         => string,  // Type hint for array or custom type
969
     *         'raw'               => string,  // Raw content of the tokens for the parameter
970
     *        )
971
     * </code>
972
     *
973
     * Parameters with default values have an additional array index of
974
     * 'default' with the value of the default as a string.
975
     *
976
     * {@internal Duplicate of same method as contained in the `PHP_CodeSniffer_File`
977
     * class, but with some improvements which will probably be introduced in
978
     * PHPCS 2.7.1/2.8. {@see https://github.com/squizlabs/PHP_CodeSniffer/pull/1117}
979
     * and {@see https://github.com/squizlabs/PHP_CodeSniffer/pull/1193}
980
     *
981
     * Once the minimum supported PHPCS version for this sniff library goes beyond
982
     * that, this method can be removed and calls to it replaced with
983
     * `$phpcsFile->getMethodParameters($stackPtr)` calls.
984
     *
985
     * Last synced with PHPCS version: PHPCS 2.7.}}
986
     *
987
     * @param PHP_CodeSniffer_File $phpcsFile Instance of phpcsFile.
988
     * @param int                  $stackPtr  The position in the stack of the
989
     *                                        T_FUNCTION token to acquire the
990
     *                                        parameters for.
991
     *
992
     * @return array|false
993
     * @throws PHP_CodeSniffer_Exception If the specified $stackPtr is not of
994
     *                                   type T_FUNCTION.
995
     */
996
    public function getMethodParameters(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
997
    {
998
        $tokens = $phpcsFile->getTokens();
999
1000
        // Check for the existence of the token.
1001
        if (isset($tokens[$stackPtr]) === false) {
1002
            return false;
1003
        }
1004
1005
        if ($tokens[$stackPtr]['code'] !== T_FUNCTION) {
1006
            throw new PHP_CodeSniffer_Exception('$stackPtr must be of type T_FUNCTION');
1007
        }
1008
1009
        $opener = $tokens[$stackPtr]['parenthesis_opener'];
1010
        $closer = $tokens[$stackPtr]['parenthesis_closer'];
1011
1012
        $vars            = array();
1013
        $currVar         = null;
1014
        $paramStart      = ($opener + 1);
1015
        $defaultStart    = null;
1016
        $paramCount      = 0;
1017
        $passByReference = false;
1018
        $variableLength  = false;
1019
        $typeHint        = '';
1020
        $nullableType    = false;
1021
1022
        for ($i = $paramStart; $i <= $closer; $i++) {
1023
            // Check to see if this token has a parenthesis or bracket opener. If it does
1024
            // it's likely to be an array which might have arguments in it. This
1025
            // could cause problems in our parsing below, so lets just skip to the
1026
            // end of it.
1027 View Code Duplication
            if (isset($tokens[$i]['parenthesis_opener']) === true) {
1 ignored issue
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...
1028
                // Don't do this if it's the close parenthesis for the method.
1029
                if ($i !== $tokens[$i]['parenthesis_closer']) {
1030
                    $i = ($tokens[$i]['parenthesis_closer'] + 1);
1031
                }
1032
            }
1033
1034 View Code Duplication
            if (isset($tokens[$i]['bracket_opener']) === true) {
1 ignored issue
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...
1035
                // Don't do this if it's the close parenthesis for the method.
1036
                if ($i !== $tokens[$i]['bracket_closer']) {
1037
                    $i = ($tokens[$i]['bracket_closer'] + 1);
1038
                }
1039
            }
1040
1041
            switch ($tokens[$i]['code']) {
1042
            case T_BITWISE_AND:
1043
                $passByReference = true;
1044
                break;
1045
            case T_VARIABLE:
1046
                $currVar = $i;
1047
                break;
1048
            case T_ELLIPSIS:
1049
                $variableLength = true;
1050
                break;
1051
            case T_ARRAY_HINT:
1052
            case T_CALLABLE:
1053
                $typeHint = $tokens[$i]['content'];
1054
                break;
1055
            case T_SELF:
1056
            case T_PARENT:
1057 View Code Duplication
            case T_STATIC:
1 ignored issue
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...
1058
                // Self is valid, the others invalid, but were probably intended as type hints.
1059
                if ($defaultStart === null) {
1060
                    $typeHint = $tokens[$i]['content'];
1061
                }
1062
                break;
1063
            case T_STRING:
1064
                // This is a string, so it may be a type hint, but it could
1065
                // also be a constant used as a default value.
1066
                $prevComma = false;
1067 View Code Duplication
                for ($t = $i; $t >= $opener; $t--) {
1 ignored issue
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...
1068
                    if ($tokens[$t]['code'] === T_COMMA) {
1069
                        $prevComma = $t;
1070
                        break;
1071
                    }
1072
                }
1073
1074
                if ($prevComma !== false) {
1075
                    $nextEquals = false;
1076 View Code Duplication
                    for ($t = $prevComma; $t < $i; $t++) {
1 ignored issue
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...
1077
                        if ($tokens[$t]['code'] === T_EQUAL) {
1078
                            $nextEquals = $t;
1079
                            break;
1080
                        }
1081
                    }
1082
1083
                    if ($nextEquals !== false) {
1084
                        break;
1085
                    }
1086
                }
1087
1088
                if ($defaultStart === null) {
1089
                    $typeHint .= $tokens[$i]['content'];
1090
                }
1091
                break;
1092 View Code Duplication
            case T_NS_SEPARATOR:
1 ignored issue
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...
1093
                // Part of a type hint or default value.
1094
                if ($defaultStart === null) {
1095
                    $typeHint .= $tokens[$i]['content'];
1096
                }
1097
                break;
1098
            case T_INLINE_THEN:
1099
                if ($defaultStart === null) {
1100
                    $nullableType = true;
1101
                    $typeHint    .= $tokens[$i]['content'];
1102
                }
1103
                break;
1104
            case T_CLOSE_PARENTHESIS:
1105
            case T_COMMA:
1106
                // If it's null, then there must be no parameters for this
1107
                // method.
1108
                if ($currVar === null) {
1109
                    continue;
1110
                }
1111
1112
                $vars[$paramCount]         = array();
1113
                $vars[$paramCount]['name'] = $tokens[$currVar]['content'];
1114
1115
                if ($defaultStart !== null) {
1116
                    $vars[$paramCount]['default']
1117
                        = $phpcsFile->getTokensAsString(
1118
                            $defaultStart,
1119
                            ($i - $defaultStart)
1120
                        );
1121
                }
1122
1123
                $rawContent = trim($phpcsFile->getTokensAsString($paramStart, ($i - $paramStart)));
1124
1125
                $vars[$paramCount]['pass_by_reference'] = $passByReference;
1126
                $vars[$paramCount]['variable_length']   = $variableLength;
1127
                $vars[$paramCount]['type_hint']         = $typeHint;
1128
                $vars[$paramCount]['nullable_type']     = $nullableType;
1129
                $vars[$paramCount]['raw']               = $rawContent;
1130
1131
                // Reset the vars, as we are about to process the next parameter.
1132
                $defaultStart    = null;
1133
                $paramStart      = ($i + 1);
1134
                $passByReference = false;
1135
                $variableLength  = false;
1136
                $typeHint        = '';
1137
                $nullableType    = false;
1138
1139
                $paramCount++;
1140
                break;
1141
            case T_EQUAL:
1142
                $defaultStart = ($i + 1);
1143
                break;
1144
            }//end switch
1145
        }//end for
1146
1147
        return $vars;
1148
1149
    }//end getMethodParameters()
1150
1151
1152
    /**
1153
     * Get the hash algorithm name from the parameter in a hash function call.
1154
     *
1155
     * @param PHP_CodeSniffer_File $phpcsFile Instance of phpcsFile.
1156
     * @param int                  $stackPtr  The position of the T_STRING function token.
1157
     *
1158
     * @return string|false The algorithm name without quotes if this was a relevant hash
1159
     *                      function call or false if it was not.
1160
     */
1161
    public function getHashAlgorithmParameter(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
1162
    {
1163
        $tokens = $phpcsFile->getTokens();
1164
1165
        // Check for the existence of the token.
1166
        if (isset($tokens[$stackPtr]) === false) {
1167
            return false;
1168
        }
1169
1170
        if ($tokens[$stackPtr]['code'] !== T_STRING) {
1171
            return false;
1172
        }
1173
1174
        $functionName   = $tokens[$stackPtr]['content'];
1175
        $functionNameLc = strtolower($functionName);
1176
1177
        // Bow out if not one of the functions we're targetting.
1178
        if (isset($this->hashAlgoFunctions[$functionNameLc]) === false) {
1179
            return false;
1180
        }
1181
1182
        // Get the parameter from the function call which should contain the algorithm name.
1183
        $algoParam = $this->getFunctionCallParameter($phpcsFile, $stackPtr, $this->hashAlgoFunctions[$functionNameLc]);
1184
        if ($algoParam === false) {
1185
            return false;
1186
        }
1187
1188
        /**
1189
         * Algorithm is a text string, so we need to remove the quotes.
1190
         */
1191
        $algo = strtolower(trim($algoParam['raw']));
1192
        $algo = $this->stripQuotes($algo);
1193
1194
        return $algo;
1195
    }
1196
1197
}//end class
1198