Complex classes like LaravelLogViewer 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 LaravelLogViewer, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 9 | class LaravelLogViewer |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @var string file |
||
| 13 | */ |
||
| 14 | private $file; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @var string folder |
||
| 18 | */ |
||
| 19 | private $folder; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var string storage_path |
||
| 23 | */ |
||
| 24 | private $storage_path; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Why? Uh... Sorry |
||
| 28 | */ |
||
| 29 | const MAX_FILE_SIZE = 52428800; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var Level level |
||
| 33 | */ |
||
| 34 | private $level; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var Pattern pattern |
||
| 38 | */ |
||
| 39 | private $pattern; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * LaravelLogViewer constructor. |
||
| 43 | */ |
||
| 44 | public function __construct() |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @param string $folder |
||
| 55 | */ |
||
| 56 | public function setFolder($folder) |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @param string $file |
||
| 67 | * @throws \Exception |
||
| 68 | */ |
||
| 69 | public function setFile($file) |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @param string $file |
||
| 80 | * @return string |
||
| 81 | * @throws \Exception |
||
| 82 | */ |
||
| 83 | public function pathToLogFile($file) |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @return string |
||
| 110 | */ |
||
| 111 | public function getFolderName() |
||
| 115 | |||
| 116 | /** |
||
| 117 | * @return string |
||
| 118 | */ |
||
| 119 | public function getFileName() |
||
| 123 | |||
| 124 | /** |
||
| 125 | * @return array |
||
| 126 | */ |
||
| 127 | public function all() |
||
| 204 | |||
| 205 | /** |
||
| 206 | * @return array |
||
| 207 | */ |
||
| 208 | public function getFolders() |
||
| 231 | |||
| 232 | /** |
||
| 233 | * @param bool $basename |
||
| 234 | * @return array |
||
| 235 | */ |
||
| 236 | public function getFolderFiles($basename = false) |
||
| 240 | |||
| 241 | /** |
||
| 242 | * @param bool $basename |
||
| 243 | * @param string $folder |
||
| 244 | * @return array |
||
| 245 | */ |
||
| 246 | public function getFiles($basename = false, $folder = '') |
||
| 278 | } |
||
| 279 |