| Conditions | 17 |
| Paths | 3460 |
| Total Lines | 108 |
| Code Lines | 65 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | 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 |
||
| 204 | public function fixItemProperty( |
||
| 205 | $tool, |
||
| 206 | ResourceRepository $repo, |
||
| 207 | $course, |
||
| 208 | $admin, |
||
| 209 | ResourceInterface $resource, |
||
| 210 | $parentResource, |
||
| 211 | array $items = [] |
||
| 212 | ) { |
||
| 213 | $courseId = $course->getId(); |
||
| 214 | $id = $resource->getResourceIdentifier(); |
||
| 215 | |||
| 216 | if (empty($items)) { |
||
| 217 | $sql = "SELECT * FROM c_item_property |
||
| 218 | WHERE tool = '{$tool}' AND c_id = {$courseId} AND ref = {$id}"; |
||
| 219 | $result = $this->connection->executeQuery($sql); |
||
| 220 | $items = $result->fetchAllAssociative(); |
||
| 221 | } |
||
| 222 | |||
| 223 | // For some reason the resource doesn't have a c_item_property value. |
||
| 224 | if (empty($items)) { |
||
| 225 | return false; |
||
| 226 | } |
||
| 227 | |||
| 228 | $sessionRepo = $this->container->get(SessionRepository::class); |
||
| 229 | $groupRepo = $this->container->get(CGroupRepository::class); |
||
| 230 | $userRepo = $this->container->get(UserRepository::class); |
||
| 231 | |||
| 232 | $resource->setParent($parentResource); |
||
| 233 | $resourceNode = null; |
||
| 234 | $userList = []; |
||
| 235 | $groupList = []; |
||
| 236 | $sessionList = []; |
||
| 237 | foreach ($items as $item) { |
||
| 238 | $visibility = (int) $item['visibility']; |
||
| 239 | $userId = (int) $item['insert_user_id']; |
||
| 240 | $sessionId = $item['session_id'] ?? 0; |
||
| 241 | $groupId = $item['to_group_id'] ?? 0; |
||
| 242 | if (empty($item['lastedit_date'])) { |
||
| 243 | $lastUpdatedAt = new DateTime('now', new DateTimeZone('UTC')); |
||
| 244 | } else { |
||
| 245 | $lastUpdatedAt = new DateTime($item['lastedit_date'], new DateTimeZone('UTC')); |
||
| 246 | } |
||
| 247 | $newVisibility = ResourceLink::VISIBILITY_DRAFT; |
||
| 248 | |||
| 249 | // Old 1.11.x visibility (item property) is based in this switch: |
||
| 250 | switch ($visibility) { |
||
| 251 | case 0: |
||
| 252 | $newVisibility = ResourceLink::VISIBILITY_DRAFT; |
||
| 253 | |||
| 254 | break; |
||
| 255 | |||
| 256 | case 1: |
||
| 257 | $newVisibility = ResourceLink::VISIBILITY_PUBLISHED; |
||
| 258 | |||
| 259 | break; |
||
| 260 | } |
||
| 261 | |||
| 262 | // If c_item_property.insert_user_id doesn't exist we use the first admin id. |
||
| 263 | $user = null; |
||
| 264 | if (isset($userList[$userId])) { |
||
| 265 | $user = $userList[$userId]; |
||
| 266 | } else { |
||
| 267 | if (!empty($userId)) { |
||
| 268 | $userFound = $userRepo->find($userId); |
||
| 269 | if ($userFound) { |
||
| 270 | $user = $userList[$userId] = $userRepo->find($userId); |
||
| 271 | } |
||
| 272 | } |
||
| 273 | } |
||
| 274 | |||
| 275 | if (null === $user) { |
||
| 276 | $user = $admin; |
||
| 277 | } |
||
| 278 | |||
| 279 | $session = null; |
||
| 280 | if (!empty($sessionId)) { |
||
| 281 | if (isset($sessionList[$sessionId])) { |
||
| 282 | $session = $sessionList[$sessionId]; |
||
| 283 | } else { |
||
| 284 | $session = $sessionList[$sessionId] = $sessionRepo->find($sessionId); |
||
| 285 | } |
||
| 286 | } |
||
| 287 | |||
| 288 | $group = null; |
||
| 289 | if (!empty($groupId)) { |
||
| 290 | if (isset($groupList[$groupId])) { |
||
| 291 | $group = $groupList[$groupId]; |
||
| 292 | } else { |
||
| 293 | $group = $groupList[$groupId] = $groupRepo->find($groupId); |
||
| 294 | } |
||
| 295 | } |
||
| 296 | |||
| 297 | if (null === $resourceNode) { |
||
| 298 | $resourceNode = $repo->addResourceNode($resource, $user, $parentResource); |
||
| 299 | $this->entityManager->persist($resourceNode); |
||
| 300 | } |
||
| 301 | $resource->addCourseLink($course, $session, $group, $newVisibility); |
||
| 302 | |||
| 303 | if (2 === $visibility) { |
||
| 304 | $link = $resource->getResourceNode()->getResourceLinkByContext($course, $session, $group); |
||
| 305 | $link->setDeletedAt($lastUpdatedAt); |
||
| 306 | } |
||
| 307 | |||
| 308 | $this->entityManager->persist($resource); |
||
| 309 | } |
||
| 310 | |||
| 311 | return true; |
||
| 312 | } |
||
| 367 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.