Conditions | 6 |
Paths | 4 |
Total Lines | 63 |
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 |
||
109 | protected function getFirstTimeValueForEvent(string $tableDef, int $now): int |
||
110 | { |
||
111 | $result = PHP_INT_MAX; |
||
112 | [$tableName, $pid] = GeneralUtility::trimExplode(':', $tableDef); |
||
113 | |||
114 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
||
115 | ->getQueryBuilderForTable($tableName); |
||
116 | $queryBuilder->getRestrictions() |
||
117 | ->removeByType(StartTimeRestriction::class) |
||
118 | ->removeByType(EndTimeRestriction::class); |
||
119 | $timeFields = ['registration_startdate', 'registration_deadline']; |
||
120 | $timeConditions = $queryBuilder->expr()->orX(); |
||
121 | foreach ($timeFields as $field) { |
||
122 | $queryBuilder->addSelectLiteral( |
||
123 | 'MIN(' |
||
124 | . 'CASE WHEN ' |
||
125 | . $queryBuilder->expr()->lte( |
||
126 | $field, |
||
127 | $queryBuilder->createNamedParameter($now, \PDO::PARAM_INT) |
||
128 | ) |
||
129 | . ' THEN NULL ELSE ' . $queryBuilder->quoteIdentifier($field) . ' END' |
||
130 | . ') AS ' . $queryBuilder->quoteIdentifier($field) |
||
131 | ); |
||
132 | $timeConditions->add( |
||
133 | $queryBuilder->expr()->gt( |
||
134 | $field, |
||
135 | $queryBuilder->createNamedParameter($now, \PDO::PARAM_INT) |
||
136 | ) |
||
137 | ); |
||
138 | } |
||
139 | |||
140 | // Only consider events where registration is enabled and that have not started yet. |
||
141 | // Also include PID and timeConditions |
||
142 | $row = $queryBuilder |
||
143 | ->from($tableName) |
||
144 | ->where( |
||
145 | $queryBuilder->expr()->eq( |
||
146 | 'pid', |
||
147 | $queryBuilder->createNamedParameter($pid, \PDO::PARAM_INT) |
||
148 | ), |
||
149 | $queryBuilder->expr()->eq( |
||
150 | 'enable_registration', |
||
151 | $queryBuilder->createNamedParameter(1, \PDO::PARAM_INT) |
||
152 | ), |
||
153 | $queryBuilder->expr()->gt( |
||
154 | 'startdate', |
||
155 | $queryBuilder->createNamedParameter($now, \PDO::PARAM_INT) |
||
156 | ), |
||
157 | $timeConditions |
||
158 | ) |
||
159 | ->execute() |
||
160 | ->fetch(); |
||
161 | |||
162 | if ($row) { |
||
163 | foreach ($timeFields as $timeField) { |
||
164 | if ($row[$timeField] !== null && (int)$row[$timeField] > $now) { |
||
165 | $result = min($result, (int)$row[$timeField]); |
||
166 | } |
||
167 | } |
||
168 | } |
||
169 | |||
170 | return $result; |
||
171 | } |
||
172 | } |
||
173 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.