| Conditions | 12 |
| Paths | 144 |
| Total Lines | 92 |
| Code Lines | 56 |
| Lines | 0 |
| Ratio | 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 |
||
| 87 | protected function processConnectors(Integration $integration, array $parameters = [], callable $callback = null) |
||
| 88 | { |
||
| 89 | if (empty($parameters['skip-dictionary'])) { |
||
| 90 | $this->processDictionaryConnectors($integration); |
||
| 91 | } |
||
| 92 | |||
| 93 | // Set start date for initial connectors |
||
| 94 | $startSyncDate = $integration->getTransport()->getSettingsBag()->get('start_sync_date'); |
||
| 95 | $parameters[self::START_SYNC_DATE] = $startSyncDate; |
||
| 96 | |||
| 97 | // Pass interval to connectors for further filters creation |
||
| 98 | $interval = $this->getSyncInterval(); |
||
| 99 | $parameters[self::INTERVAL] = $interval; |
||
| 100 | |||
| 101 | // Collect initial connectors |
||
| 102 | $postProcessConnectorTypes = array_keys($this->postProcessors); |
||
| 103 | $connectors = $this->getTypesOfConnectorsToProcess($integration, $this->getConnectorsFilterFunction($callback)); |
||
| 104 | $postProcessConnectors = array_intersect($connectors, $postProcessConnectorTypes); |
||
| 105 | $connectors = array_diff($connectors, $postProcessConnectorTypes); |
||
| 106 | |||
| 107 | /** @var \DateTime[] $connectorsSyncedTo */ |
||
| 108 | $connectorsSyncedTo = []; |
||
| 109 | foreach ($connectors as $connector) { |
||
| 110 | $connectorsSyncedTo[$connector] = $this->getInitialConnectorSyncedTo($integration, $connector); |
||
| 111 | } |
||
| 112 | |||
| 113 | // Process all initial connectors by date interval while there are connectors to process |
||
| 114 | $isSuccess = true; |
||
| 115 | do { |
||
| 116 | $syncedConnectors = 0; |
||
| 117 | foreach ($connectors as $connector) { |
||
| 118 | if ($connectorsSyncedTo[$connector] > $startSyncDate) { |
||
| 119 | $syncedConnectors++; |
||
| 120 | |||
| 121 | $this->logger->info( |
||
| 122 | sprintf( |
||
| 123 | 'Syncing connector %s starting %s interval %s', |
||
| 124 | $connector, |
||
| 125 | $connectorsSyncedTo[$connector]->format('Y-m-d H:i:s'), |
||
| 126 | $interval->format('%d days') |
||
| 127 | ) |
||
| 128 | ); |
||
| 129 | |||
| 130 | try { |
||
| 131 | // Pass synced to for further filters creation |
||
| 132 | $parameters = array_merge( |
||
| 133 | $parameters, |
||
| 134 | [self::INITIAL_SYNCED_TO => clone $connectorsSyncedTo[$connector]] |
||
| 135 | ); |
||
| 136 | |||
| 137 | $realConnector = $this->getRealConnector($integration, $connector); |
||
| 138 | $status = $this->processIntegrationConnector( |
||
| 139 | $integration, |
||
| 140 | $realConnector, |
||
| 141 | $parameters |
||
| 142 | ); |
||
| 143 | // Move sync date into past by interval value |
||
| 144 | $connectorsSyncedTo[$connector]->sub($interval); |
||
| 145 | |||
| 146 | $isSuccess = $isSuccess && $this->isIntegrationConnectorProcessSuccess($status); |
||
| 147 | |||
| 148 | if ($isSuccess) { |
||
| 149 | // Save synced to date for connector |
||
| 150 | $syncedTo = $connectorsSyncedTo[$connector]; |
||
| 151 | if ($syncedTo < $startSyncDate) { |
||
| 152 | $syncedTo = $startSyncDate; |
||
| 153 | } |
||
| 154 | $this->updateSyncedTo($integration, $connector, $syncedTo); |
||
| 155 | } else { |
||
| 156 | break 2; |
||
| 157 | } |
||
| 158 | } catch (\Exception $e) { |
||
| 159 | $isSuccess = false; |
||
| 160 | |||
| 161 | $this->logger->critical($e->getMessage()); |
||
| 162 | break 2; |
||
| 163 | } |
||
| 164 | } |
||
| 165 | } |
||
| 166 | } while ($syncedConnectors > 0); |
||
| 167 | |||
| 168 | if ($isSuccess && $postProcessConnectors) { |
||
|
|
|||
| 169 | $isSuccess = $this->executePostProcessConnectors( |
||
| 170 | $integration, |
||
| 171 | $parameters, |
||
| 172 | $postProcessConnectors, |
||
| 173 | $startSyncDate |
||
| 174 | ); |
||
| 175 | } |
||
| 176 | |||
| 177 | return $isSuccess; |
||
| 178 | } |
||
| 179 | |||
| 272 |
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.