Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like ServerJsonConfiguration 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 ServerJsonConfiguration, and based on these observations, apply Extract Interface, too.
| 1 | <?php  | 
            ||
| 34 | class ServerJsonConfiguration implements ServerConfigurationInterface  | 
            ||
| 35 | { | 
            ||
| 36 | /**  | 
            ||
| 37 | * Holds raw data instance  | 
            ||
| 38 | *  | 
            ||
| 39 | * @var \stdClass  | 
            ||
| 40 | */  | 
            ||
| 41 | protected $data;  | 
            ||
| 42 | |||
| 43 | /**  | 
            ||
| 44 | * Holds the modules to be used  | 
            ||
| 45 | *  | 
            ||
| 46 | * @var array  | 
            ||
| 47 | */  | 
            ||
| 48 | protected $modules;  | 
            ||
| 49 | |||
| 50 | /**  | 
            ||
| 51 | * Holds the handlers array  | 
            ||
| 52 | *  | 
            ||
| 53 | * @var array  | 
            ||
| 54 | */  | 
            ||
| 55 | protected $handlers;  | 
            ||
| 56 | |||
| 57 | /**  | 
            ||
| 58 | * Holds the virtual hosts array  | 
            ||
| 59 | *  | 
            ||
| 60 | * @var array  | 
            ||
| 61 | */  | 
            ||
| 62 | protected $virtualHosts;  | 
            ||
| 63 | |||
| 64 | /**  | 
            ||
| 65 | * Holds the authentications array  | 
            ||
| 66 | *  | 
            ||
| 67 | * @var array  | 
            ||
| 68 | */  | 
            ||
| 69 | protected $authentications;  | 
            ||
| 70 | |||
| 71 | /**  | 
            ||
| 72 | * Holds the rewrites array  | 
            ||
| 73 | *  | 
            ||
| 74 | * @var array  | 
            ||
| 75 | */  | 
            ||
| 76 | protected $rewrites;  | 
            ||
| 77 | |||
| 78 | /**  | 
            ||
| 79 | * Holds the environmentVariables array  | 
            ||
| 80 | *  | 
            ||
| 81 | * @var array  | 
            ||
| 82 | */  | 
            ||
| 83 | protected $environmentVariables;  | 
            ||
| 84 | |||
| 85 | /**  | 
            ||
| 86 | * Holds the connection handlers array  | 
            ||
| 87 | *  | 
            ||
| 88 | * @var array  | 
            ||
| 89 | */  | 
            ||
| 90 | protected $connectionHandlers;  | 
            ||
| 91 | |||
| 92 | /**  | 
            ||
| 93 | * Holds the accesses array  | 
            ||
| 94 | *  | 
            ||
| 95 | * @var array  | 
            ||
| 96 | */  | 
            ||
| 97 | protected $accesses;  | 
            ||
| 98 | |||
| 99 | /**  | 
            ||
| 100 | * Holds the accesses array  | 
            ||
| 101 | *  | 
            ||
| 102 | * @var array  | 
            ||
| 103 | */  | 
            ||
| 104 | protected $analytics;  | 
            ||
| 105 | |||
| 106 | /**  | 
            ||
| 107 | * The configured locations.  | 
            ||
| 108 | *  | 
            ||
| 109 | * @var array  | 
            ||
| 110 | */  | 
            ||
| 111 | protected $locations;  | 
            ||
| 112 | |||
| 113 | /**  | 
            ||
| 114 | * The rewrite maps  | 
            ||
| 115 | *  | 
            ||
| 116 | * @var array  | 
            ||
| 117 | */  | 
            ||
| 118 | protected $rewriteMaps;  | 
            ||
| 119 | |||
| 120 | /**  | 
            ||
| 121 | * Constructs config  | 
            ||
| 122 | *  | 
            ||
| 123 | * @param \stdClass $data The data object use  | 
            ||
| 124 | */  | 
            ||
| 125 | public function __construct($data)  | 
            ||
| 129 | |||
| 130 | /**  | 
            ||
| 131 | * Returns name  | 
            ||
| 132 | *  | 
            ||
| 133 | * @return string  | 
            ||
| 134 | */  | 
            ||
| 135 | public function getName()  | 
            ||
| 139 | |||
| 140 | /**  | 
            ||
| 141 | * Returns logger name  | 
            ||
| 142 | *  | 
            ||
| 143 | * @return string  | 
            ||
| 144 | */  | 
            ||
| 145 | public function getLoggerName()  | 
            ||
| 149 | |||
| 150 | /**  | 
            ||
| 151 | * Returns type  | 
            ||
| 152 | *  | 
            ||
| 153 | * @return string  | 
            ||
| 154 | */  | 
            ||
| 155 | public function getType()  | 
            ||
| 159 | |||
| 160 | /**  | 
            ||
| 161 | * Returns transport  | 
            ||
| 162 | *  | 
            ||
| 163 | * @return string  | 
            ||
| 164 | */  | 
            ||
| 165 | public function getTransport()  | 
            ||
| 169 | |||
| 170 | /**  | 
            ||
| 171 | * Returns address  | 
            ||
| 172 | *  | 
            ||
| 173 | * @return string  | 
            ||
| 174 | */  | 
            ||
| 175 | public function getAddress()  | 
            ||
| 179 | |||
| 180 | /**  | 
            ||
| 181 | * Returns port  | 
            ||
| 182 | *  | 
            ||
| 183 | * @return int  | 
            ||
| 184 | */  | 
            ||
| 185 | public function getPort()  | 
            ||
| 189 | |||
| 190 | /**  | 
            ||
| 191 | * Returns flags  | 
            ||
| 192 | *  | 
            ||
| 193 | * @return string  | 
            ||
| 194 | */  | 
            ||
| 195 | public function getFlags()  | 
            ||
| 199 | |||
| 200 | /**  | 
            ||
| 201 | * Returns software  | 
            ||
| 202 | *  | 
            ||
| 203 | * @return string  | 
            ||
| 204 | */  | 
            ||
| 205 | public function getSoftware()  | 
            ||
| 209 | |||
| 210 | /**  | 
            ||
| 211 | * Returns admin  | 
            ||
| 212 | *  | 
            ||
| 213 | * @return string  | 
            ||
| 214 | */  | 
            ||
| 215 | public function getAdmin()  | 
            ||
| 219 | |||
| 220 | /**  | 
            ||
| 221 | * Returns keep-alive max connection  | 
            ||
| 222 | *  | 
            ||
| 223 | * @return int  | 
            ||
| 224 | */  | 
            ||
| 225 | public function getKeepAliveMax()  | 
            ||
| 229 | |||
| 230 | /**  | 
            ||
| 231 | * Returns keep-alive timeout  | 
            ||
| 232 | *  | 
            ||
| 233 | * @return int  | 
            ||
| 234 | */  | 
            ||
| 235 | public function getKeepAliveTimeout()  | 
            ||
| 239 | |||
| 240 | /**  | 
            ||
| 241 | * Returns admin  | 
            ||
| 242 | *  | 
            ||
| 243 | * @return string  | 
            ||
| 244 | */  | 
            ||
| 245 | public function getErrorsPageTemplatePath()  | 
            ||
| 249 | |||
| 250 | /**  | 
            ||
| 251 | * Returns template path for possible configured welcome page  | 
            ||
| 252 | *  | 
            ||
| 253 | * @return string  | 
            ||
| 254 | */  | 
            ||
| 255 | public function getWelcomePageTemplatePath()  | 
            ||
| 259 | |||
| 260 | /**  | 
            ||
| 261 | * Returns template path for possible configured auto index page  | 
            ||
| 262 | *  | 
            ||
| 263 | * @return string  | 
            ||
| 264 | */  | 
            ||
| 265 | public function getAutoIndexTemplatePath()  | 
            ||
| 269 | |||
| 270 | /**  | 
            ||
| 271 | * Returns worker number  | 
            ||
| 272 | *  | 
            ||
| 273 | * @return int  | 
            ||
| 274 | */  | 
            ||
| 275 | public function getWorkerNumber()  | 
            ||
| 279 | |||
| 280 | /**  | 
            ||
| 281 | * Returns worker's accept min count  | 
            ||
| 282 | *  | 
            ||
| 283 | * @return int  | 
            ||
| 284 | */  | 
            ||
| 285 | public function getWorkerAcceptMin()  | 
            ||
| 289 | |||
| 290 | /**  | 
            ||
| 291 | * Returns worker's accept min count  | 
            ||
| 292 | *  | 
            ||
| 293 | * @return int  | 
            ||
| 294 | */  | 
            ||
| 295 | public function getWorkerAcceptMax()  | 
            ||
| 299 | |||
| 300 | /**  | 
            ||
| 301 | * Returns the auto index configuration  | 
            ||
| 302 | *  | 
            ||
| 303 | * @return boolean  | 
            ||
| 304 | */  | 
            ||
| 305 | public function getAutoIndex()  | 
            ||
| 309 | |||
| 310 | /**  | 
            ||
| 311 | * Returns context type  | 
            ||
| 312 | *  | 
            ||
| 313 | * @return string  | 
            ||
| 314 | */  | 
            ||
| 315 | public function getServerContextType()  | 
            ||
| 319 | |||
| 320 | /**  | 
            ||
| 321 | * Returns stream context type  | 
            ||
| 322 | *  | 
            ||
| 323 | * @return string  | 
            ||
| 324 | */  | 
            ||
| 325 | public function getStreamContextType()  | 
            ||
| 329 | |||
| 330 | /**  | 
            ||
| 331 | * Returns request type  | 
            ||
| 332 | *  | 
            ||
| 333 | * @return string  | 
            ||
| 334 | */  | 
            ||
| 335 | public function getRequestContextType()  | 
            ||
| 339 | |||
| 340 | /**  | 
            ||
| 341 | * Returns socket type  | 
            ||
| 342 | *  | 
            ||
| 343 | * @return string  | 
            ||
| 344 | */  | 
            ||
| 345 | public function getSocketType()  | 
            ||
| 349 | |||
| 350 | /**  | 
            ||
| 351 | * Returns worker type  | 
            ||
| 352 | *  | 
            ||
| 353 | * @return string  | 
            ||
| 354 | */  | 
            ||
| 355 | public function getWorkerType()  | 
            ||
| 359 | |||
| 360 | /**  | 
            ||
| 361 | * Returns document root  | 
            ||
| 362 | *  | 
            ||
| 363 | * @return string  | 
            ||
| 364 | */  | 
            ||
| 365 | public function getDocumentRoot()  | 
            ||
| 369 | |||
| 370 | /**  | 
            ||
| 371 | * Returns directory index definition  | 
            ||
| 372 | *  | 
            ||
| 373 | * @return string  | 
            ||
| 374 | */  | 
            ||
| 375 | public function getDirectoryIndex()  | 
            ||
| 379 | |||
| 380 | /**  | 
            ||
| 381 | * Returns connection handlers  | 
            ||
| 382 | *  | 
            ||
| 383 | * @return array  | 
            ||
| 384 | */  | 
            ||
| 385 | public function getConnectionHandlers()  | 
            ||
| 386 |     { | 
            ||
| 387 |         if (!$this->connectionHandlers) { | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 388 | $this->connectionHandlers = $this->prepareConnectionHandlers($this->data);  | 
            ||
| 389 | }  | 
            ||
| 390 | return $this->connectionHandlers;  | 
            ||
| 391 | }  | 
            ||
| 392 | |||
| 393 | /**  | 
            ||
| 394 | * Returns the headers used by the server  | 
            ||
| 395 | *  | 
            ||
| 396 | * @return array  | 
            ||
| 397 | */  | 
            ||
| 398 | public function getHeaders()  | 
            ||
| 399 |     { | 
            ||
| 400 |         if (!$this->headers) { | 
            ||
| 401 | $this->headers = $this->prepareHeaders($this->data);  | 
            ||
| 402 | }  | 
            ||
| 403 | return $this->headers;  | 
            ||
| 404 | }  | 
            ||
| 405 | |||
| 406 | /**  | 
            ||
| 407 | * Returns the certificates used by the server  | 
            ||
| 408 | *  | 
            ||
| 409 | * @return array  | 
            ||
| 410 | */  | 
            ||
| 411 | public function getCertificates()  | 
            ||
| 412 |     { | 
            ||
| 413 |         if (!$this->certificates) { | 
            ||
| 414 | $this->certificates = $this->prepareCertificates($this->data);  | 
            ||
| 415 | }  | 
            ||
| 416 | return $this->certificates;  | 
            ||
| 417 | }  | 
            ||
| 418 | |||
| 419 | /**  | 
            ||
| 420 | * Returns the virtual hosts  | 
            ||
| 421 | *  | 
            ||
| 422 | * @return array  | 
            ||
| 423 | */  | 
            ||
| 424 | public function getVirtualHosts()  | 
            ||
| 425 |     { | 
            ||
| 426 |         if (!$this->virtualHosts) { | 
            ||
| 427 | $this->virtualHosts = $this->prepareVirtualHosts($this->data);  | 
            ||
| 428 | }  | 
            ||
| 429 | return $this->virtualHosts;  | 
            ||
| 430 | }  | 
            ||
| 431 | |||
| 432 | /**  | 
            ||
| 433 | * Returns the authentications  | 
            ||
| 434 | *  | 
            ||
| 435 | * @return array  | 
            ||
| 436 | */  | 
            ||
| 437 | public function getAuthentications()  | 
            ||
| 438 |     { | 
            ||
| 439 |         if (!$this->authentications) { | 
            ||
| 440 | $this->authentications = $this->prepareAuthentications($this->data);  | 
            ||
| 441 | }  | 
            ||
| 442 | return $this->authentications;  | 
            ||
| 443 | }  | 
            ||
| 444 | |||
| 445 | /**  | 
            ||
| 446 | * Returns modules  | 
            ||
| 447 | *  | 
            ||
| 448 | * @return array  | 
            ||
| 449 | */  | 
            ||
| 450 | public function getModules()  | 
            ||
| 451 |     { | 
            ||
| 452 |         if (!$this->modules) { | 
            ||
| 453 | $this->modules = $this->prepareModules($this->data);  | 
            ||
| 454 | }  | 
            ||
| 455 | return $this->modules;  | 
            ||
| 456 | }  | 
            ||
| 457 | |||
| 458 | /**  | 
            ||
| 459 | * Returns handlers  | 
            ||
| 460 | *  | 
            ||
| 461 | * @return array  | 
            ||
| 462 | */  | 
            ||
| 463 | public function getHandlers()  | 
            ||
| 464 |     { | 
            ||
| 465 |         if (!$this->handlers) { | 
            ||
| 466 | $this->handlers = $this->prepareHandlers($this->data);  | 
            ||
| 467 | }  | 
            ||
| 468 | return $this->handlers;  | 
            ||
| 469 | }  | 
            ||
| 470 | |||
| 471 | /**  | 
            ||
| 472 | * Returns cert path  | 
            ||
| 473 | *  | 
            ||
| 474 | * @return string  | 
            ||
| 475 | */  | 
            ||
| 476 | public function getCertPath()  | 
            ||
| 477 |     { | 
            ||
| 478 | return $this->data->certPath;  | 
            ||
| 479 | }  | 
            ||
| 480 | |||
| 481 | /**  | 
            ||
| 482 | * Returns passphrase  | 
            ||
| 483 | *  | 
            ||
| 484 | * @return string  | 
            ||
| 485 | */  | 
            ||
| 486 | public function getPassphrase()  | 
            ||
| 487 |     { | 
            ||
| 488 | return $this->data->passphrase;  | 
            ||
| 489 | }  | 
            ||
| 490 | |||
| 491 | /**  | 
            ||
| 492 | * Returns the rewrite configuration.  | 
            ||
| 493 | *  | 
            ||
| 494 | * @return array  | 
            ||
| 495 | */  | 
            ||
| 496 | public function getRewrites()  | 
            ||
| 497 |     { | 
            ||
| 498 | // init rewrites  | 
            ||
| 499 |         if (!$this->rewrites) { | 
            ||
| 500 | $this->rewrites = $this->prepareRewrites($this->data);  | 
            ||
| 501 | }  | 
            ||
| 502 | // return the rewrites  | 
            ||
| 503 | return $this->rewrites;  | 
            ||
| 504 | }  | 
            ||
| 505 | |||
| 506 | /**  | 
            ||
| 507 | * Returns the environment variable configuration  | 
            ||
| 508 | *  | 
            ||
| 509 | * @return array  | 
            ||
| 510 | */  | 
            ||
| 511 | public function getEnvironmentVariables()  | 
            ||
| 512 |     { | 
            ||
| 513 | // init EnvironmentVariables  | 
            ||
| 514 |         if (!$this->environmentVariables) { | 
            ||
| 515 | $this->environmentVariables = $this->prepareEnvironmentVariables($this->data);  | 
            ||
| 516 | }  | 
            ||
| 517 | // return the environmentVariables  | 
            ||
| 518 | return $this->environmentVariables;  | 
            ||
| 519 | }  | 
            ||
| 520 | |||
| 521 | /**  | 
            ||
| 522 | * Returns the accesses  | 
            ||
| 523 | *  | 
            ||
| 524 | * @return array  | 
            ||
| 525 | */  | 
            ||
| 526 | public function getAccesses()  | 
            ||
| 527 |     { | 
            ||
| 528 |         if (!$this->accesses) { | 
            ||
| 529 | $this->accesses = $this->prepareAccesses($this->data);  | 
            ||
| 530 | }  | 
            ||
| 531 | return $this->accesses;  | 
            ||
| 532 | }  | 
            ||
| 533 | |||
| 534 | /**  | 
            ||
| 535 | * Returns the analytics  | 
            ||
| 536 | *  | 
            ||
| 537 | * @return array  | 
            ||
| 538 | */  | 
            ||
| 539 | public function getAnalytics()  | 
            ||
| 540 |     { | 
            ||
| 541 |         if (!$this->analytics) { | 
            ||
| 542 | $this->analytics = $this->prepareAnalytics($this->data);  | 
            ||
| 543 | }  | 
            ||
| 544 | return $this->analytics;  | 
            ||
| 545 | }  | 
            ||
| 546 | |||
| 547 | /**  | 
            ||
| 548 | * Returns the locations.  | 
            ||
| 549 | *  | 
            ||
| 550 | * @return array  | 
            ||
| 551 | */  | 
            ||
| 552 | public function getLocations()  | 
            ||
| 553 |     { | 
            ||
| 554 |         if (!$this->locations) { | 
            ||
| 555 | $this->locations = $this->prepareLocations($this->data);  | 
            ||
| 556 | }  | 
            ||
| 557 | return $this->locations;  | 
            ||
| 558 | }  | 
            ||
| 559 | |||
| 560 | |||
| 561 | /**  | 
            ||
| 562 | * Returns the rewrite maps.  | 
            ||
| 563 | *  | 
            ||
| 564 | * @return array  | 
            ||
| 565 | */  | 
            ||
| 566 | public function getRewriteMaps()  | 
            ||
| 567 |     { | 
            ||
| 568 |         if (!$this->rewriteMaps) { | 
            ||
| 569 | $this->rewriteMaps = $this->prepareRewriteMaps($this->data);  | 
            ||
| 570 | }  | 
            ||
| 571 | return $this->rewriteMaps;  | 
            ||
| 572 | }  | 
            ||
| 573 | |||
| 574 | /**  | 
            ||
| 575 | * Prepares the modules array based on a data object  | 
            ||
| 576 | *  | 
            ||
| 577 | * @param \stdClass $data The data object  | 
            ||
| 578 | *  | 
            ||
| 579 | * @return array  | 
            ||
| 580 | */  | 
            ||
| 581 | public function prepareModules(\stdClass $data)  | 
            ||
| 582 |     { | 
            ||
| 583 | |||
| 584 | $modules = array();  | 
            ||
| 585 |         if (isset($data->modules)) { | 
            ||
| 586 |             foreach ($data->modules as $module) { | 
            ||
| 587 | $modules[] = new ModuleJsonConfiguration($module);  | 
            ||
| 588 | }  | 
            ||
| 589 | }  | 
            ||
| 590 | return $modules;  | 
            ||
| 591 | }  | 
            ||
| 592 | |||
| 593 | /**  | 
            ||
| 594 | * Prepares the connectionHandlers array based on a data object  | 
            ||
| 595 | *  | 
            ||
| 596 | * @param \stdClass $data The data object  | 
            ||
| 597 | *  | 
            ||
| 598 | * @return array  | 
            ||
| 599 | */  | 
            ||
| 600 | public function prepareConnectionHandlers(\stdClass $data)  | 
            ||
| 601 |     { | 
            ||
| 602 | $connectionHandlers = array();  | 
            ||
| 603 |         if (isset($data->connectionHandlers)) { | 
            ||
| 604 | $connectionHandlers = $data->connectionHandlers;  | 
            ||
| 605 | }  | 
            ||
| 606 | return $connectionHandlers;  | 
            ||
| 607 | }  | 
            ||
| 608 | |||
| 609 | /**  | 
            ||
| 610 | * Prepares the headers array based on a data object  | 
            ||
| 611 | *  | 
            ||
| 612 | * @param \stdClass $data The data object  | 
            ||
| 613 | *  | 
            ||
| 614 | * @return array  | 
            ||
| 615 | */  | 
            ||
| 616 | public function prepareHeaders(\stdClass $data)  | 
            ||
| 617 |     { | 
            ||
| 618 | $headers = array();  | 
            ||
| 619 |         if (isset($data->headers)) { | 
            ||
| 620 | $headers = $data->headers;  | 
            ||
| 621 | }  | 
            ||
| 622 | return $headers;  | 
            ||
| 623 | }  | 
            ||
| 624 | |||
| 625 | /**  | 
            ||
| 626 | * Prepares the certificates array based on a data object  | 
            ||
| 627 | *  | 
            ||
| 628 | * @param \stdClass $data The data object  | 
            ||
| 629 | *  | 
            ||
| 630 | * @return array  | 
            ||
| 631 | */  | 
            ||
| 632 | public function prepareCertificates(\stdClass $data)  | 
            ||
| 633 |     { | 
            ||
| 634 | $certificates = array();  | 
            ||
| 635 |         if (isset($data->certificates)) { | 
            ||
| 636 | $certificates = $data->certificates;  | 
            ||
| 637 | }  | 
            ||
| 638 | return $certificates;  | 
            ||
| 639 | }  | 
            ||
| 640 | |||
| 641 | /**  | 
            ||
| 642 | * Prepares the handlers array based on a data object  | 
            ||
| 643 | *  | 
            ||
| 644 | * @param \stdClass $data The data object  | 
            ||
| 645 | *  | 
            ||
| 646 | * @return array  | 
            ||
| 647 | */  | 
            ||
| 648 | public function prepareHandlers(\stdClass $data)  | 
            ||
| 649 |     { | 
            ||
| 650 | $handlers = array();  | 
            ||
| 651 |         if (isset($data->handlers)) { | 
            ||
| 652 |             foreach ($data->handlers as $handler) { | 
            ||
| 653 | // get all params  | 
            ||
| 654 | $params = array();  | 
            ||
| 655 |                 if (isset($handler->params)) { | 
            ||
| 656 | $params = (array)$handler->params;  | 
            ||
| 657 | }  | 
            ||
| 658 | // set the handler information  | 
            ||
| 659 | $handlers[$handler->extension] = array(  | 
            ||
| 660 | "name" => $handler->name,  | 
            ||
| 661 | "params" => $params  | 
            ||
| 662 | );  | 
            ||
| 663 | }  | 
            ||
| 664 | }  | 
            ||
| 665 | return $handlers;  | 
            ||
| 666 | }  | 
            ||
| 667 | |||
| 668 | /**  | 
            ||
| 669 | * Prepares the virtual hosts array based on a data object  | 
            ||
| 670 | *  | 
            ||
| 671 | * @param \stdClass $data The data object  | 
            ||
| 672 | *  | 
            ||
| 673 | * @return array  | 
            ||
| 674 | */  | 
            ||
| 675 | public function prepareVirtualHosts(\stdClass $data)  | 
            ||
| 676 |     { | 
            ||
| 677 | $virtualHosts = array();  | 
            ||
| 678 |         if (isset($data->virtualHosts)) { | 
            ||
| 679 |             foreach ($data->virtualHosts as $virtualHost) { | 
            ||
| 680 | // explode virtuaHost names  | 
            ||
| 681 |                 $virtualHostNames = explode(' ', $virtualHost->name); | 
            ||
| 682 | // get all params  | 
            ||
| 683 | $params = get_object_vars($virtualHost);  | 
            ||
| 684 | // remove name  | 
            ||
| 685 | unset($params["name"]);  | 
            ||
| 686 | // set all virtual host information's  | 
            ||
| 687 | View Code Duplication |                 foreach ($virtualHostNames as $virtualHostName) { | 
            |
| 688 | // add all virtual hosts params per key for faster matching later on  | 
            ||
| 689 | $virtualHosts[trim($virtualHostName)] = array(  | 
            ||
| 690 | 'params' => $params,  | 
            ||
| 691 | 'rewriteMaps' => $this->prepareRewriteMaps($virtualHost),  | 
            ||
| 692 | 'rewrites' => $this->prepareRewrites($virtualHost),  | 
            ||
| 693 | 'locations' => $this->prepareLocations($virtualHost),  | 
            ||
| 694 | 'environmentVariables' => $this->prepareEnvironmentVariables($virtualHost),  | 
            ||
| 695 | 'authentication' => $this->prepareAuthentications($virtualHost),  | 
            ||
| 696 | 'accesses' => $this->prepareAccesses($virtualHost),  | 
            ||
| 697 | 'analytics' => $this->prepareAnalytics($virtualHost)  | 
            ||
| 698 | );  | 
            ||
| 699 | }  | 
            ||
| 700 | }  | 
            ||
| 701 | }  | 
            ||
| 702 | return $virtualHosts;  | 
            ||
| 703 | }  | 
            ||
| 704 | |||
| 705 | /**  | 
            ||
| 706 | * Prepares the rewrites array based on a data object  | 
            ||
| 707 | *  | 
            ||
| 708 | * @param \stdClass $data The data object  | 
            ||
| 709 | *  | 
            ||
| 710 | * @return array  | 
            ||
| 711 | */  | 
            ||
| 712 | View Code Duplication | public function prepareRewrites(\stdClass $data)  | 
            |
| 713 |     { | 
            ||
| 714 | $rewrites = array();  | 
            ||
| 715 |         if (isset($data->rewrites)) { | 
            ||
| 716 | // prepare the array with the rewrite rules  | 
            ||
| 717 |             foreach ($data->rewrites as $rewrite) { | 
            ||
| 718 | // Build up the array entry  | 
            ||
| 719 | $rewrites[] = array(  | 
            ||
| 720 | 'condition' => $rewrite->condition,  | 
            ||
| 721 | 'target' => $rewrite->target,  | 
            ||
| 722 | 'flag' => $rewrite->flag  | 
            ||
| 723 | );  | 
            ||
| 724 | }  | 
            ||
| 725 | }  | 
            ||
| 726 | return $rewrites;  | 
            ||
| 727 | }  | 
            ||
| 728 | |||
| 729 | /**  | 
            ||
| 730 | * Prepares the environmentVariables array based on a data object  | 
            ||
| 731 | *  | 
            ||
| 732 | * @param \stdClass $data The data object  | 
            ||
| 733 | *  | 
            ||
| 734 | * @return array  | 
            ||
| 735 | */  | 
            ||
| 736 | View Code Duplication | public function prepareEnvironmentVariables(\stdClass $data)  | 
            |
| 751 | |||
| 752 | /**  | 
            ||
| 753 | * Prepares the authentications array based on a data object  | 
            ||
| 754 | *  | 
            ||
| 755 | * @param \stdClass $data The data object  | 
            ||
| 756 | *  | 
            ||
| 757 | * @return array  | 
            ||
| 758 | */  | 
            ||
| 759 | View Code Duplication | public function prepareAuthentications(\stdClass $data)  | 
            |
| 760 |     { | 
            ||
| 761 | $authentications = array();  | 
            ||
| 762 |         if (isset($data->authentications)) { | 
            ||
| 763 |             foreach ($data->authentications as $authentication) { | 
            ||
| 764 | $authenticationType = $authentication->uri;  | 
            ||
| 765 | // get all params  | 
            ||
| 766 | $params = get_object_vars($authentication);  | 
            ||
| 767 | // remove type  | 
            ||
| 768 | unset($params["uri"]);  | 
            ||
| 769 | // set all authentication information's  | 
            ||
| 770 | $authentications[$authenticationType] = $params;  | 
            ||
| 771 | }  | 
            ||
| 772 | }  | 
            ||
| 773 | return $authentications;  | 
            ||
| 775 | |||
| 776 | /**  | 
            ||
| 777 | * Prepares the access array based on a data object  | 
            ||
| 778 | *  | 
            ||
| 779 | * @param \stdClass $data The data object  | 
            ||
| 780 | *  | 
            ||
| 781 | * @return array  | 
            ||
| 782 | */  | 
            ||
| 783 | View Code Duplication | public function prepareAccesses(\stdClass $data)  | 
            |
| 799 | |||
| 800 | /**  | 
            ||
| 801 | * Prepares the analytics array based on a data object  | 
            ||
| 802 | *  | 
            ||
| 803 | * @param \stdClass $data The data object  | 
            ||
| 804 | *  | 
            ||
| 805 | * @return array  | 
            ||
| 806 | */  | 
            ||
| 807 | public function prepareAnalytics(\stdClass $data)  | 
            ||
| 833 | |||
| 834 | /**  | 
            ||
| 835 | * Prepares the locations array based on a data object  | 
            ||
| 836 | *  | 
            ||
| 837 | * @param \stdClass $data The data object  | 
            ||
| 838 | *  | 
            ||
| 839 | * @return array  | 
            ||
| 840 | */  | 
            ||
| 841 | View Code Duplication | public function prepareLocations(\stdClass $data)  | 
            |
| 856 | |||
| 857 | /**  | 
            ||
| 858 | * Prepares the rewrite maps array based on a data object  | 
            ||
| 859 | *  | 
            ||
| 860 | * @param \stdClass $data The data object  | 
            ||
| 861 | *  | 
            ||
| 862 | * @return array  | 
            ||
| 863 | */  | 
            ||
| 864 | public function prepareRewriteMaps(\stdClass $data)  | 
            ||
| 878 | |||
| 879 | /**  | 
            ||
| 880 | * Return's DH param path  | 
            ||
| 881 | *  | 
            ||
| 882 | * @return string  | 
            ||
| 883 | */  | 
            ||
| 884 | public function getDhParamPath()  | 
            ||
| 888 | |||
| 889 | /**  | 
            ||
| 890 | * Return's private key path  | 
            ||
| 891 | *  | 
            ||
| 892 | * @return string  | 
            ||
| 893 | */  | 
            ||
| 894 | public function getPrivateKeyPath()  | 
            ||
| 898 | |||
| 899 | /**  | 
            ||
| 900 | * Return's the crypto method to use  | 
            ||
| 901 | *  | 
            ||
| 902 | * @return string  | 
            ||
| 903 | */  | 
            ||
| 904 | public function getCryptoMethod()  | 
            ||
| 908 | |||
| 909 | /**  | 
            ||
| 910 | * Return's the peer name to be used, if this value is not set, then the name is guessed based on the hostname used when opening the stream  | 
            ||
| 911 | *  | 
            ||
| 912 | * @return string  | 
            ||
| 913 | */  | 
            ||
| 914 | public function getPeerName()  | 
            ||
| 918 | |||
| 919 | /**  | 
            ||
| 920 | * Return's TRUE it the verification of use SSL certificate has to be required  | 
            ||
| 921 | *  | 
            ||
| 922 | * @return boolean  | 
            ||
| 923 | */  | 
            ||
| 924 | public function getVerifyPeer()  | 
            ||
| 928 | |||
| 929 | /**  | 
            ||
| 930 | * Return's TRUE it the peer name has to be verified  | 
            ||
| 931 | *  | 
            ||
| 932 | * @return boolean  | 
            ||
| 933 | */  | 
            ||
| 934 | public function getVerifyPeerName()  | 
            ||
| 938 | |||
| 939 | /**  | 
            ||
| 940 | * Return's TRUE to disable TLS compression. This can help mitigate the CRIME attack vector  | 
            ||
| 941 | *  | 
            ||
| 942 | * @return boolean  | 
            ||
| 943 | */  | 
            ||
| 944 | public function getDisableCompression()  | 
            ||
| 948 | |||
| 949 | /**  | 
            ||
| 950 | * Return's TRUE if self-signed certificates has to be allowed, but requires verify_peer to be FALSE  | 
            ||
| 951 | *  | 
            ||
| 952 | * @return boolean  | 
            ||
| 953 | */  | 
            ||
| 954 | public function getAllowSelfSigned()  | 
            ||
| 958 | |||
| 959 | /**  | 
            ||
| 960 | * Return's TRUE if control cipher ordering preferences during negotiation has to be allowed  | 
            ||
| 961 | *  | 
            ||
| 962 | * @return boolean  | 
            ||
| 963 | */  | 
            ||
| 964 | public function getHonorCipherOrder()  | 
            ||
| 968 | |||
| 969 | /**  | 
            ||
| 970 | * Return's the curve to use with ECDH ciphers, if not specified prime256v1 will be used  | 
            ||
| 971 | *  | 
            ||
| 972 | * @return string  | 
            ||
| 973 | */  | 
            ||
| 974 | public function getEcdhCurve()  | 
            ||
| 978 | |||
| 979 | /**  | 
            ||
| 980 | * Return's TRUE if a new key pair has to be created in scenarios where ECDH cipher suites are negotiated (instead of the preferred ECDHE ciphers)  | 
            ||
| 981 | *  | 
            ||
| 982 | * @return boolean  | 
            ||
| 983 | */  | 
            ||
| 984 | public function getSingleEcdhUse()  | 
            ||
| 988 | |||
| 989 | /**  | 
            ||
| 990 | * Return's TRUE if new key pair has to be created created when using DH parameters (improves forward secrecy)  | 
            ||
| 991 | *  | 
            ||
| 992 | * @return boolean  | 
            ||
| 993 | */  | 
            ||
| 994 | public function getSingleDhUse()  | 
            ||
| 998 | |||
| 999 | /**  | 
            ||
| 1000 | * Return's the list of available ciphers.  | 
            ||
| 1001 | *  | 
            ||
| 1002 | * @return string  | 
            ||
| 1003 | * @link http://php.net/manual/en/context.ssl.php#context.ssl.ciphers  | 
            ||
| 1004 | * @link https://www.openssl.org/docs/manmaster/apps/ciphers.html#CIPHER_LIST_FORMAT  | 
            ||
| 1005 | */  | 
            ||
| 1006 | public function getCiphers()  | 
            ||
| 1010 | }  | 
            ||
| 1011 | 
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.