Completed
Pull Request — master (#215)
by Juliette
03:31
created

setUpBeforeClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 18 and the first side effect is on line 9.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * Base class to use when testing methods in the Sniff.php file.
4
 *
5
 * @package PHPCompatibility
6
 */
7
8
if (class_exists('BaseSniffTest', true) === false) {
9
    require_once dirname(dirname(__FILE__)) . '/BaseSniffTest.php';
10
}
11
12
/**
13
 * Set up and Tear down methods for testing methods in the Sniff.php file.
14
 *
15
 * @uses    BaseSniffTest
16
 * @package PHPCompatibility
17
 */
18
abstract class AbstractSniffMethodTestFramework extends BaseSniffTest
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...
19
{
20
21
    public $filename;
22
23
    /**
24
     * The PHP_CodeSniffer_File object containing parsed contents of this file.
25
     *
26
     * @var PHP_CodeSniffer_File
27
     */
28
    protected $_phpcsFile;
29
30
    /**
31
     * A wrapper for the abstract PHPCompatibility sniff.
32
     *
33
     * @var PHPCompatibility_Sniff
34
     */
35
    protected $helperClass;
36
37
38
    public static function setUpBeforeClass()
39
    {
40
        require_once dirname(__FILE__) . '/TestHelperPHPCompatibility.php';
41
    }
42
43
    protected function setUp()
44
    {
45
        parent::setUp();
46
47
        $this->helperClass = new TestHelperPHPCompatibility;
48
49
        $filename = realpath(dirname(__FILE__)) . DIRECTORY_SEPARATOR . $this->filename;
50
        $phpcs    = new PHP_CodeSniffer();
51
52
        if (version_compare(PHP_CodeSniffer::VERSION, '2.0', '<')) {
53
            $this->_phpcsFile = new PHP_CodeSniffer_File(
54
                $filename,
55
                array(),
56
                array(),
57
                array(),
0 ignored issues
show
Documentation introduced by
array() is of type array, but the function expects a object<PHP_CodeSniffer>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
58
                array(),
0 ignored issues
show
Unused Code introduced by
The call to PHP_CodeSniffer_File::__construct() has too many arguments starting with array().

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
59
                $phpcs
60
            );
61
        }
62
        else {
63
            $this->_phpcsFile = new PHP_CodeSniffer_File(
64
                $filename,
65
                array(),
66
                array(),
67
                $phpcs
68
            );
69
        }
70
71
        $contents = file_get_contents($filename);
72
        $this->_phpcsFile->start($contents);
73
    }
74
75
    /**
76
     * Clean up after finished test.
77
     *
78
     * @return void
79
     */
80
    public function tearDown()
81
    {
82
        unset($this->_phpcsFile, $this->helperClass);
83
84
    }//end tearDown()
85
86
}
87