for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Class FinderTest
*
* @author Mauro Moreno <[email protected]>
*/
namespace MauroMoreno\FindBundle\Tests\Services;
use MauroMoreno\FindBundle\Service\Finder;
* @package MauroMoreno\FindBundle\Tests\Services
class FinderTest extends \PHPUnit_Framework_TestCase
{
* @var Finder
private $finder;
* Set up
public function setUp()
parent::setUp();
$this->finder = new Finder();
}
* Test find, wrong parameter pattern
* @expectedException \InvalidArgumentException
public function testFindWrongParameterPattern()
$found = $this->finder->find(
$found
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
$myVar = 'Value'; $higher = false; if (rand(1, 6) > 3) { $higher = true; } else { $higher = false; }
Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.
$myVar
$higher
[],
array()
array
string
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);
new \SplFileInfo(__DIR__ . '/../Fixtures/directory/file_2')
);
* Test find, not found
public function testFindNotFound()
'pattern',
$this->assertEquals($found, false);
* Test find Ok
public function testFindOk()
$file_info = new \SplFileInfo(
__DIR__ . '/../Fixtures/directory/file_1'
$file_info
$this->assertEquals($found, $file_info);
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.