| Conditions | 12 |
| Paths | 384 |
| Total Lines | 59 |
| 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 |
||
| 13 | /** |
||
| 14 | * Xcloner_Logger constructor. |
||
| 15 | * @param Xcloner $xcloner_container |
||
| 16 | * @param string $logger_name |
||
| 17 | * @throws Exception |
||
| 18 | */ |
||
| 19 | public function __construct(Xcloner $xcloner_container, $logger_name = "xcloner_logger") { |
||
| 20 | if (!$xcloner_container->get_xcloner_settings()) { |
||
| 21 | $xcloner_settings = new Xcloner_Settings($xcloner_container); |
||
| 22 | } else { |
||
| 23 | $xcloner_settings = $xcloner_container->get_xcloner_settings(); |
||
| 24 | } |
||
| 25 | |||
| 26 | $hash = $xcloner_settings->get_hash(); |
||
| 27 | if ($hash == "-".$xcloner_settings->get_server_unique_hash(5)) { |
||
| 28 | $hash = ""; |
||
| 29 | } |
||
| 30 | |||
| 31 | $logger_path = $xcloner_settings->get_xcloner_store_path().DS.$xcloner_settings->get_logger_filename(); |
||
| 32 | $logger_path_tmp = ""; |
||
| 33 | |||
| 34 | if ($hash) { |
||
| 35 | $logger_path_tmp = $xcloner_settings->get_xcloner_tmp_path().DS.$xcloner_settings->get_logger_filename(1); |
||
| 36 | } |
||
| 37 | |||
| 38 | $this->logger_path = $logger_path; |
||
| 39 | |||
| 40 | if (!is_dir($xcloner_settings->get_xcloner_store_path()) or !is_writable($xcloner_settings->get_xcloner_store_path())) { |
||
| 41 | $logger_path = 'php://stderr'; |
||
| 42 | $logger_path_tmp = ""; |
||
| 43 | } |
||
| 44 | |||
| 45 | if (!$xcloner_settings->get_xcloner_option('xcloner_enable_log')) { |
||
| 46 | $logger_path = 'php://stderr'; |
||
| 47 | $logger_path_tmp = ""; |
||
| 48 | } |
||
| 49 | |||
| 50 | // create a log channel |
||
| 51 | parent::__construct($logger_name); |
||
| 52 | |||
| 53 | $debug_level = Logger::INFO; |
||
| 54 | |||
| 55 | if (WP_DEBUG) { |
||
| 56 | $debug_level = Logger::DEBUG; |
||
| 57 | } |
||
| 58 | |||
| 59 | |||
| 60 | if ($logger_path) { |
||
| 61 | if (!$xcloner_settings->get_xcloner_option('xcloner_enable_log')) { |
||
| 62 | $stream = new StreamHandler($logger_path, $debug_level); |
||
| 63 | } else { |
||
| 64 | $stream = new RotatingFileHandler($logger_path, $this->max_logger_files, $debug_level); |
||
| 65 | } |
||
| 66 | |||
| 67 | $this->pushHandler($stream); |
||
| 68 | |||
| 69 | $this->main_logger_url = $stream->getUrl(); |
||
| 70 | } |
||
| 71 | |||
| 72 | if ($hash and $logger_path_tmp) { |
||
| 123 |
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.