Conditions | 7 |
Paths | 16 |
Total Lines | 65 |
Code Lines | 40 |
Lines | 25 |
Ratio | 38.46 % |
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 |
||
35 | protected function compute() |
||
36 | { |
||
37 | $connection = $this->tdbmService->getConnection(); |
||
38 | |||
39 | $columnsList = null; |
||
40 | |||
41 | $allFetchedTables = $this->tdbmService->_getRelatedTablesByInheritance($this->mainTable); |
||
42 | |||
43 | list($columnDescList, $columnsList, $orderString) = $this->getColumnsList($this->mainTable, [], $this->orderBy); |
||
44 | |||
45 | $sql = 'SELECT DISTINCT '.implode(', ', $columnsList).' FROM '.$this->from; |
||
46 | |||
47 | // Let's compute the COUNT. |
||
48 | $pkColumnNames = $this->schema->getTable($this->mainTable)->getPrimaryKeyColumns(); |
||
49 | View Code Duplication | $pkColumnNames = array_map(function ($pkColumn) { |
|
50 | return $this->tdbmService->getConnection()->quoteIdentifier($this->mainTable).'.'.$this->tdbmService->getConnection()->quoteIdentifier($pkColumn); |
||
51 | }, $pkColumnNames); |
||
52 | |||
53 | $countSql = 'SELECT COUNT(DISTINCT '.implode(', ', $pkColumnNames).') FROM '.$this->from; |
||
54 | |||
55 | // Add joins on inherited tables if necessary |
||
56 | if (count($allFetchedTables) > 1) { |
||
57 | $joinSql = ''; |
||
58 | $parentFks = $this->getParentRelationshipForeignKeys($this->mainTable); |
||
59 | View Code Duplication | foreach ($parentFks as $fk) { |
|
60 | $joinSql .= sprintf(' JOIN %s ON (%s.%s = %s.%s)', |
||
61 | $connection->quoteIdentifier($fk->getForeignTableName()), |
||
62 | $connection->quoteIdentifier($fk->getLocalTableName()), |
||
63 | $connection->quoteIdentifier($fk->getLocalColumns()[0]), |
||
64 | $connection->quoteIdentifier($fk->getForeignTableName()), |
||
65 | $connection->quoteIdentifier($fk->getForeignColumns()[0]) |
||
66 | ); |
||
67 | } |
||
68 | |||
69 | $childrenFks = $this->getChildrenRelationshipForeignKeys($this->mainTable); |
||
70 | View Code Duplication | foreach ($childrenFks as $fk) { |
|
71 | $joinSql .= sprintf(' LEFT JOIN %s ON (%s.%s = %s.%s)', |
||
72 | $connection->quoteIdentifier($fk->getLocalTableName()), |
||
73 | $connection->quoteIdentifier($fk->getForeignTableName()), |
||
74 | $connection->quoteIdentifier($fk->getForeignColumns()[0]), |
||
75 | $connection->quoteIdentifier($fk->getLocalTableName()), |
||
76 | $connection->quoteIdentifier($fk->getLocalColumns()[0]) |
||
77 | ); |
||
78 | } |
||
79 | |||
80 | $sql .= $joinSql; |
||
81 | } |
||
82 | |||
83 | View Code Duplication | if (!empty($this->filterString)) { |
|
84 | $sql .= ' WHERE '.$this->filterString; |
||
85 | $countSql .= ' WHERE '.$this->filterString; |
||
86 | } |
||
87 | |||
88 | if (!empty($orderString)) { |
||
89 | $sql .= ' ORDER BY '.$orderString; |
||
90 | } |
||
91 | |||
92 | if (stripos($countSql, 'GROUP BY') !== false) { |
||
93 | throw new TDBMException('Unsupported use of GROUP BY in SQL request.'); |
||
94 | } |
||
95 | |||
96 | $this->magicSql = $sql; |
||
97 | $this->magicSqlCount = $countSql; |
||
98 | $this->columnDescList = $columnDescList; |
||
99 | } |
||
100 | |||
183 |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.