| Conditions | 12 |
| Paths | 144 |
| Total Lines | 92 |
| Code Lines | 56 |
| 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 |
||
| 46 | protected function processConnectors(Integration $integration, array $parameters = [], callable $callback = null) |
||
| 47 | { |
||
| 48 | if (empty($parameters['skip-dictionary'])) { |
||
| 49 | $this->processDictionaryConnectors($integration); |
||
| 50 | } |
||
| 51 | |||
| 52 | // Set start date for initial connectors |
||
| 53 | $startSyncDate = $integration->getTransport()->getSettingsBag()->get(self::START_SYNC_DATE); |
||
| 54 | $parameters[self::START_SYNC_DATE] = $startSyncDate; |
||
| 55 | |||
| 56 | // Pass interval to connectors for further filters creation |
||
| 57 | $interval = $this->getSyncInterval(); |
||
| 58 | $parameters[self::INTERVAL] = $interval; |
||
| 59 | |||
| 60 | // Collect initial connectors |
||
| 61 | $postProcessConnectorTypes = array_keys($this->postProcessors); |
||
| 62 | $connectors = $this->getTypesOfConnectorsToProcess($integration, $this->getConnectorsFilterFunction($callback)); |
||
| 63 | $postProcessConnectors = array_intersect($connectors, $postProcessConnectorTypes); |
||
| 64 | $connectors = array_diff($connectors, $postProcessConnectorTypes); |
||
| 65 | |||
| 66 | /** @var \DateTime[] $connectorsSyncedTo */ |
||
| 67 | $connectorsSyncedTo = []; |
||
| 68 | foreach ($connectors as $connector) { |
||
| 69 | $connectorsSyncedTo[$connector] = $this->getConnectorSyncedTo($integration, $connector); |
||
| 70 | } |
||
| 71 | |||
| 72 | // Process all initial connectors by date interval while there are connectors to process |
||
| 73 | $isSuccess = true; |
||
| 74 | do { |
||
| 75 | $syncedConnectors = 0; |
||
| 76 | foreach ($connectors as $connector) { |
||
| 77 | if ($connectorsSyncedTo[$connector] > $startSyncDate) { |
||
| 78 | $syncedConnectors++; |
||
| 79 | |||
| 80 | $this->logger->info( |
||
| 81 | sprintf( |
||
| 82 | 'Syncing connector %s starting %s interval %s', |
||
| 83 | $connector, |
||
| 84 | $connectorsSyncedTo[$connector]->format('Y-m-d H:i:s'), |
||
| 85 | $interval->format('%d days') |
||
| 86 | ) |
||
| 87 | ); |
||
| 88 | |||
| 89 | try { |
||
| 90 | // Pass synced to for further filters creation |
||
| 91 | $parameters = array_merge( |
||
| 92 | $parameters, |
||
| 93 | [self::SYNCED_TO => clone $connectorsSyncedTo[$connector]] |
||
| 94 | ); |
||
| 95 | |||
| 96 | $realConnector = $this->getRealConnector($integration, $connector); |
||
| 97 | $status = $this->processIntegrationConnector( |
||
| 98 | $integration, |
||
| 99 | $realConnector, |
||
| 100 | $parameters |
||
| 101 | ); |
||
| 102 | // Move sync date into past by interval value |
||
| 103 | $connectorsSyncedTo[$connector]->sub($interval); |
||
| 104 | |||
| 105 | $isSuccess = $isSuccess && $this->isIntegrationConnectorProcessSuccess($status); |
||
| 106 | |||
| 107 | if ($isSuccess) { |
||
| 108 | // Save synced to date for connector |
||
| 109 | $syncedTo = $connectorsSyncedTo[$connector]; |
||
| 110 | if ($syncedTo < $startSyncDate) { |
||
| 111 | $syncedTo = $startSyncDate; |
||
| 112 | } |
||
| 113 | $this->updateSyncedTo($integration, $connector, $syncedTo); |
||
| 114 | } else { |
||
| 115 | break 2; |
||
| 116 | } |
||
| 117 | } catch (\Exception $e) { |
||
| 118 | $isSuccess = false; |
||
| 119 | |||
| 120 | $this->logger->critical($e->getMessage()); |
||
| 121 | break 2; |
||
| 122 | } |
||
| 123 | } |
||
| 124 | } |
||
| 125 | } while ($syncedConnectors > 0); |
||
| 126 | |||
| 127 | if ($isSuccess && $postProcessConnectors) { |
||
|
|
|||
| 128 | $isSuccess = $this->executePostProcessConnectors( |
||
| 129 | $integration, |
||
| 130 | $parameters, |
||
| 131 | $postProcessConnectors, |
||
| 132 | $startSyncDate |
||
| 133 | ); |
||
| 134 | } |
||
| 135 | |||
| 136 | return $isSuccess; |
||
| 137 | } |
||
| 138 | |||
| 184 |
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.