Failed Conditions
Branch test-scrutinizer-coverage (7e25b2)
by Wim
13:51 queued 10:07
created

DefaultTimezoneRequiredSniff   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 40
ccs 10
cts 11
cp 0.9091
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 5 1
A process() 0 14 4
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
 * Requires that a default timezone is set as of PHP 5.4.
17
 *
18
 * PHP version 5.4
19
 *
20
 * @category  PHP
21
 * @package   PHPCompatibility
22
 * @author    Wim Godden <[email protected]>
23
 * @copyright 2012 Cu.be Solutions bvba
24
 */
25
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...
26
{
27
    /**
28
     * Returns an array of tokens this test wants to listen for.
29
     * Maybe not ideal to do this on each open tag. But I don't feel like digging further into PHP_CodeSniffer right now
30
     *
31
     * @return array
32
     */
33 2
    public function register()
34
    {
35 2
        return array(T_OPEN_TAG);
36
37
    }//end register()
38
39
    /**
40
     * Processes this test, when one of its tokens is encountered.
41
     *
42
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
43
     * @param int                  $stackPtr  The position of the current token in the
44
     *                                        stack passed in $tokens.
45
     *
46
     * @return void
47
     */
48 2
    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
49
    {
50 2
        if ($this->supportsAbove('5.4')) {
51 1
            $ini_value = ini_get('date.timezone');
52 1
            if (is_string($ini_value) === false || $ini_value === '') {
53 1
                $phpcsFile->addError(
54 1
                    'Default timezone is required since PHP 5.4',
55
                    $stackPtr,
56 1
                    'Missing'
57
                );
58
            }
59
        }
60
61 2
    }//end process()
62
63
64
}//end class
65