Completed
Pull Request — master (#170)
by Juliette
02:34
created

PHPCompatibility_Sniff::getFunctionCallParameter()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 2
eloc 6
nc 2
nop 3
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
/* The testVersion configuration variable may be in any of the following formats:
26
 * 1) Omitted/empty, in which case no version is specified.  This effectively
27
 *    disables all the checks provided by this standard.
28
 * 2) A single PHP version number, e.g. "5.4" in which case the standard checks that
29
 *    the code will run on that version of PHP (no deprecated features or newer
30
 *    features being used).
31
 * 3) A range, e.g. "5.0-5.5", in which case the standard checks the code will run
32
 *    on all PHP versions in that range, and that it doesn't use any features that
33
 *    were deprecated by the final version in the list, or which were not available
34
 *    for the first version in the list.
35
 * PHP version numbers should always be in Major.Minor format.  Both "5", "5.3.2"
36
 * would be treated as invalid, and ignored.
37
 * This standard doesn't support checking against PHP4, so the minimum version that
38
 * is recognised is "5.0".
39
 */
40
41
    private function getTestVersion()
42
    {
43
        /**
44
         * var $arrTestVersions will hold an array containing min/max version of PHP
45
         *   that we are checking against (see above).  If only a single version
46
         *   number is specified, then this is used as both the min and max.
47
         */
48
        static $arrTestVersions = array();
49
50
        $testVersion = trim(PHP_CodeSniffer::getConfigData('testVersion'));
51
52
        if (!isset($arrTestVersions[$testVersion]) && !empty($testVersion)) {
53
54
            $arrTestVersions[$testVersion] = array(null, null);
55
            if (preg_match('/^\d+\.\d+$/', $testVersion)) {
56
                $arrTestVersions[$testVersion] = array($testVersion, $testVersion);
57
            }
58
            elseif (preg_match('/^(\d+\.\d+)\s*-\s*(\d+\.\d+)$/', $testVersion,
59
                               $matches))
60
            {
61
                if (version_compare($matches[1], $matches[2], '>')) {
62
                    trigger_error("Invalid range in testVersion setting: '"
63
                                  . $testVersion . "'", E_USER_WARNING);
64
                }
65
                else {
66
                    $arrTestVersions[$testVersion] = array($matches[1], $matches[2]);
67
                }
68
            }
69
            elseif (!$testVersion == '') {
70
                trigger_error("Invalid testVersion setting: '" . $testVersion
71
                              . "'", E_USER_WARNING);
72
            }
73
        }
74
75
        if (isset($arrTestVersions[$testVersion])) {
76
            return $arrTestVersions[$testVersion];
77
        }
78
        else {
79
			return array(null, null);
80
        }
81
    }
82
83 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...
84
    {
85
        $testVersion = $this->getTestVersion();
86
        $testVersion = $testVersion[1];
87
88
        if (is_null($testVersion)
89
            || version_compare($testVersion, $phpVersion) >= 0
90
        ) {
91
            return true;
92
        } else {
93
            return false;
94
        }
95
    }//end supportsAbove()
96
97 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...
98
    {
99
        $testVersion = $this->getTestVersion();
100
        $testVersion = $testVersion[0];
101
102
        if (!is_null($testVersion)
103
            && version_compare($testVersion, $phpVersion) <= 0
104
        ) {
105
            return true;
106
        } else {
107
            return false;
108
        }
109
    }//end supportsBelow()
110
111
    /**
112
     * Returns the name(s) of the interface(s) that the specified class implements.
113
     *
114
     * Returns FALSE on error or if there are no implemented interface names.
115
     *
116
     * {@internal Duplicate of same method as introduced in PHPCS 2.7.
117
     * Once the minimum supported PHPCS version for this sniff library goes beyond
118
     * that, this method can be removed and call to it replaced with
119
     * `$phpcsFile->findImplementedInterfaceNames($stackPtr)` calls.}}
120
     *
121
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
122
     * @param int                  $stackPtr  The position of the class token.
123
     *
124
     * @return array|false
125
     */
126
    public function findImplementedInterfaceNames($phpcsFile, $stackPtr)
127
    {
128
        $tokens = $phpcsFile->getTokens();
129
130
        // Check for the existence of the token.
131
        if (isset($tokens[$stackPtr]) === false) {
132
            return false;
133
        }
134
135
        if ($tokens[$stackPtr]['code'] !== T_CLASS) {
136
            return false;
137
        }
138
139
        if (isset($tokens[$stackPtr]['scope_closer']) === false) {
140
            return false;
141
        }
142
143
        $classOpenerIndex = $tokens[$stackPtr]['scope_opener'];
144
        $implementsIndex  = $phpcsFile->findNext(T_IMPLEMENTS, $stackPtr, $classOpenerIndex);
145
        if ($implementsIndex === false) {
146
            return false;
147
        }
148
149
        $find = array(
150
                 T_NS_SEPARATOR,
151
                 T_STRING,
152
                 T_WHITESPACE,
153
                 T_COMMA,
154
                );
155
156
        $end  = $phpcsFile->findNext($find, ($implementsIndex + 1), ($classOpenerIndex + 1), true);
157
        $name = $phpcsFile->getTokensAsString(($implementsIndex + 1), ($end - $implementsIndex - 1));
158
        $name = trim($name);
159
160
        if ($name === '') {
161
            return false;
162
        } else {
163
            $names = explode(',', $name);
164
            $names = array_map('trim', $names);
165
            return $names;
166
        }
167
168
    }//end findImplementedInterfaceNames()
169
170
171
    /**
172
     * Checks if a function call has parameters.
173
     *
174
     * Expects to be passed the T_STRING stack pointer for the function call.
175
     * If passed a T_STRING which is *not* a function call, the behaviour is unreliable.
176
     *
177
     * @link https://github.com/wimg/PHPCompatibility/issues/120
178
     * @link https://github.com/wimg/PHPCompatibility/issues/152
179
     *
180
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
181
     * @param int                  $stackPtr  The position of the function call token.
182
     *
183
     * @return bool
184
     */
185
    public function doesFunctionCallHaveParameters(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
186
    {
187
        $tokens = $phpcsFile->getTokens();
188
189
        // Check for the existence of the token.
190
        if (isset($tokens[$stackPtr]) === false) {
191
            return false;
192
        }
193
194
        if ($tokens[$stackPtr]['code'] !== T_STRING) {
195
            return false;
196
        }
197
198
        // Next non-empty token should be the open parenthesis.
199
        $openParenthesis = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true);
200
        if ($openParenthesis === false || $tokens[$openParenthesis]['code'] !== T_OPEN_PARENTHESIS) {
201
            return false;
202
        }
203
204
        if (isset($tokens[$openParenthesis]['parenthesis_closer']) === false) {
205
            return false;
206
        }
207
208
        $closeParenthesis = $tokens[$openParenthesis]['parenthesis_closer'];
209
        $nextNonEmpty     = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $openParenthesis + 1, $closeParenthesis + 1, true);
210
211
        if ($nextNonEmpty === $closeParenthesis) {
212
            // No parameters.
213
            return false;
214
        }
215
216
        return true;
217
    }
218
219
220
    /**
221
     * Count the number of parameters a function call has been passed.
222
     *
223
     * Expects to be passed the T_STRING stack pointer for the function call.
224
     * If passed a T_STRING which is *not* a function call, the behaviour is unreliable.
225
     *
226
     * @link https://github.com/wimg/PHPCompatibility/issues/111
227
     * @link https://github.com/wimg/PHPCompatibility/issues/114
228
     * @link https://github.com/wimg/PHPCompatibility/issues/151
229
     *
230
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
231
     * @param int                  $stackPtr  The position of the function call token.
232
     *
233
     * @return int
234
     */
235
    public function getFunctionCallParameterCount(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
236
    {
237
        if ($this->doesFunctionCallHaveParameters($phpcsFile, $stackPtr) === false) {
238
            return 0;
239
        }
240
241
        return count($this->getFunctionCallParameters($phpcsFile, $stackPtr));
242
    }
243
244
245
    /**
246
     * Get information on all parameters passed to a function call.
247
     *
248
     * Expects to be passed the T_STRING stack pointer for the function call.
249
     * If passed a T_STRING which is *not* a function call, the behaviour is unreliable.
250
     *
251
     * Will return an multi-dimentional array with the start token pointer, end token
252
     * pointer and raw parameter value for all parameters. Index will be 0-based.
253
     * If no parameters are found, will return an empty array.
254
     *
255
     * @param PHP_CodeSniffer_File $phpcsFile     The file being scanned.
256
     * @param int                  $stackPtr      The position of the function call token.
257
     *
258
     * @return array
259
     */
260
    public function getFunctionCallParameters(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
261
    {
262
        if ($this->doesFunctionCallHaveParameters($phpcsFile, $stackPtr) === false) {
263
            return array();
264
        }
265
266
        // Ok, we know we have a T_STRING with parameters and valid open & close parenthesis.
267
        $tokens = $phpcsFile->getTokens();
268
269
        $openParenthesis = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true);
270
        $closeParenthesis = $tokens[$openParenthesis]['parenthesis_closer'];
271
272
        // Which nesting level is the one we are interested in ?
273
        $nestedParenthesisCount = 1;
274
        if (isset($tokens[$openParenthesis]['nested_parenthesis'])) {
275
            $nestedParenthesisCount = count($tokens[$openParenthesis]['nested_parenthesis']) + 1;
276
        }
277
278
        $parameters = array();
279
        $nextComma  = $openParenthesis;
280
        $paramStart = $openParenthesis + 1;
281
        $cnt        = 0;
282
        while ($nextComma = $phpcsFile->findNext(array(T_COMMA, T_CLOSE_PARENTHESIS), $nextComma + 1, $closeParenthesis + 1)) {
283
            // Ignore comma's at a lower nesting level.
284
            if (
285
                $tokens[$nextComma]['type'] == 'T_COMMA'
286
                &&
287
                isset($tokens[$nextComma]['nested_parenthesis'])
288
                &&
289
                count($tokens[$nextComma]['nested_parenthesis']) != $nestedParenthesisCount
290
            ) {
291
                continue;
292
            }
293
294
            // Ignore closing parenthesis if not 'ours'.
295
            if ($tokens[$nextComma]['type'] == 'T_CLOSE_PARENTHESIS' && $nextComma != $closeParenthesis) {
296
                continue;
297
            }
298
299
            // Ok, we've reached the end of the parameter.
300
            $parameters[$cnt]['start'] = $paramStart;
301
            $parameters[$cnt]['end']   = $nextComma - 1;
302
            $parameters[$cnt]['raw']   = trim($phpcsFile->getTokensAsString($paramStart, ($nextComma - $paramStart)));
303
304
            // Prepare for the next parameter.
305
            $paramStart = $nextComma + 1;
306
            $cnt++;
307
        }
308
309
        return $parameters;
310
    }
311
312
313
    /**
314
     * Get information on a specific parameter passed to a function call.
315
     *
316
     * Expects to be passed the T_STRING stack pointer for the function call.
317
     * If passed a T_STRING which is *not* a function call, the behaviour is unreliable.
318
     *
319
     * Will return a array with the start token pointer, end token pointer and the raw value
320
     * of the parameter at a specific offset.
321
     * If the specified parameter is not found, will return false.
322
     *
323
     * @param PHP_CodeSniffer_File $phpcsFile   The file being scanned.
324
     * @param int                  $stackPtr    The position of the function call token.
325
     * @param int                  $paramOffset The 0-based index position of the parameter to retrieve.
326
     *
327
     * @return array|false
328
     */
329
    public function getFunctionCallParameter(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $paramOffset)
330
    {
331
        $parameters = $this->getFunctionCallParameters($phpcsFile, $stackPtr);
332
333
        if (isset($parameters[$paramOffset]) === false) {
334
            return false;
335
        }
336
        else {
337
            return $parameters[$paramOffset];
338
        }
339
    }
340
341
342
    /**
343
     * Returns the fully qualified class name for a new class instantiation.
344
     *
345
     * Returns an empty string if the class name could not be reliably inferred.
346
     *
347
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
348
     * @param int                  $stackPtr  The position of a T_NEW token.
349
     *
350
     * @return string
351
     */
352
    public function getFQClassNameFromNewToken(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
353
    {
354
        $tokens = $phpcsFile->getTokens();
355
356
        // Check for the existence of the token.
357
        if (isset($tokens[$stackPtr]) === false) {
358
            return '';
359
        }
360
361
        if ($tokens[$stackPtr]['code'] !== T_NEW) {
362
            return '';
363
        }
364
365
        $find = array(
366
                 T_NS_SEPARATOR,
367
                 T_STRING,
368
                 T_NAMESPACE,
369
                 T_WHITESPACE,
370
                );
371
372
        $start     = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true);
373
        $end       = $phpcsFile->findNext($find, ($start + 1), null, true, null, true);
374
        $className = $phpcsFile->getTokensAsString($start, ($end - $start));
375
        $className = trim($className);
376
377
        return $this->getFQName($phpcsFile, $stackPtr, $className);
378
    }
379
380
381
    /**
382
     * Returns the fully qualified name of the class that the specified class extends.
383
     *
384
     * Returns an empty string if the class does not extend another class or if
385
     * the class name could not be reliably inferred.
386
     *
387
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
388
     * @param int                  $stackPtr  The position of a T_CLASS token.
389
     *
390
     * @return string
391
     */
392
    public function getFQExtendedClassName(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
393
    {
394
        $tokens = $phpcsFile->getTokens();
395
396
        // Check for the existence of the token.
397
        if (isset($tokens[$stackPtr]) === false) {
398
            return '';
399
        }
400
401
        if ($tokens[$stackPtr]['code'] !== T_CLASS) {
402
            return '';
403
        }
404
405
        $extends = $phpcsFile->findExtendedClassName($stackPtr);
406
        if (empty($extends) || is_string($extends) === false) {
407
            return '';
408
        }
409
410
        return $this->getFQName($phpcsFile, $stackPtr, $extends);
411
    }
412
413
414
    /**
415
     * Returns the class name for the static usage of a class.
416
     * This can be a call to a method, the use of a property or constant.
417
     *
418
     * Returns an empty string if the class name could not be reliably inferred.
419
     *
420
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
421
     * @param int                  $stackPtr  The position of a T_NEW token.
422
     *
423
     * @return string
424
     */
425
    public function getFQClassNameFromDoubleColonToken(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
426
    {
427
        $tokens = $phpcsFile->getTokens();
428
429
        // Check for the existence of the token.
430
        if (isset($tokens[$stackPtr]) === false) {
431
            return '';
432
        }
433
434
        if ($tokens[$stackPtr]['code'] !== T_DOUBLE_COLON) {
435
            return '';
436
        }
437
438
        // Nothing to do if 'parent' or 'static' as we don't know how far the class tree extends.
439
        if (in_array($tokens[$stackPtr - 1]['code'], array(T_PARENT, T_STATIC), true)) {
440
            return '';
441
        }
442
443
        // Get the classname from the class declaration if self is used.
444
        if ($tokens[$stackPtr - 1]['code'] === T_SELF) {
445
            $classDeclarationPtr = $phpcsFile->findPrevious(T_CLASS, $stackPtr - 1);
446
            if ($classDeclarationPtr === false) {
447
				return '';
448
			}
449
            $className = $phpcsFile->getDeclarationName($classDeclarationPtr);
450
            return $this->getFQName($phpcsFile, $classDeclarationPtr, $className);
451
        }
452
453
        $find = array(
454
                 T_NS_SEPARATOR,
455
                 T_STRING,
456
                 T_NAMESPACE,
457
                 T_WHITESPACE,
458
                );
459
460
        $start     = ($phpcsFile->findPrevious($find, $stackPtr - 1, null, true, null, true) + 1);
461
        $className = $phpcsFile->getTokensAsString($start, ($stackPtr - $start));
462
        $className = trim($className);
463
464
        return $this->getFQName($phpcsFile, $stackPtr, $className);
465
    }
466
467
468
    /**
469
     * Get the Fully Qualified name for a class/function/constant etc.
470
     *
471
     * Checks if a class/function/constant name is already fully qualified and
472
     * if not, enrich it with the relevant namespace information.
473
     *
474
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
475
     * @param int                  $stackPtr  The position of the token.
476
     * @param string               $name      The class / function / constant name.
477
     *
478
     * @return string
479
     */
480
    public function getFQName(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $name)
481
    {
482
        if (strpos($name, '\\' ) === 0) {
483
            // Already fully qualified.
484
            return $name;
485
        }
486
487
        // Remove the namespace keyword if used.
488
        if (strpos($name, 'namespace\\') === 0) {
489
            $name = substr($name, 10);
490
        }
491
492
        $namespace = $this->determineNamespace($phpcsFile, $stackPtr);
493
494
        if ($namespace === '') {
495
            return '\\' . $name;
496
        }
497
        else {
498
            return '\\' . $namespace . '\\' . $name;
499
        }
500
    }
501
502
503
    /**
504
     * Is the class/function/constant name namespaced or global ?
505
     *
506
     * @param string $FQName Fully Qualified name of a class, function etc.
507
     *                       I.e. should always start with a `\` !
508
     *
509
     * @return bool True if namespaced, false if global.
510
     */
511
    public function isNamespaced($FQName) {
512
        if (strpos($FQName, '\\') !== 0) {
513
            throw new PHP_CodeSniffer_Exception('$FQName must be a fully qualified name');
514
        }
515
516
        return (strpos(substr($FQName, 1), '\\') !== false);
517
    }
518
519
520
    /**
521
     * Determine the namespace name an arbitrary token lives in.
522
     *
523
     * @param PHP_CodeSniffer_File $phpcsFile Instance of phpcsFile.
524
     * @param int                  $stackPtr  The token position for which to determine the namespace.
525
     *
526
     * @return string Namespace name or empty string if it couldn't be determined or no namespace applies.
527
     */
528
    public function determineNamespace(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
529
    {
530
        $tokens = $phpcsFile->getTokens();
531
532
        // Check for the existence of the token.
533
        if (isset($tokens[$stackPtr]) === false) {
534
            return '';
535
        }
536
537
        // Check for scoped namespace {}.
538
        if (empty($tokens[$stackPtr]['conditions']) === false) {
539
            foreach ($tokens[$stackPtr]['conditions'] as $pointer => $type) {
540
                if ($type === T_NAMESPACE) {
541
                    $namespace = $this->getDeclaredNamespaceName($phpcsFile, $pointer);
542
                    if ($namespace !== false) {
543
                        return $namespace;
544
                    }
545
                }
546
                break; // We only need to check the highest level condition.
547
            }
548
        }
549
550
        /*
551
         * Not in a scoped namespace, so let's see if we can find a non-scoped namespace instead.
552
         * Keeping in mind that:
553
         * - there can be multiple non-scoped namespaces in a file (bad practice, but it happens).
554
         * - the namespace keyword can also be used as part of a function/method call and such.
555
         * - that a non-named namespace resolves to the global namespace.
556
         */
557
        $previousNSToken = $stackPtr;
558
        $namespace       = false;
559
        do {
560
            $previousNSToken = $phpcsFile->findPrevious(T_NAMESPACE, $previousNSToken -1);
561
562
            // Stop if we encounter a scoped namespace declaration as we already know we're not in one.
563
            if (empty($tokens[$previousNSToken]['scope_condition']) === false && $tokens[$previousNSToken]['scope_condition'] = $previousNSToken) {
564
                break;
565
            }
566
            $namespace = $this->getDeclaredNamespaceName($phpcsFile, $previousNSToken);
567
568
        } while ($namespace === false && $previousNSToken !== false);
569
570
        // If we still haven't got a namespace, return an empty string.
571
        if ($namespace === false) {
572
            return '';
573
        }
574
        else {
575
            return $namespace;
576
        }
577
    }
578
579
    /**
580
     * Get the complete namespace name for a namespace declaration.
581
     *
582
     * For hierarchical namespaces, the name will be composed of several tokens,
583
     * i.e. MyProject\Sub\Level which will be returned together as one string.
584
     *
585
     * @param PHP_CodeSniffer_File $phpcsFile Instance of phpcsFile.
586
     * @param int|bool             $stackPtr  The position of a T_NAMESPACE token.
587
     *
588
     * @return string|false Namespace name or false if not a namespace declaration.
589
     *                      Namespace name can be an empty string for global namespace declaration.
590
     */
591
    public function getDeclaredNamespaceName(PHP_CodeSniffer_File $phpcsFile, $stackPtr )
592
    {
593
        $tokens = $phpcsFile->getTokens();
594
595
        // Check for the existence of the token.
596
        if ($stackPtr === false || isset($tokens[$stackPtr]) === false) {
597
            return false;
598
        }
599
600
        if ($tokens[$stackPtr]['code'] !== T_NAMESPACE) {
601
            return false;
602
        }
603
604
        if ($tokens[$stackPtr + 1]['code'] === T_NS_SEPARATOR) {
605
            // Not a namespace declaration, but use of, i.e. namespace\someFunction();
606
            return false;
607
        }
608
609
        $nextToken = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true);
610
        if ($tokens[$nextToken]['code'] === T_OPEN_CURLY_BRACKET) {
611
            // Declaration for global namespace when using multiple namespaces in a file.
612
            // I.e.: namespace {}
613
            return '';
614
        }
615
616
        // Ok, this should be a namespace declaration, so get all the parts together.
617
        $validTokens = array(
618
                        T_STRING,
619
                        T_NS_SEPARATOR,
620
                        T_WHITESPACE,
621
                       );
622
623
        $namespaceName = '';
624
        while(in_array($tokens[$nextToken]['code'], $validTokens, true) === true) {
625
            $namespaceName .= trim($tokens[$nextToken]['content']);
626
            $nextToken++;
627
        }
628
629
        return $namespaceName;
630
    }
631
632
}//end class
633