Completed
Push — master ( e572fe...043b66 )
by Wim
02:07
created

DefaultTimezoneRequiredSniff::process()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.2
c 0
b 0
f 0
cc 4
eloc 8
nc 3
nop 2
1
<?php
2
/**
3
 * PHPCompatibility_Sniffs_PHP_DefaultTimeZoneRequiredSniff.
4
 *
5
 * PHP version 5.4
6
 *
7
 * @category  PHP
8
 * @package   PHPCompatibility
9
 * @author    Wim Godden <[email protected]>
10
 * @copyright 2012 Cu.be Solutions bvba
11
 */
12
13
/**
14
 * PHPCompatibility_Sniffs_PHP_DefaultTimeZoneRequiredSniff.
15
 *
16
 * Discourages the use of deprecated INI directives through ini_set() or ini_get().
17
 *
18
 * @category  PHP
19
 * @package   PHPCompatibility
20
 * @author    Wim Godden <[email protected]>
21
 * @copyright 2012 Cu.be Solutions bvba
22
 */
23
class PHPCompatibility_Sniffs_PHP_DefaultTimezoneRequiredSniff extends PHPCompatibility_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...
24
{
25
    /**
26
     * Returns an array of tokens this test wants to listen for.
27
     * Maybe not ideal to do this on each open tag. But I don't feel like digging further into PHP_CodeSniffer right now
28
     *
29
     * @return array
30
     */
31
    public function register()
32
    {
33
        return array(T_OPEN_TAG);
34
35
    }//end register()
36
37
    /**
38
     * Processes this test, when one of its tokens is encountered.
39
     *
40
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
41
     * @param int                  $stackPtr  The position of the current token in the
42
     *                                        stack passed in $tokens.
43
     *
44
     * @return void
45
     */
46
    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
47
    {
48
        if ($this->supportsAbove('5.4')) {
49
            $ini_value = ini_get('date.timezone');
50
            if (is_string($ini_value) === false || $ini_value === '') {
51
                $phpcsFile->addError(
52
                    'Default timezone is required since PHP 5.4',
53
                    $stackPtr,
54
                    'Missing'
55
                );
56
            }
57
        }
58
59
    }//end process()
60
61
62
}//end class
63