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:
Complex classes like Xhgui_Storage_File often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Xhgui_Storage_File, and based on these observations, apply Extract Interface, too.
| 1 | <?php  | 
            ||
| 3 | class Xhgui_Storage_File extends Xhgui_Storage_Abstract implements  | 
            ||
| 4 | Xhgui_StorageInterface,  | 
            ||
| 5 | Xhgui_WatchedFunctionsStorageInterface  | 
            ||
| 6 | { | 
            ||
| 7 | |||
| 8 | /**  | 
            ||
| 9 | * @var string  | 
            ||
| 10 | */  | 
            ||
| 11 | protected $path = '../data/';  | 
            ||
| 12 | |||
| 13 | /**  | 
            ||
| 14 | * @var string  | 
            ||
| 15 | */  | 
            ||
| 16 | protected $prefix = 'xhgui.data';  | 
            ||
| 17 | |||
| 18 | /**  | 
            ||
| 19 | * @var bool|mixed  | 
            ||
| 20 | */  | 
            ||
| 21 | protected $separateMeta = true;  | 
            ||
| 22 | |||
| 23 | /**  | 
            ||
| 24 | * @var mixed  | 
            ||
| 25 | */  | 
            ||
| 26 | protected $dataSerializer;  | 
            ||
| 27 | |||
| 28 | /**  | 
            ||
| 29 | * @var mixed  | 
            ||
| 30 | */  | 
            ||
| 31 | protected $metaSerializer;  | 
            ||
| 32 | |||
| 33 | /**  | 
            ||
| 34 | * @var string  | 
            ||
| 35 | */  | 
            ||
| 36 | protected $watchedFunctionsPathPrefix = '../watched_functions/';  | 
            ||
| 37 | |||
| 38 | /**  | 
            ||
| 39 | * @var int[]  | 
            ||
| 40 | */  | 
            ||
| 41 | protected $countCache;  | 
            ||
| 42 | |||
| 43 | /**  | 
            ||
| 44 | * @var Xhgui_Storage_Filter  | 
            ||
| 45 | */  | 
            ||
| 46 | private $filter;  | 
            ||
| 47 | |||
| 48 | /**  | 
            ||
| 49 | * Xhgui_Storage_File constructor.  | 
            ||
| 50 | * @param $config  | 
            ||
| 51 | */  | 
            ||
| 52 | public function __construct($config)  | 
            ||
| 61 | |||
| 62 | /**  | 
            ||
| 63 | * @inheritDoc  | 
            ||
| 64 | * @param Xhgui_Storage_Filter $filter  | 
            ||
| 65 | * @param bool $projections  | 
            ||
| 66 | * @return Xhgui_Storage_ResultSet  | 
            ||
| 67 | */  | 
            ||
| 68 | public function find(Xhgui_Storage_Filter $filter, $projections = false)  | 
            ||
| 172 | |||
| 173 | /**  | 
            ||
| 174 | * @inheritDoc  | 
            ||
| 175 | * @param Xhgui_Storage_Filter $filter  | 
            ||
| 176 | * @return int  | 
            ||
| 177 | */  | 
            ||
| 178 | public function count(Xhgui_Storage_Filter $filter)  | 
            ||
| 186 | |||
| 187 | /**  | 
            ||
| 188 | * @inheritDoc  | 
            ||
| 189 | * @param $id  | 
            ||
| 190 | * @return mixed  | 
            ||
| 191 | */  | 
            ||
| 192 | public function findOne($id)  | 
            ||
| 199 | |||
| 200 | /**  | 
            ||
| 201 | * @inheritDoc  | 
            ||
| 202 | * @param $id  | 
            ||
| 203 | * @return bool  | 
            ||
| 204 | */  | 
            ||
| 205 | public function remove($id)  | 
            ||
| 217 | |||
| 218 | /**  | 
            ||
| 219 | * @inheritDoc  | 
            ||
| 220 | */  | 
            ||
| 221 | public function drop()  | 
            ||
| 226 | |||
| 227 | /**  | 
            ||
| 228 | * @inheritDoc  | 
            ||
| 229 | * @param $match  | 
            ||
| 230 | * @param $col  | 
            ||
| 231 | * @param int $percentile  | 
            ||
| 232 | * @return array  | 
            ||
| 233 | */  | 
            ||
| 234 | public function aggregate(Xhgui_Storage_Filter $filter, $col, $percentile = 1)  | 
            ||
| 263 | |||
| 264 | |||
| 265 | /**  | 
            ||
| 266 | * Column sorter  | 
            ||
| 267 | *  | 
            ||
| 268 | * @param $a  | 
            ||
| 269 | * @param $b  | 
            ||
| 270 | * @return int  | 
            ||
| 271 | */  | 
            ||
| 272 | public function sortByColumn($a, $b)  | 
            ||
| 327 | |||
| 328 | /**  | 
            ||
| 329 | * Generate meta profile name from profile file name.  | 
            ||
| 330 | *  | 
            ||
| 331 | * In most cases just add .meta extension  | 
            ||
| 332 | *  | 
            ||
| 333 | * @param $file  | 
            ||
| 334 | * @return mixed  | 
            ||
| 335 | */  | 
            ||
| 336 | protected function getMetafileNameFromProfileName($file)  | 
            ||
| 341 | |||
| 342 | /**  | 
            ||
| 343 | * Load profile file from disk, prepare it and return parsed array  | 
            ||
| 344 | *  | 
            ||
| 345 | * @param $path  | 
            ||
| 346 | * @param bool $meta  | 
            ||
| 347 | * @return mixed  | 
            ||
| 348 | */  | 
            ||
| 349 | protected function importFile($path, $meta = false)  | 
            ||
| 386 | |||
| 387 | /**  | 
            ||
| 388 | * @inheritDoc  | 
            ||
| 389 | * @return array  | 
            ||
| 390 | */  | 
            ||
| 391 | public function getWatchedFunctions()  | 
            ||
| 400 | |||
| 401 | /**  | 
            ||
| 402 | * @inheritDoc  | 
            ||
| 403 | * @param $name  | 
            ||
| 404 | * @return bool  | 
            ||
| 405 | */  | 
            ||
| 406 | View Code Duplication | public function addWatchedFunction($name)  | 
            |
| 419 | |||
| 420 | /**  | 
            ||
| 421 | * @inheritDoc  | 
            ||
| 422 | * @param $id  | 
            ||
| 423 | * @param $name  | 
            ||
| 424 | * @return bool  | 
            ||
| 425 | */  | 
            ||
| 426 | View Code Duplication | public function updateWatchedFunction($id, $name)  | 
            |
| 439 | |||
| 440 | /**  | 
            ||
| 441 | * @inheritDoc  | 
            ||
| 442 | * @param $id  | 
            ||
| 443 | */  | 
            ||
| 444 | public function removeWatchedFunction($id)  | 
            ||
| 450 | |||
| 451 | /**  | 
            ||
| 452 | * Parse filename and try to get request time from filename  | 
            ||
| 453 | *  | 
            ||
| 454 | * @param $fileName  | 
            ||
| 455 | * @return bool|DateTime  | 
            ||
| 456 | */  | 
            ||
| 457 | public function getRequestTimeFromFilename($fileName)  | 
            ||
| 469 | }  | 
            ||
| 470 | 
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: