Completed
Pull Request — master (#153)
by Juliette
02:52
created

BaseAbstractClassMethodTest::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
rs 9.4285
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * Base class to use when testing methods in the Sniff.php file.
4
 *
5
 * @package PHPCompatibility
6
 */
7
8
9
/**
10
 * Set up and Tear down methods for testing methods in the Sniff.php file.
11
 *
12
 * @uses BaseSniffTest
13
 * @package PHPCompatibility
14
 */
15
abstract class BaseAbstractClassMethodTest 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...
16
{
17
18
    public $filename;
19
20
    /**
21
     * The PHP_CodeSniffer_File object containing parsed contents of this file.
22
     *
23
     * @var PHP_CodeSniffer_File
24
     */
25
    protected $_phpcsFile;
26
27
    /**
28
     * A wrapper for the abstract PHPCompatibility sniff.
29
     *
30
     * @var PHPCompatibility_Sniff
31
     */
32
    protected $helperClass;
33
34
35
    public static function setUpBeforeClass()
36
    {
37
        require_once dirname(__FILE__) . '/TestHelperPHPCompatibility.php';
38
    }
39
40
    protected function setUp()
41
    {
42
        parent::setUp();
43
44
        $this->helperClass = new TestHelperPHPCompatibility;
45
46
        $filename = realpath(dirname(__FILE__)) . DIRECTORY_SEPARATOR . $this->filename;
47
        $phpcs    = new PHP_CodeSniffer();
48
49
        if (version_compare(PHP_CodeSniffer::VERSION, '2.0', '<')) {
50
            $this->_phpcsFile = new PHP_CodeSniffer_File(
51
                $filename,
52
                array(),
53
                array(),
54
                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...
55
                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...
56
                $phpcs
57
            );
58
        }
59
        else {
60
            $this->_phpcsFile = new PHP_CodeSniffer_File(
61
                $filename,
62
                array(),
63
                array(),
64
                $phpcs
65
            );
66
        }
67
68
        $contents = file_get_contents($filename);
69
        $this->_phpcsFile->start($contents);
70
    }
71
72
    /**
73
     * Clean up after finished test.
74
     *
75
     * @return void
76
     */
77
    public function tearDown()
78
    {
79
        unset($this->_phpcsFile, $this->helperClass);
80
81
    }//end tearDown()
82
83
}
84