Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
10 | class InvalidHostTest extends PHPUnit_Framework_TestCase |
||
11 | { |
||
12 | /** @var xmlrpc_client $client */ |
||
13 | public $client = null; |
||
14 | public $args = array(); |
||
15 | |||
16 | public function setUp() |
||
17 | { |
||
18 | $this->args = argParser::getArgs(); |
||
19 | |||
20 | $this->client = new xmlrpc_client('/NOTEXIST.php', $this->args['LOCALSERVER'], 80); |
||
21 | $this->client->setDebug($this->args['DEBUG']); |
||
22 | |||
23 | if ($this->args['DEBUG'] == 1) |
||
24 | ob_start(); |
||
25 | } |
||
26 | |||
27 | protected function tearDown() |
||
28 | { |
||
29 | if ($this->args['DEBUG'] != 1) |
||
30 | return; |
||
31 | $out = ob_get_clean(); |
||
32 | $status = $this->getStatus(); |
||
33 | if ($status == PHPUnit_Runner_BaseTestRunner::STATUS_ERROR |
||
34 | || $status == PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE) { |
||
35 | echo $out; |
||
36 | } |
||
37 | } |
||
38 | |||
39 | public function test404() |
||
40 | { |
||
41 | $m = new xmlrpcmsg('examples.echo', array( |
||
42 | new xmlrpcval('hello', 'string'), |
||
43 | )); |
||
44 | $r = $this->client->send($m, 5); |
||
45 | $this->assertEquals(5, $r->faultCode()); |
||
46 | } |
||
47 | |||
48 | public function testSrvNotFound() |
||
61 | } |
||
62 | } |
||
63 | |||
64 | public function testCurlKAErr() |
||
93 | } |
||
94 | } |
||
95 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.