| Conditions | 31 |
| Paths | > 20000 |
| Total Lines | 120 |
| Code Lines | 68 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 35 | function check($verbose=false) |
||
| 36 | { |
||
| 37 | // set us up as provider for Api\Cache class |
||
| 38 | $GLOBALS['egw_info']['server']['install_id'] = md5(microtime(true)); |
||
| 39 | unset($GLOBALS['egw_info']['server']['cache_provider_instance']); |
||
| 40 | unset($GLOBALS['egw_info']['server']['cache_provider_tree']); |
||
| 41 | Api\Cache::$default_provider = get_class($this); |
||
|
|
|||
| 42 | |||
| 43 | $failed = 0; |
||
| 44 | foreach(array( |
||
| 45 | Api\Cache::TREE => 'tree', |
||
| 46 | Api\Cache::INSTANCE => 'instance', |
||
| 47 | ) as $level => $label) |
||
| 48 | { |
||
| 49 | $locations = array(); |
||
| 50 | foreach(array('string',123,true,false,null,array(),array(1,2,3)) as $data) |
||
| 51 | { |
||
| 52 | $location = md5(microtime(true).$label.serialize($data)); |
||
| 53 | $get_before_set = $this->get(array($level,__CLASS__,$location)); |
||
| 54 | if (!is_null($get_before_set)) |
||
| 55 | { |
||
| 56 | if ($verbose) echo "$label: get_before_set=".array2string($get_before_set)." != NULL\n"; |
||
| 57 | ++$failed; |
||
| 58 | } |
||
| 59 | if (($set = $this->set(array($level,__CLASS__,$location), $data, 10)) !== true) |
||
| 60 | { |
||
| 61 | if ($verbose) echo "$label: set returned ".array2string($set)." !== TRUE\n"; |
||
| 62 | ++$failed; |
||
| 63 | } |
||
| 64 | $get_after_set = $this->get(array($level,__CLASS__,$location)); |
||
| 65 | if ($get_after_set !== $data) |
||
| 66 | { |
||
| 67 | if ($verbose) echo "$label: get_after_set=".array2string($get_after_set)." !== ".array2string($data)."\n"; |
||
| 68 | ++$failed; |
||
| 69 | } |
||
| 70 | if (is_a($this, 'EGroupware\Api\Cache\ProviderMultiple')) |
||
| 71 | { |
||
| 72 | $mget_after_set = $this->mget(array($level,__CLASS__,array($location))); |
||
| 73 | if ($mget_after_set[$location] !== $data) |
||
| 74 | { |
||
| 75 | if ($verbose) echo "$label: mget_after_set['$location']=".array2string($mget_after_set[$location])." !== ".array2string($data)."\n"; |
||
| 76 | ++$failed; |
||
| 77 | } |
||
| 78 | } |
||
| 79 | $add_after_set = $this->add(array($level,__CLASS__,$location), 'other-data'); |
||
| 80 | if ($add_after_set !== false) |
||
| 81 | { |
||
| 82 | if ($verbose) echo "$label: add_after_set=".array2string($add_after_set)."\n"; |
||
| 83 | ++$failed; |
||
| 84 | } |
||
| 85 | if (($delete = $this->delete(array($level,__CLASS__,$location))) !== true) |
||
| 86 | { |
||
| 87 | if ($verbose) echo "$label: delete returned ".array2string($delete)." !== TRUE\n"; |
||
| 88 | ++$failed; |
||
| 89 | } |
||
| 90 | $get_after_delete = $this->get(array($level,__CLASS__,$location)); |
||
| 91 | if (!is_null($get_after_delete)) |
||
| 92 | { |
||
| 93 | if ($verbose) echo "$label: get_after_delete=".array2string($get_after_delete)." != NULL\n"; |
||
| 94 | ++$failed; |
||
| 95 | } |
||
| 96 | // prepare for mget of everything |
||
| 97 | if (is_a($this, 'EGroupware\Api\Cache\ProviderMultiple')) |
||
| 98 | { |
||
| 99 | $locations[$location] = $data; |
||
| 100 | $mget_after_delete = $this->mget(array($level,__CLASS__,array($location))); |
||
| 101 | if (isset($mget_after_delete[$location])) |
||
| 102 | { |
||
| 103 | if ($verbose) echo "$label: mget_after_delete['$location']=".array2string($mget_after_delete[$location])." != NULL\n"; |
||
| 104 | ++$failed; |
||
| 105 | } |
||
| 106 | } |
||
| 107 | elseif (!is_null($data)) // emulation can NOT distinquish between null and not set |
||
| 108 | { |
||
| 109 | $locations[$location] = $data; |
||
| 110 | } |
||
| 111 | $add_after_delete = $this->add(array($level,__CLASS__,$location), $data, 10); |
||
| 112 | if ($add_after_delete !== true) |
||
| 113 | { |
||
| 114 | if ($verbose) echo "$label: add_after_delete=".array2string($add_after_delete)."\n"; |
||
| 115 | ++$failed; |
||
| 116 | } |
||
| 117 | else |
||
| 118 | { |
||
| 119 | $get_after_add = $this->get(array($level,__CLASS__,$location)); |
||
| 120 | if ($get_after_add !== $data) |
||
| 121 | { |
||
| 122 | if ($verbose) echo "$label: get_after_add=".array2string($get_after_add)." !== ".array2string($data)."\n"; |
||
| 123 | ++$failed; |
||
| 124 | } |
||
| 125 | } |
||
| 126 | } |
||
| 127 | // get all above in one request |
||
| 128 | $keys = array_keys($locations); |
||
| 129 | $keys_bogus = array_merge(array('not-set'),array_keys($locations),array('not-set-too')); |
||
| 130 | if (is_a($this, 'EGroupware\Api\Cache\ProviderMultiple')) |
||
| 131 | { |
||
| 132 | $mget = $this->mget(array($level,__CLASS__,$keys)); |
||
| 133 | $mget_bogus = $this->mget(array($level,__CLASS__,$keys_bogus)); |
||
| 134 | /* Api\Cache::getCache() gives a different result, as it does NOT use $level direkt |
||
| 135 | } |
||
| 136 | else |
||
| 137 | { |
||
| 138 | $mget = Api\Cache::getCache($level, __CLASS__, $keys); |
||
| 139 | $mget_bogus = Api\Cache::getCache($level, __CLASS__, $keys_bogus); |
||
| 140 | }*/ |
||
| 141 | if ($mget !== $locations) |
||
| 142 | { |
||
| 143 | if ($verbose) echo "$label: mget=\n".array2string($mget)." !==\n".array2string($locations)."\n"; |
||
| 144 | ++$failed; |
||
| 145 | } |
||
| 146 | if ($mget_bogus !== $locations) |
||
| 147 | { |
||
| 148 | if ($verbose) echo "$label: mget(".array2string($keys_bogus).")=\n".array2string($mget_bogus)." !==\n".array2string($locations)."\n"; |
||
| 149 | ++$failed; |
||
| 150 | } |
||
| 151 | } |
||
| 152 | } |
||
| 153 | |||
| 154 | return $failed; |
||
| 155 | } |
||
| 213 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..