| Conditions | 11 |
| Paths | 18 |
| Total Lines | 49 |
| Code Lines | 28 |
| 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 |
||
| 103 | public function scheduleRecalculation(Channel $channel = null) |
||
| 104 | { |
||
| 105 | if ($channel) { |
||
| 106 | $argument = sprintf('--channel=%s', $channel->getId()); |
||
| 107 | |||
| 108 | if ($this->isJobRunning($argument)) { |
||
| 109 | return; |
||
| 110 | } |
||
| 111 | |||
| 112 | $isActiveChannel = $channel->getStatus() === Channel::STATUS_ACTIVE; |
||
| 113 | $channelData = $channel->getData(); |
||
| 114 | $rfmEnabled = !empty($channelData[RFMAwareInterface::RFM_STATE_KEY]); |
||
| 115 | |||
| 116 | if (!$isActiveChannel || !$rfmEnabled) { |
||
| 117 | return; |
||
| 118 | } |
||
| 119 | } |
||
| 120 | |||
| 121 | if ($this->getJob()) { |
||
| 122 | return; |
||
| 123 | } |
||
| 124 | |||
| 125 | $args = []; |
||
| 126 | if ($channel) { |
||
| 127 | $argument = sprintf('--channel=%s', $channel->getId()); |
||
| 128 | $channelJob = $this->getJob($argument); |
||
| 129 | if ($channelJob) { |
||
| 130 | return; |
||
| 131 | } |
||
| 132 | |||
| 133 | $args = [$argument]; |
||
| 134 | } |
||
| 135 | |||
| 136 | $job = new Job(CalculateAnalyticsCommand::COMMAND_NAME, $args); |
||
| 137 | $em = $this->doctrineHelper->getEntityManager($job); |
||
| 138 | |||
| 139 | if (!$channel) { |
||
| 140 | $channelJobs = $this->getJob('--channel'); |
||
| 141 | |||
| 142 | if ($channelJobs) { |
||
| 143 | foreach ($channelJobs as $channelJob) { |
||
| 144 | $em->remove($channelJob); |
||
| 145 | } |
||
| 146 | } |
||
| 147 | } |
||
| 148 | |||
| 149 | $em->persist($job); |
||
| 150 | $em->flush($job); |
||
| 151 | } |
||
| 152 | } |
||
| 153 |
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.