Complex classes like FileStorage 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 FileStorage, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 11 | class FileStorage extends AbstractStorage { |
||
| 12 | var $folder; |
||
| 13 | protected $_multi_folder = false; |
||
| 14 | const ERROR_CODE = 100; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @param KeyValueSettings|object $settings |
||
| 18 | * |
||
| 19 | * @throws KeyValueException |
||
| 20 | */ |
||
| 21 | 180 | function __construct($settings) { |
|
| 46 | |||
| 47 | /** |
||
| 48 | * @param string $key Название ключа |
||
| 49 | * @param mixed $value Новое значение |
||
| 50 | * @param double|integer $ttl Кол-во секунд, после которых значение будет считаться просроченным |
||
| 51 | * |
||
| 52 | * @throws KeyValueException |
||
| 53 | */ |
||
| 54 | 66 | function set_value($key, $value, $ttl = 315576000) { |
|
| 76 | |||
| 77 | /** |
||
| 78 | * Создаём папку |
||
| 79 | * |
||
| 80 | * @param string $folder |
||
| 81 | * @param boolean $multi_folder |
||
| 82 | * @param string $key |
||
| 83 | * |
||
| 84 | * @throws KeyValueException |
||
| 85 | */ |
||
| 86 | 72 | protected static function create_path($folder, $multi_folder, $key) { |
|
| 112 | |||
| 113 | /** |
||
| 114 | * @param string $key |
||
| 115 | * |
||
| 116 | * @return object|null |
||
| 117 | */ |
||
| 118 | 72 | protected function get_value_full_clear($key) { |
|
| 136 | |||
| 137 | /** |
||
| 138 | * @param string $key |
||
| 139 | * |
||
| 140 | * @return string |
||
| 141 | */ |
||
| 142 | 168 | function get_filename($key) { |
|
| 145 | |||
| 146 | 72 | function get_folder($key) { |
|
| 155 | |||
| 156 | /** |
||
| 157 | * Key for NokitaKaze\Mutex\MutexInterface |
||
| 158 | * |
||
| 159 | * @param string $key |
||
| 160 | * |
||
| 161 | * @return string |
||
| 162 | */ |
||
| 163 | 168 | function get_mutex_key_name($key) { |
|
| 167 | |||
| 168 | /** |
||
| 169 | * Создаём мьютекс, соответствующий ключу и кладём его в _locks |
||
| 170 | * |
||
| 171 | * @param string $key |
||
| 172 | */ |
||
| 173 | 72 | protected function create_lock($key) { |
|
| 181 | |||
| 182 | /** |
||
| 183 | * @param string $key |
||
| 184 | */ |
||
| 185 | 30 | function delete_value($key) { |
|
| 198 | |||
| 199 | /** |
||
| 200 | * Санация части regexp для добавления напрямую в regexp |
||
| 201 | * |
||
| 202 | * @param string $text Часть, которую над санировать |
||
| 203 | * |
||
| 204 | * @return string |
||
| 205 | * @codeCoverageIgnore |
||
| 206 | */ |
||
| 207 | protected static function sad_safe_reg($text) { |
||
| 220 | |||
| 221 | 24 | protected function delete_all_files_in_folder($folder) { |
|
| 230 | |||
| 231 | 30 | function clear() { |
|
| 265 | } |
||
| 266 | |||
| 267 | ?> |
||
|
1 ignored issue
–
show
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.