| Conditions | 6 |
| Paths | 9 |
| Total Lines | 51 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 39 | protected function compute(): void |
||
| 40 | { |
||
| 41 | $key = 'FindObjectsQueryFactory_'.$this->mainTable.'__'.implode('_/_', $this->additionalTablesFetch).'__'.$this->filterString.'__'.$this->orderBy; |
||
| 42 | if ($this->cache->contains($key)) { |
||
| 43 | [ |
||
| 44 | $this->magicSql, |
||
| 45 | $this->magicSqlCount, |
||
| 46 | $this->columnDescList, |
||
| 47 | $this->magicSqlSubQuery |
||
| 48 | ] = $this->cache->fetch($key); |
||
| 49 | return; |
||
| 50 | } |
||
| 51 | |||
| 52 | list($columnDescList, $columnsList, $orderString) = $this->getColumnsList($this->mainTable, $this->additionalTablesFetch, $this->orderBy, true); |
||
| 53 | |||
| 54 | $sql = 'SELECT DISTINCT '.implode(', ', $columnsList).' FROM MAGICJOIN('.$this->mainTable.')'; |
||
| 55 | |||
| 56 | $pkColumnNames = $this->tdbmService->getPrimaryKeyColumns($this->mainTable); |
||
| 57 | $mysqlPlatform = new MySqlPlatform(); |
||
| 58 | $pkColumnNames = array_map(function ($pkColumn) use ($mysqlPlatform) { |
||
| 59 | return $mysqlPlatform->quoteIdentifier($this->mainTable).'.'.$mysqlPlatform->quoteIdentifier($pkColumn); |
||
| 60 | }, $pkColumnNames); |
||
| 61 | |||
| 62 | $subQuery = 'SELECT DISTINCT '.implode(', ', $pkColumnNames).' FROM MAGICJOIN('.$this->mainTable.')'; |
||
| 63 | |||
| 64 | if (count($pkColumnNames) === 1 || $this->tdbmService->getConnection()->getDatabasePlatform() instanceof MySqlPlatform) { |
||
| 65 | $countSql = 'SELECT COUNT(DISTINCT '.implode(', ', $pkColumnNames).') FROM MAGICJOIN('.$this->mainTable.')'; |
||
| 66 | } else { |
||
| 67 | $countSql = 'SELECT COUNT(*) FROM ('.$subQuery.') tmp'; |
||
| 68 | } |
||
| 69 | |||
| 70 | if (!empty($this->filterString)) { |
||
| 71 | $sql .= ' WHERE '.$this->filterString; |
||
| 72 | $countSql .= ' WHERE '.$this->filterString; |
||
| 73 | $subQuery .= ' WHERE '.$this->filterString; |
||
| 74 | } |
||
| 75 | |||
| 76 | if (!empty($orderString)) { |
||
| 77 | $sql .= ' ORDER BY '.$orderString; |
||
| 78 | } |
||
| 79 | |||
| 80 | $this->magicSql = $sql; |
||
| 81 | $this->magicSqlCount = $countSql; |
||
| 82 | $this->magicSqlSubQuery = $subQuery; |
||
| 83 | $this->columnDescList = $columnDescList; |
||
| 84 | |||
| 85 | $this->cache->save($key, [ |
||
| 86 | $this->magicSql, |
||
| 87 | $this->magicSqlCount, |
||
| 88 | $this->columnDescList, |
||
| 89 | $this->magicSqlSubQuery, |
||
| 90 | ]); |
||
| 117 |