Conditions | 4 |
Paths | 5 |
Total Lines | 67 |
Code Lines | 26 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 3 | Features | 1 |
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 |
||
109 | protected function updateOpportunityClosedAtValue(LoggerInterface $logger, $dryRun) |
||
110 | { |
||
111 | $platform = $this->connection->getDatabasePlatform(); |
||
112 | |||
113 | if ($platform instanceof PostgreSqlPlatform) { |
||
114 | $updateSql = <<<SQL |
||
115 | UPDATE orocrm_sales_opportunity o |
||
116 | SET closed_at = afm.logged_at |
||
117 | FROM |
||
118 | oro_audit a |
||
119 | INNER JOIN |
||
120 | ( |
||
121 | SELECT |
||
122 | MAX(af.audit_id) AS max_audit_id, |
||
123 | MAX(am.logged_at) AS logged_at |
||
124 | FROM oro_audit_field af |
||
125 | INNER JOIN oro_audit am ON am.id = af.audit_id AND am.object_class = :objectClass |
||
126 | WHERE af.field = :field AND af.new_text IN (:statuses) |
||
127 | GROUP BY am.object_id |
||
128 | ) afm |
||
129 | ON afm.max_audit_id = a.id |
||
130 | |||
131 | WHERE o.status_id IN (:status_ids) and |
||
132 | a.object_id = o.id AND a.object_class = :objectClass |
||
133 | SQL; |
||
134 | } elseif ($platform instanceof MySqlPlatform) { |
||
135 | $updateSql = <<<SQL |
||
136 | UPDATE orocrm_sales_opportunity o |
||
137 | INNER JOIN oro_audit a ON a.object_id = o.id AND a.object_class = :objectClass |
||
138 | INNER JOIN |
||
139 | ( |
||
140 | SELECT |
||
141 | MAX(af.audit_id) AS max_audit_id, |
||
142 | MAX(am.logged_at) AS logged_at |
||
143 | FROM oro_audit_field af |
||
144 | INNER JOIN oro_audit am ON am.id = af.audit_id AND am.object_class = :objectClass |
||
145 | WHERE af.field = :field AND af.new_text IN (:statuses) |
||
146 | GROUP BY am.object_id |
||
147 | ) afm |
||
148 | ON afm.max_audit_id = a.id |
||
149 | SET o.closed_at = afm.logged_at |
||
150 | WHERE o.status_id IN (:status_ids) |
||
151 | SQL; |
||
152 | } else { |
||
153 | throw new UnsupportedDatabasePlatformException( |
||
154 | sprintf('Platform %s is not supported', $platform->getName()) |
||
155 | ); |
||
156 | } |
||
157 | $params = [ |
||
158 | 'field' => 'status', |
||
159 | 'statuses' => ['Closed Lost', 'Closed Won', 'Lost', 'Won'], |
||
160 | 'objectClass' => 'OroCRM\Bundle\SalesBundle\Entity\Opportunity', |
||
161 | 'status_ids' => [Opportunity::STATUS_WON, Opportunity::STATUS_LOST] |
||
162 | ]; |
||
163 | $types = [ |
||
164 | 'field' => Type::STRING, |
||
165 | 'statuses' => Connection::PARAM_STR_ARRAY, |
||
166 | 'objectClass' => Type::STRING, |
||
167 | 'status_ids' => Connection::PARAM_STR_ARRAY |
||
168 | ]; |
||
169 | |||
170 | $this->logQuery($logger, $updateSql, $params, $types); |
||
171 | |||
172 | if (!$dryRun) { |
||
173 | $this->connection->executeUpdate($updateSql, $params, $types); |
||
174 | } |
||
175 | } |
||
176 | } |
||
177 |