| Total Complexity | 53 |
| Total Lines | 574 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like Config 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.
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 Config, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 13 | class Config extends ConfigurationOption |
||
| 14 | { |
||
| 15 | protected const DEFAULT_VALUE = '_default'; |
||
| 16 | protected const DEFAULT_HOST = '127.0.0.1'; |
||
| 17 | |||
| 18 | protected string $username = ''; |
||
| 19 | protected string $password = ''; |
||
| 20 | protected string $bucketName = self::DEFAULT_VALUE; |
||
| 21 | protected string $scopeName = self::DEFAULT_VALUE; |
||
| 22 | protected string $collectionName = self::DEFAULT_VALUE; |
||
| 23 | |||
| 24 | protected array $servers = []; |
||
| 25 | |||
| 26 | protected bool $secure = false; |
||
| 27 | |||
| 28 | protected ClusterOptions $clusterOptions; |
||
| 29 | |||
| 30 | public function __construct(array $parameters = []) |
||
| 31 | { |
||
| 32 | parent::__construct($parameters); |
||
| 33 | $this->clusterOptions = new ClusterOptions(); |
||
| 34 | } |
||
| 35 | |||
| 36 | |||
| 37 | public function getServers(): array |
||
| 38 | { |
||
| 39 | return $this->servers ?: [self::DEFAULT_HOST]; |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @param array $servers |
||
| 44 | * @return $this |
||
| 45 | * @throws PhpfastcacheLogicException |
||
| 46 | */ |
||
| 47 | public function setServers(array $servers): Config |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @param string $host |
||
| 57 | * @param int|null $port |
||
| 58 | * @return $this |
||
| 59 | * @throws PhpfastcacheLogicException |
||
| 60 | */ |
||
| 61 | public function addServer(string $host, ?int $port = null): Config |
||
| 62 | { |
||
| 63 | $this->enforceLockedProperty(__FUNCTION__); |
||
| 64 | $this->servers[] = $host . ($port ? ':' . $port : ''); |
||
| 65 | return $this; |
||
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @param bool $secure |
||
| 70 | * @return $this |
||
| 71 | * @throws PhpfastcacheLogicException |
||
| 72 | */ |
||
| 73 | public function setSecure(bool $secure): Config |
||
| 74 | { |
||
| 75 | $this->enforceLockedProperty(__FUNCTION__); |
||
| 76 | $this->secure = $secure; |
||
| 77 | return $this; |
||
| 78 | } |
||
| 79 | |||
| 80 | public function getSecure(): bool |
||
| 81 | { |
||
| 82 | return $this->secure; |
||
| 83 | } |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @return string |
||
| 87 | */ |
||
| 88 | public function getUsername(): string |
||
| 89 | { |
||
| 90 | return $this->username; |
||
| 91 | } |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @param string $username |
||
| 95 | * @return Config |
||
| 96 | * @throws PhpfastcacheLogicException |
||
| 97 | */ |
||
| 98 | public function setUsername(string $username): Config |
||
| 99 | { |
||
| 100 | $this->enforceLockedProperty(__FUNCTION__); |
||
| 101 | $this->username = $username; |
||
| 102 | return $this; |
||
| 103 | } |
||
| 104 | |||
| 105 | /** |
||
| 106 | * @return string |
||
| 107 | */ |
||
| 108 | public function getPassword(): string |
||
| 109 | { |
||
| 110 | return $this->password; |
||
| 111 | } |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @param string $password |
||
| 115 | * @return Config |
||
| 116 | * @throws PhpfastcacheLogicException |
||
| 117 | */ |
||
| 118 | public function setPassword(string $password): Config |
||
| 119 | { |
||
| 120 | $this->enforceLockedProperty(__FUNCTION__); |
||
| 121 | $this->password = $password; |
||
| 122 | return $this; |
||
| 123 | } |
||
| 124 | |||
| 125 | /** |
||
| 126 | * @return string |
||
| 127 | */ |
||
| 128 | public function getBucketName(): string |
||
| 129 | { |
||
| 130 | return $this->bucketName; |
||
| 131 | } |
||
| 132 | |||
| 133 | /** |
||
| 134 | * @param string $bucketName |
||
| 135 | * @return Config |
||
| 136 | * @throws PhpfastcacheLogicException |
||
| 137 | */ |
||
| 138 | public function setBucketName(string $bucketName): Config |
||
| 139 | { |
||
| 140 | $this->enforceLockedProperty(__FUNCTION__); |
||
| 141 | $this->bucketName = $bucketName; |
||
| 142 | return $this; |
||
| 143 | } |
||
| 144 | /** |
||
| 145 | * @return string |
||
| 146 | */ |
||
| 147 | public function getScopeName(): string |
||
| 148 | { |
||
| 149 | return $this->scopeName; |
||
| 150 | } |
||
| 151 | |||
| 152 | /** |
||
| 153 | * @param string $scopeName |
||
| 154 | * @return Config |
||
| 155 | * @throws PhpfastcacheLogicException |
||
| 156 | */ |
||
| 157 | public function setScopeName(string $scopeName): Config |
||
| 158 | { |
||
| 159 | $this->enforceLockedProperty(__FUNCTION__); |
||
| 160 | $this->scopeName = $scopeName; |
||
| 161 | return $this; |
||
| 162 | } |
||
| 163 | |||
| 164 | /** |
||
| 165 | * @return string |
||
| 166 | */ |
||
| 167 | public function getCollectionName(): string |
||
| 168 | { |
||
| 169 | return $this->collectionName; |
||
| 170 | } |
||
| 171 | |||
| 172 | /** |
||
| 173 | * @param string $collectionName |
||
| 174 | * @return Config |
||
| 175 | * @throws PhpfastcacheLogicException |
||
| 176 | */ |
||
| 177 | public function setCollectionName(string $collectionName): Config |
||
| 178 | { |
||
| 179 | $this->enforceLockedProperty(__FUNCTION__); |
||
| 180 | $this->collectionName = $collectionName; |
||
| 181 | return $this; |
||
| 182 | } |
||
| 183 | |||
| 184 | /*************************************************************************/ |
||
| 185 | /*************************************************************************/ |
||
| 186 | /*************************************************************************/ |
||
| 187 | |||
| 188 | public function getClusterOptions(): ClusterOptions |
||
| 189 | { |
||
| 190 | return $this->clusterOptions; |
||
| 191 | } |
||
| 192 | |||
| 193 | /** |
||
| 194 | * @param int $milliseconds |
||
| 195 | * @return Config |
||
| 196 | * @throws PhpfastcacheLogicException |
||
| 197 | */ |
||
| 198 | public function setAnalyticsTimeout(int $milliseconds): Config |
||
| 199 | { |
||
| 200 | $this->enforceLockedProperty(__FUNCTION__); |
||
| 201 | $this->clusterOptions->analyticsTimeout($milliseconds); |
||
| 202 | return $this; |
||
| 203 | } |
||
| 204 | |||
| 205 | /** |
||
| 206 | * @param int $milliseconds |
||
| 207 | * @return Config |
||
| 208 | * @throws PhpfastcacheLogicException |
||
| 209 | */ |
||
| 210 | public function setBootstrapTimeout(int $milliseconds): Config |
||
| 211 | { |
||
| 212 | $this->enforceLockedProperty(__FUNCTION__); |
||
| 213 | $this->clusterOptions->bootstrapTimeout($milliseconds); |
||
| 214 | return $this; |
||
| 215 | } |
||
| 216 | |||
| 217 | /** |
||
| 218 | * @param int $milliseconds |
||
| 219 | * @return Config |
||
| 220 | * @throws PhpfastcacheLogicException |
||
| 221 | */ |
||
| 222 | public function setConnectTimeout(int $milliseconds): Config |
||
| 223 | { |
||
| 224 | $this->enforceLockedProperty(__FUNCTION__); |
||
| 225 | $this->clusterOptions->connectTimeout($milliseconds); |
||
| 226 | return $this; |
||
| 227 | } |
||
| 228 | |||
| 229 | /** |
||
| 230 | * @param int $milliseconds |
||
| 231 | * @return Config |
||
| 232 | * @throws PhpfastcacheLogicException |
||
| 233 | */ |
||
| 234 | public function setDnsSrvTimeout(int $milliseconds): Config |
||
| 235 | { |
||
| 236 | $this->enforceLockedProperty(__FUNCTION__); |
||
| 237 | $this->clusterOptions->dnsSrvTimeout($milliseconds); |
||
| 238 | return $this; |
||
| 239 | } |
||
| 240 | |||
| 241 | /** |
||
| 242 | * @param int $milliseconds |
||
| 243 | * @return Config |
||
| 244 | * @throws PhpfastcacheLogicException |
||
| 245 | */ |
||
| 246 | public function setKeyValueDurableTimeout(int $milliseconds): Config |
||
| 247 | { |
||
| 248 | $this->enforceLockedProperty(__FUNCTION__); |
||
| 249 | $this->clusterOptions->keyValueDurableTimeout($milliseconds); |
||
| 250 | return $this; |
||
| 251 | } |
||
| 252 | |||
| 253 | /** |
||
| 254 | * @param int $milliseconds |
||
| 255 | * @return Config |
||
| 256 | * @throws PhpfastcacheLogicException |
||
| 257 | */ |
||
| 258 | public function setKeyValueTimeout(int $milliseconds): Config |
||
| 259 | { |
||
| 260 | $this->enforceLockedProperty(__FUNCTION__); |
||
| 261 | $this->clusterOptions->keyValueTimeout($milliseconds); |
||
| 262 | return $this; |
||
| 263 | } |
||
| 264 | |||
| 265 | /** |
||
| 266 | * @param int $milliseconds |
||
| 267 | * @return Config |
||
| 268 | * @throws PhpfastcacheLogicException |
||
| 269 | */ |
||
| 270 | public function setManagementTimeout(int $milliseconds): Config |
||
| 271 | { |
||
| 272 | $this->enforceLockedProperty(__FUNCTION__); |
||
| 273 | $this->clusterOptions->managementTimeout($milliseconds); |
||
| 274 | return $this; |
||
| 275 | } |
||
| 276 | |||
| 277 | /** |
||
| 278 | * @param int $milliseconds |
||
| 279 | * @return Config |
||
| 280 | * @throws PhpfastcacheLogicException |
||
| 281 | */ |
||
| 282 | public function setQueryTimeout(int $milliseconds): Config |
||
| 283 | { |
||
| 284 | $this->enforceLockedProperty(__FUNCTION__); |
||
| 285 | $this->clusterOptions->queryTimeout($milliseconds); |
||
| 286 | return $this; |
||
| 287 | } |
||
| 288 | |||
| 289 | /** |
||
| 290 | * @param int $milliseconds |
||
| 291 | * @return Config |
||
| 292 | * @throws PhpfastcacheLogicException |
||
| 293 | */ |
||
| 294 | public function setResolveTimeout(int $milliseconds): Config |
||
| 295 | { |
||
| 296 | $this->enforceLockedProperty(__FUNCTION__); |
||
| 297 | $this->clusterOptions->resolveTimeout($milliseconds); |
||
| 298 | return $this; |
||
| 299 | } |
||
| 300 | |||
| 301 | /** |
||
| 302 | * @param int $milliseconds |
||
| 303 | * @return Config |
||
| 304 | * @throws PhpfastcacheLogicException |
||
| 305 | */ |
||
| 306 | public function setSearchTimeout(int $milliseconds): Config |
||
| 307 | { |
||
| 308 | $this->enforceLockedProperty(__FUNCTION__); |
||
| 309 | $this->clusterOptions->searchTimeout($milliseconds); |
||
| 310 | return $this; |
||
| 311 | } |
||
| 312 | |||
| 313 | /** |
||
| 314 | * @param int $milliseconds |
||
| 315 | * @return Config |
||
| 316 | * @throws PhpfastcacheLogicException |
||
| 317 | */ |
||
| 318 | public function setViewTimeout(int $milliseconds): Config |
||
| 319 | { |
||
| 320 | $this->enforceLockedProperty(__FUNCTION__); |
||
| 321 | $this->clusterOptions->viewTimeout($milliseconds); |
||
| 322 | return $this; |
||
| 323 | } |
||
| 324 | |||
| 325 | /** |
||
| 326 | * @param int $numberOfConnections |
||
| 327 | * @return Config |
||
| 328 | * @throws PhpfastcacheLogicException |
||
| 329 | */ |
||
| 330 | public function setMaxHttpConnections(int $numberOfConnections): Config |
||
| 331 | { |
||
| 332 | $this->enforceLockedProperty(__FUNCTION__); |
||
| 333 | $this->clusterOptions->maxHttpConnections($numberOfConnections); |
||
| 334 | return $this; |
||
| 335 | } |
||
| 336 | |||
| 337 | /** |
||
| 338 | * @param int $milliseconds |
||
| 339 | * @return Config |
||
| 340 | * @throws PhpfastcacheLogicException |
||
| 341 | */ |
||
| 342 | public function setConfigIdleRedialTimeout(int $milliseconds): Config |
||
| 343 | { |
||
| 344 | $this->enforceLockedProperty(__FUNCTION__); |
||
| 345 | $this->clusterOptions->configIdleRedialTimeout($milliseconds); |
||
| 346 | return $this; |
||
| 347 | } |
||
| 348 | |||
| 349 | /** |
||
| 350 | * @param int $milliseconds |
||
| 351 | * @return Config |
||
| 352 | * @throws PhpfastcacheLogicException |
||
| 353 | */ |
||
| 354 | public function setConfigPollFloor(int $milliseconds): Config |
||
| 355 | { |
||
| 356 | $this->enforceLockedProperty(__FUNCTION__); |
||
| 357 | $this->clusterOptions->configPollFloor($milliseconds); |
||
| 358 | return $this; |
||
| 359 | } |
||
| 360 | |||
| 361 | /** |
||
| 362 | * @param int $milliseconds |
||
| 363 | * @return Config |
||
| 364 | * @throws PhpfastcacheLogicException |
||
| 365 | */ |
||
| 366 | public function setConfigPollInterval(int $milliseconds): Config |
||
| 367 | { |
||
| 368 | $this->enforceLockedProperty(__FUNCTION__); |
||
| 369 | $this->clusterOptions->configPollInterval($milliseconds); |
||
| 370 | return $this; |
||
| 371 | } |
||
| 372 | |||
| 373 | /** |
||
| 374 | * @param int $milliseconds |
||
| 375 | * @return Config |
||
| 376 | * @throws PhpfastcacheLogicException |
||
| 377 | */ |
||
| 378 | public function setTcpKeepAliveInterval(int $milliseconds): Config |
||
| 379 | { |
||
| 380 | $this->enforceLockedProperty(__FUNCTION__); |
||
| 381 | $this->clusterOptions->tcpKeepAliveInterval($milliseconds); |
||
| 382 | return $this; |
||
| 383 | } |
||
| 384 | |||
| 385 | /** |
||
| 386 | * @param bool $enable |
||
| 387 | * @return Config |
||
| 388 | * @throws PhpfastcacheLogicException |
||
| 389 | */ |
||
| 390 | public function setEnableClustermapNotification(bool $enable): Config |
||
| 391 | { |
||
| 392 | $this->enforceLockedProperty(__FUNCTION__); |
||
| 393 | $this->clusterOptions->enableClustermapNotification($enable); |
||
| 394 | return $this; |
||
| 395 | } |
||
| 396 | |||
| 397 | /** |
||
| 398 | * @param bool $enable |
||
| 399 | * @return Config |
||
| 400 | * @throws PhpfastcacheLogicException |
||
| 401 | */ |
||
| 402 | public function setEnableCompression(bool $enable): Config |
||
| 403 | { |
||
| 404 | $this->enforceLockedProperty(__FUNCTION__); |
||
| 405 | $this->clusterOptions->enableCompression($enable); |
||
| 406 | return $this; |
||
| 407 | } |
||
| 408 | |||
| 409 | /** |
||
| 410 | * @param bool $enable |
||
| 411 | * @return Config |
||
| 412 | * @throws PhpfastcacheLogicException |
||
| 413 | */ |
||
| 414 | public function setEnableDnsSrv(bool $enable): Config |
||
| 415 | { |
||
| 416 | $this->enforceLockedProperty(__FUNCTION__); |
||
| 417 | $this->clusterOptions->enableDnsSrv($enable); |
||
| 418 | return $this; |
||
| 419 | } |
||
| 420 | |||
| 421 | /** |
||
| 422 | * @param bool $enable |
||
| 423 | * @return Config |
||
| 424 | * @throws PhpfastcacheLogicException |
||
| 425 | */ |
||
| 426 | public function setEnableMetrics(bool $enable): Config |
||
| 427 | { |
||
| 428 | $this->enforceLockedProperty(__FUNCTION__); |
||
| 429 | $this->clusterOptions->enableMetrics($enable); |
||
| 430 | return $this; |
||
| 431 | } |
||
| 432 | |||
| 433 | /** |
||
| 434 | * @param bool $enable |
||
| 435 | * @return Config |
||
| 436 | * @throws PhpfastcacheLogicException |
||
| 437 | */ |
||
| 438 | public function setEnableMutationTokens(bool $enable): Config |
||
| 439 | { |
||
| 440 | $this->enforceLockedProperty(__FUNCTION__); |
||
| 441 | $this->clusterOptions->enableMutationTokens($enable); |
||
| 442 | return $this; |
||
| 443 | } |
||
| 444 | |||
| 445 | /** |
||
| 446 | * @param bool $enable |
||
| 447 | * @return Config |
||
| 448 | * @throws PhpfastcacheLogicException |
||
| 449 | */ |
||
| 450 | public function setEnableTcpKeepAlive(bool $enable): Config |
||
| 451 | { |
||
| 452 | $this->enforceLockedProperty(__FUNCTION__); |
||
| 453 | $this->clusterOptions->enableTcpKeepAlive($enable); |
||
| 454 | return $this; |
||
| 455 | } |
||
| 456 | |||
| 457 | /** |
||
| 458 | * @param bool $enable |
||
| 459 | * @return Config |
||
| 460 | * @throws PhpfastcacheLogicException |
||
| 461 | */ |
||
| 462 | public function setEnableTls(bool $enable): Config |
||
| 463 | { |
||
| 464 | $this->enforceLockedProperty(__FUNCTION__); |
||
| 465 | $this->clusterOptions->enableTls($enable); |
||
| 466 | return $this; |
||
| 467 | } |
||
| 468 | |||
| 469 | /** |
||
| 470 | * @param bool $enable |
||
| 471 | * @return Config |
||
| 472 | * @throws PhpfastcacheLogicException |
||
| 473 | */ |
||
| 474 | public function setEnableTracing(bool $enable): Config |
||
| 475 | { |
||
| 476 | $this->enforceLockedProperty(__FUNCTION__); |
||
| 477 | $this->clusterOptions->enableTracing($enable); |
||
| 478 | return $this; |
||
| 479 | } |
||
| 480 | |||
| 481 | /** |
||
| 482 | * @param bool $enable |
||
| 483 | * @return Config |
||
| 484 | * @throws PhpfastcacheLogicException |
||
| 485 | */ |
||
| 486 | public function setEnableUnorderedExecution(bool $enable): Config |
||
| 487 | { |
||
| 488 | $this->enforceLockedProperty(__FUNCTION__); |
||
| 489 | $this->clusterOptions->enableUnorderedExecution($enable); |
||
| 490 | return $this; |
||
| 491 | } |
||
| 492 | |||
| 493 | /** |
||
| 494 | * @param string $mode "any", "forceIpv4" or "forceIpv6" |
||
| 495 | * @return Config |
||
| 496 | * @throws PhpfastcacheLogicException |
||
| 497 | */ |
||
| 498 | public function setUseIpProtocol(string $mode): Config |
||
| 499 | { |
||
| 500 | $this->enforceLockedProperty(__FUNCTION__); |
||
| 501 | $this->clusterOptions->useIpProtocol($mode); |
||
| 502 | return $this; |
||
| 503 | } |
||
| 504 | |||
| 505 | /** |
||
| 506 | * @param bool $enable |
||
| 507 | * @return Config |
||
| 508 | * @throws PhpfastcacheLogicException |
||
| 509 | */ |
||
| 510 | public function setShowQueries(bool $enable): Config |
||
| 511 | { |
||
| 512 | $this->enforceLockedProperty(__FUNCTION__); |
||
| 513 | $this->clusterOptions->showQueries($enable); |
||
| 514 | return $this; |
||
| 515 | } |
||
| 516 | |||
| 517 | /** |
||
| 518 | * @param string $networkSelector |
||
| 519 | * @return Config |
||
| 520 | * @throws PhpfastcacheLogicException |
||
| 521 | */ |
||
| 522 | public function setNetwork(string $networkSelector): Config |
||
| 523 | { |
||
| 524 | $this->enforceLockedProperty(__FUNCTION__); |
||
| 525 | $this->clusterOptions->network($networkSelector); |
||
| 526 | return $this; |
||
| 527 | } |
||
| 528 | |||
| 529 | /** |
||
| 530 | * @param string $certificatePath |
||
| 531 | * @return Config |
||
| 532 | * @throws PhpfastcacheLogicException |
||
| 533 | */ |
||
| 534 | public function setTrustCertificate(string $certificatePath): Config |
||
| 535 | { |
||
| 536 | $this->enforceLockedProperty(__FUNCTION__); |
||
| 537 | $this->clusterOptions->trustCertificate($certificatePath); |
||
| 538 | return $this; |
||
| 539 | } |
||
| 540 | |||
| 541 | /** |
||
| 542 | * @param string $userAgentExtraString |
||
| 543 | * @return Config |
||
| 544 | * @throws PhpfastcacheLogicException |
||
| 545 | */ |
||
| 546 | public function setUserAgentExtra(string $userAgentExtraString): Config |
||
| 551 | } |
||
| 552 | |||
| 553 | /** |
||
| 554 | * @param string $mode |
||
| 555 | * @return Config |
||
| 556 | * @throws PhpfastcacheLogicException |
||
| 557 | */ |
||
| 558 | public function setTlsVerify(string $mode): Config |
||
| 559 | { |
||
| 560 | $this->enforceLockedProperty(__FUNCTION__); |
||
| 561 | $this->clusterOptions->tlsVerify($mode); |
||
| 562 | return $this; |
||
| 563 | } |
||
| 564 | |||
| 565 | /** |
||
| 566 | * @param ThresholdLoggingOptions $options |
||
| 567 | * @return Config |
||
| 568 | * @throws PhpfastcacheLogicException |
||
| 569 | */ |
||
| 570 | public function setThresholdLoggingTracerOptions(ThresholdLoggingOptions $options): Config |
||
| 571 | { |
||
| 572 | $this->enforceLockedProperty(__FUNCTION__); |
||
| 573 | $this->clusterOptions->thresholdLoggingTracerOptions($options); |
||
| 574 | return $this; |
||
| 575 | } |
||
| 576 | |||
| 577 | /** |
||
| 578 | * @param TransactionsConfiguration $options |
||
| 579 | * @return Config |
||
| 580 | * @throws PhpfastcacheLogicException |
||
| 581 | */ |
||
| 582 | public function setTransactionsConfiguration(TransactionsConfiguration $options): Config |
||
| 583 | { |
||
| 584 | $this->enforceLockedProperty(__FUNCTION__); |
||
| 585 | $this->clusterOptions->transactionsConfiguration($options); |
||
| 586 | return $this; |
||
| 587 | } |
||
| 588 | } |
||
| 589 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths