| Conditions | 15 |
| Paths | 25 |
| Total Lines | 42 |
| Code Lines | 25 |
| 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 |
||
| 72 | public function validate(): void |
||
| 73 | { |
||
| 74 | if (!empty($this->host)) { |
||
| 75 | $ip = gethostbyname($this->host); |
||
| 76 | if (false === filter_var($ip, FILTER_VALIDATE_IP)) { |
||
| 77 | throw new ConfigException(ConfigException::IP_ERROR_MESSAGE, ConfigException::IP_ERROR_CODE); |
||
| 78 | } |
||
| 79 | } |
||
| 80 | if (!empty($this->port) && false === filter_var( |
||
| 81 | $this->port, FILTER_VALIDATE_INT, ['options' => ['min_range' => 0]] |
||
| 82 | )) { |
||
| 83 | throw new ConfigException(ConfigException::PORT_ERROR_MESSAGE, ConfigException::PORT_ERROR_CODE); |
||
| 84 | } |
||
| 85 | if (!empty($this->gtid)) { |
||
| 86 | foreach (explode(',', $this->gtid) as $gtid) { |
||
| 87 | if (!(bool)preg_match( |
||
| 88 | '/^([0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12})((?::[0-9-]+)+)$/', $gtid, $matches |
||
| 89 | )) { |
||
| 90 | throw new ConfigException(ConfigException::GTID_ERROR_MESSAGE, ConfigException::GTID_ERROR_CODE); |
||
| 91 | } |
||
| 92 | } |
||
| 93 | } |
||
| 94 | if (!empty($this->slaveId) && false === filter_var( |
||
| 95 | $this->slaveId, FILTER_VALIDATE_INT, ['options' => ['min_range' => 0]] |
||
| 96 | )) { |
||
| 97 | throw new ConfigException(ConfigException::SLAVE_ID_ERROR_MESSAGE, ConfigException::SLAVE_ID_ERROR_CODE); |
||
| 98 | } |
||
| 99 | if (false === filter_var($this->binLogPosition, FILTER_VALIDATE_INT, ['options' => ['min_range' => 0]])) { |
||
| 100 | throw new ConfigException( |
||
| 101 | ConfigException::BIN_LOG_FILE_POSITION_ERROR_MESSAGE, ConfigException::BIN_LOG_FILE_POSITION_ERROR_CODE |
||
| 102 | ); |
||
| 103 | } |
||
| 104 | if (false === filter_var($this->tableCacheSize, FILTER_VALIDATE_INT, ['options' => ['min_range' => 0]])) { |
||
| 105 | throw new ConfigException( |
||
| 106 | ConfigException::TABLE_CACHE_SIZE_ERROR_MESSAGE, ConfigException::TABLE_CACHE_SIZE_ERROR_CODE |
||
| 107 | ); |
||
| 108 | } |
||
| 109 | if (0.0 !== $this->heartbeatPeriod && false === ( |
||
| 110 | $this->heartbeatPeriod >= 0.001 && $this->heartbeatPeriod <= 4294967.0 |
||
| 111 | )) { |
||
| 112 | throw new ConfigException( |
||
| 113 | ConfigException::HEARTBEAT_PERIOD_ERROR_MESSAGE, ConfigException::HEARTBEAT_PERIOD_ERROR_CODE |
||
| 114 | ); |
||
| 235 | } |