Conditions | 11 |
Paths | 35 |
Total Lines | 66 |
Lines | 11 |
Ratio | 16.67 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
23 | public function setUp() |
||
24 | { |
||
25 | if (!class_exists('Memcached')) |
||
26 | { |
||
27 | $this->markTestSkipped( |
||
28 | 'The Memcached class does not exist.' |
||
29 | ); |
||
30 | |||
31 | return; |
||
32 | } |
||
33 | |||
34 | // Parse the DSN details for the test server |
||
35 | $dsn = defined('JTEST_CACHE_MEMCACHED_DSN') ? JTEST_CACHE_MEMCACHED_DSN : getenv('JTEST_CACHE_MEMCACHED_DSN'); |
||
36 | |||
37 | if ($dsn) |
||
38 | { |
||
39 | $options = $this->cacheOptions; |
||
40 | |||
41 | if (!$options) |
||
|
|||
42 | { |
||
43 | $options = array(); |
||
44 | } |
||
45 | |||
46 | // First let's trim the memcached: part off the front of the DSN if it exists. |
||
47 | if (strpos($dsn, 'memcached:') === 0) |
||
48 | { |
||
49 | $dsn = substr($dsn, 10); |
||
50 | } |
||
51 | |||
52 | if (!is_array($options)) |
||
53 | { |
||
54 | $options = array($options); |
||
55 | } |
||
56 | |||
57 | // Split the DSN into its parts over semicolons. |
||
58 | $parts = explode(';', $dsn); |
||
59 | |||
60 | if (!isset($options['memcache.servers'])) |
||
61 | { |
||
62 | $server = new \stdClass; |
||
63 | |||
64 | // Parse each part and populate the options array. |
||
65 | View Code Duplication | foreach ($parts as $part) |
|
66 | { |
||
67 | list ($k, $v) = explode('=', $part, 2); |
||
68 | switch ($k) |
||
69 | { |
||
70 | case 'host': |
||
71 | case 'port': |
||
72 | $server->$k = $v; |
||
73 | break; |
||
74 | } |
||
75 | } |
||
76 | $options['memcache.servers'] = array($server); |
||
77 | } |
||
78 | |||
79 | $this->cacheOptions = $options; |
||
80 | } |
||
81 | else |
||
82 | { |
||
83 | $this->markTestSkipped('No configuration for Memcached given'); |
||
84 | } |
||
85 | |||
86 | $this->cacheClass = 'Joomla\\Cache\\Memcached'; |
||
87 | parent::setUp(); |
||
88 | } |
||
89 | } |
||
90 |
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.