Complex classes like Manager 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 Manager, and based on these observations, apply Extract Interface, too.
| 1 | <?php | ||
| 28 | class Manager | ||
| 29 | { | ||
| 30 | /** | ||
| 31 | * @var string Manager name | ||
| 32 | */ | ||
| 33 | private $name; | ||
| 34 | |||
| 35 | /** | ||
| 36 | * @var array Manager configuration | ||
| 37 | */ | ||
| 38 | private $config = []; | ||
| 39 | |||
| 40 | /** | ||
| 41 | * @var Client | ||
| 42 | */ | ||
| 43 | private $client; | ||
| 44 | |||
| 45 | /** | ||
| 46 | * @var Converter | ||
| 47 | */ | ||
| 48 | private $converter; | ||
| 49 | |||
| 50 | /** | ||
| 51 | * @var array Container for bulk queries | ||
| 52 | */ | ||
| 53 | private $bulkQueries = []; | ||
| 54 | |||
| 55 | /** | ||
| 56 | * @var array Holder for consistency, refresh and replication parameters | ||
| 57 | */ | ||
| 58 | private $bulkParams = []; | ||
| 59 | |||
| 60 | /** | ||
| 61 | * @var array | ||
| 62 | */ | ||
| 63 | private $indexSettings; | ||
| 64 | |||
| 65 | /** | ||
| 66 | * @var MetadataCollector | ||
| 67 | */ | ||
| 68 | private $metadataCollector; | ||
| 69 | |||
| 70 | /** | ||
| 71 | * After commit to make data available the refresh or flush operation is needed | ||
| 72 | * so one of those methods has to be defined, the default is refresh. | ||
| 73 | * | ||
| 74 | * @var string | ||
| 75 | */ | ||
| 76 | private $commitMode = 'refresh'; | ||
| 77 | |||
| 78 | /** | ||
| 79 | * The size that defines after how much document inserts call commit function. | ||
| 80 | * | ||
| 81 | * @var int | ||
| 82 | */ | ||
| 83 | private $bulkCommitSize = 100; | ||
| 84 | |||
| 85 | /** | ||
| 86 | * Container to count how many documents was passed to the bulk query. | ||
| 87 | * | ||
| 88 | * @var int | ||
| 89 | */ | ||
| 90 | private $bulkCount = 0; | ||
| 91 | |||
| 92 | /** | ||
| 93 | * @var Repository[] Repository local cache | ||
| 94 | */ | ||
| 95 | private $repositories; | ||
| 96 | |||
| 97 | /** | ||
| 98 | * @var EventDispatcherInterface | ||
| 99 | */ | ||
| 100 | private $eventDispatcher; | ||
| 101 | |||
| 102 | /** | ||
| 103 | * @var Stopwatch | ||
| 104 | */ | ||
| 105 | private $stopwatch; | ||
| 106 | |||
| 107 | /** | ||
| 108 | * @param string $name Manager name | ||
| 109 | * @param array $config Manager configuration | ||
| 110 | * @param Client $client | ||
| 111 | * @param array $indexSettings | ||
| 112 | * @param MetadataCollector $metadataCollector | ||
| 113 | * @param Converter $converter | ||
| 114 | */ | ||
| 115 | public function __construct( | ||
| 130 | |||
| 131 | /** | ||
| 132 | * Returns Elasticsearch connection. | ||
| 133 | * | ||
| 134 | * @return Client | ||
| 135 | */ | ||
| 136 | public function getClient() | ||
| 140 | |||
| 141 | /** | ||
| 142 | * @return string | ||
| 143 | */ | ||
| 144 | public function getName() | ||
| 148 | |||
| 149 | /** | ||
| 150 | * @return array | ||
| 151 | */ | ||
| 152 | public function getConfig() | ||
| 156 | |||
| 157 | /** | ||
| 158 | * @param EventDispatcherInterface $eventDispatcher | ||
| 159 | */ | ||
| 160 | public function setEventDispatcher(EventDispatcherInterface $eventDispatcher) | ||
| 164 | |||
| 165 | /** | ||
| 166 | * @param Stopwatch $stopwatch | ||
| 167 | */ | ||
| 168 | public function setStopwatch(Stopwatch $stopwatch) | ||
| 172 | |||
| 173 | /** | ||
| 174 | * Returns repository by document class. | ||
| 175 | * | ||
| 176 | * @param string $className FQCN or string in Bundle:Document format | ||
| 177 | * | ||
| 178 | * @return Repository | ||
| 179 | */ | ||
| 180 | public function getRepository($className) | ||
| 207 | |||
| 208 | /** | ||
| 209 | * @return MetadataCollector | ||
| 210 | */ | ||
| 211 | public function getMetadataCollector() | ||
| 215 | |||
| 216 | /** | ||
| 217 | * @return Converter | ||
| 218 | */ | ||
| 219 | public function getConverter() | ||
| 223 | |||
| 224 | /** | ||
| 225 | * @return string | ||
| 226 | */ | ||
| 227 | public function getCommitMode() | ||
| 231 | |||
| 232 | /** | ||
| 233 | * @param string $commitMode | ||
| 234 | */ | ||
| 235 | public function setCommitMode($commitMode) | ||
| 243 | |||
| 244 | /** | ||
| 245 | * @return int | ||
| 246 | */ | ||
| 247 | public function getBulkCommitSize() | ||
| 251 | |||
| 252 | /** | ||
| 253 | * @param int $bulkCommitSize | ||
| 254 | */ | ||
| 255 | public function setBulkCommitSize($bulkCommitSize) | ||
| 259 | |||
| 260 | /** | ||
| 261 | * Creates a repository. | ||
| 262 | * | ||
| 263 | * @param string $className | ||
| 264 | * | ||
| 265 | * @return Repository | ||
| 266 | */ | ||
| 267 | private function createRepository($className) | ||
| 271 | |||
| 272 | /** | ||
| 273 | * Executes search query in the index. | ||
| 274 | * | ||
| 275 | * @param array $types List of types to search in. | ||
| 276 | * @param array $query Query to execute. | ||
| 277 | * @param array $queryStringParams Query parameters. | ||
| 278 | * | ||
| 279 | * @return array | ||
| 280 | */ | ||
| 281 | public function search(array $types, array $query, array $queryStringParams = []) | ||
| 307 | |||
| 308 | /** | ||
| 309 | * Adds document to next flush. | ||
| 310 | * | ||
| 311 | * @param object $document | ||
| 312 | */ | ||
| 313 | public function persist($document) | ||
| 320 | |||
| 321 | /** | ||
| 322 | * Adds document for removal. | ||
| 323 | * | ||
| 324 | * @param object $document | ||
| 325 | */ | ||
| 326 | public function remove($document) | ||
| 340 | |||
| 341 | /** | ||
| 342 | * Flushes elasticsearch index. | ||
| 343 | * | ||
| 344 | * @param array $params | ||
| 345 | * | ||
| 346 | * @return array | ||
| 347 | */ | ||
| 348 | public function flush(array $params = []) | ||
| 352 | |||
| 353 | /** | ||
| 354 | * Refreshes elasticsearch index. | ||
| 355 | * | ||
| 356 | * @param array $params | ||
| 357 | * | ||
| 358 | * @return array | ||
| 359 | */ | ||
| 360 | public function refresh(array $params = []) | ||
| 364 | |||
| 365 | /** | ||
| 366 | * Inserts the current query container to the index, used for bulk queries execution. | ||
| 367 | * | ||
| 368 | * @param array $params Parameters that will be passed to the flush or refresh queries. | ||
| 369 | * | ||
| 370 | * @return null|array | ||
| 371 | * | ||
| 372 | * @throws BulkWithErrorsException | ||
| 373 | */ | ||
| 374 | public function commit(array $params = []) | ||
| 423 | |||
| 424 | /** | ||
| 425 | * Adds query to bulk queries container. | ||
| 426 | * | ||
| 427 | * @param string $operation One of: index, update, delete, create. | ||
| 428 | * @param string|array $type Elasticsearch type name. | ||
| 429 | * @param array $query DSL to execute. | ||
| 430 | * | ||
| 431 | * @throws \InvalidArgumentException | ||
| 432 | * | ||
| 433 | * @return null|array | ||
| 434 | */ | ||
| 435 | public function bulk($operation, $type, array $query) | ||
| 483 | |||
| 484 | /** | ||
| 485 | * Optional setter to change bulk query params. | ||
| 486 | * | ||
| 487 | * @param array $params Possible keys: | ||
| 488 | * ['consistency'] = (enum) Explicit write consistency setting for the operation. | ||
| 489 | * ['refresh'] = (boolean) Refresh the index after performing the operation. | ||
| 490 | * ['replication'] = (enum) Explicitly set the replication type. | ||
| 491 | */ | ||
| 492 | public function setBulkParams(array $params) | ||
| 496 | |||
| 497 | /** | ||
| 498 | * Creates fresh elasticsearch index. | ||
| 499 | * | ||
| 500 | * @param bool $noMapping Determines if mapping should be included. | ||
| 501 | * | ||
| 502 | * @return array | ||
| 503 | */ | ||
| 504 | public function createIndex($noMapping = false) | ||
| 512 | |||
| 513 | /** | ||
| 514 | * Drops elasticsearch index. | ||
| 515 | */ | ||
| 516 | public function dropIndex() | ||
| 520 | |||
| 521 | /** | ||
| 522 | * Tries to drop and create fresh elasticsearch index. | ||
| 523 | * | ||
| 524 | * @param bool $noMapping Determines if mapping should be included. | ||
| 525 | * | ||
| 526 | * @return array | ||
| 527 | */ | ||
| 528 | public function dropAndCreateIndex($noMapping = false) | ||
| 540 | |||
| 541 | /** | ||
| 542 | * Checks if connection index is already created. | ||
| 543 | * | ||
| 544 | * @return bool | ||
| 545 | */ | ||
| 546 | public function indexExists() | ||
| 550 | |||
| 551 | /** | ||
| 552 | * Returns index name this connection is attached to. | ||
| 553 | * | ||
| 554 | * @return string | ||
| 555 | */ | ||
| 556 | public function getIndexName() | ||
| 560 | |||
| 561 | /** | ||
| 562 | * Sets index name for this connection. | ||
| 563 | * | ||
| 564 | * @param string $name | ||
| 565 | */ | ||
| 566 | public function setIndexName($name) | ||
| 570 | |||
| 571 | /** | ||
| 572 | * Returns mappings of the index for this connection. | ||
| 573 | * | ||
| 574 | * @return array | ||
| 575 | */ | ||
| 576 | public function getIndexMappings() | ||
| 580 | |||
| 581 | /** | ||
| 582 | * Returns Elasticsearch version number. | ||
| 583 | * | ||
| 584 | * @return string | ||
| 585 | */ | ||
| 586 | public function getVersionNumber() | ||
| 590 | |||
| 591 | /** | ||
| 592 | * Clears elasticsearch client cache. | ||
| 593 | */ | ||
| 594 | public function clearCache() | ||
| 598 | |||
| 599 | /** | ||
| 600 | * Returns a single document by ID. Returns NULL if document was not found. | ||
| 601 | * | ||
| 602 | * @param string $className Document class name or Elasticsearch type name | ||
| 603 | * @param string $id Document ID to find | ||
| 604 | * @param string $routing Custom routing for the document | ||
| 605 | * | ||
| 606 | * @return object | ||
| 607 | */ | ||
| 608 | public function find($className, $id, $routing = null) | ||
| 630 | |||
| 631 | /** | ||
| 632 | * Fetches next set of results. | ||
| 633 | * | ||
| 634 | * @param string $scrollId | ||
| 635 | * @param string $scrollDuration | ||
| 636 | * | ||
| 637 | * @return mixed | ||
| 638 | * | ||
| 639 | * @throws \Exception | ||
| 640 | */ | ||
| 641 | public function scroll( | ||
| 649 | |||
| 650 | /** | ||
| 651 | * Clears scroll. | ||
| 652 | * | ||
| 653 | * @param string $scrollId | ||
| 654 | */ | ||
| 655 | public function clearScroll($scrollId) | ||
| 659 | |||
| 660 | /** | ||
| 661 | * Calls "Get Settings API" in Elasticsearch and will return you the currently configured settings. | ||
| 662 | * | ||
| 663 | * return array | ||
| 664 | */ | ||
| 665 | public function getSettings() | ||
| 669 | |||
| 670 | /** | ||
| 671 | * Gets Elasticsearch aliases information. | ||
| 672 | * @param $params | ||
| 673 | * | ||
| 674 | * @return array | ||
| 675 | */ | ||
| 676 | public function getAliases($params = []) | ||
| 680 | |||
| 681 | /** | ||
| 682 | * Resolves type name by class name. | ||
| 683 | * | ||
| 684 | * @param string $className | ||
| 685 | * | ||
| 686 | * @return string | ||
| 687 | */ | ||
| 688 | private function resolveTypeName($className) | ||
| 696 | |||
| 697 | /** | ||
| 698 | * Starts and stops an event in the stopwatch | ||
| 699 | * | ||
| 700 | * @param string $action only 'start' and 'stop' | ||
| 701 | * @param string $name name of the event | ||
| 702 | */ | ||
| 703 | private function stopwatch($action, $name) | ||
| 709 | } | ||
| 710 | 
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: