| Conditions | 13 |
| Paths | 63 |
| Total Lines | 110 |
| Code Lines | 76 |
| Lines | 54 |
| Ratio | 49.09 % |
| 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 |
||
| 34 | $limit = 10; |
||
| 35 | foreach ($filter as $key => $value) { |
||
| 36 | switch ($key) { |
||
| 37 | case "limit": |
||
| 38 | $limit = $value; |
||
| 39 | break; |
||
| 40 | |||
| 41 | case "days": |
||
| 42 | $date = new \DateTime(); |
||
| 43 | $date->modify('-' . (int) $value. ' day'); |
||
| 44 | $q = array('$lt' => $date); |
||
| 45 | if (isset($query['datePublishStart.date'])) { |
||
| 46 | $query['datePublishStart.date']= array_merge( |
||
| 47 | $query['datePublishStart.date'], |
||
| 48 | $q |
||
| 49 | ); |
||
| 50 | } else { |
||
| 51 | $query['datePublishStart.date'] = $q; |
||
| 52 | } |
||
| 53 | break; |
||
| 54 | |||
| 55 | default: |
||
| 56 | $query[$key] = $value; |
||
| 57 | break; |
||
| 58 | } |
||
| 59 | } |
||
| 60 | $query['status.name'] = 'active'; |
||
| 61 | |||
| 62 | $jobs = $jobsRepo->findBy($query,null,$limit); |
||
| 63 | $count = count($jobs); |
||
| 64 | |||
| 65 | if (0 === $count) { |
||
| 66 | return 'No jobs found.'; |
||
| 67 | } |
||
| 68 | |||
| 69 | foreach ($repositories->getEventManager()->getListeners('preUpdate') as $listener) { |
||
| 70 | $repositories->getEventManager()->removeEventListener('preUpdate', $listener); |
||
| 71 | } |
||
| 72 | |||
| 73 | |||
| 74 | echo "$count jobs found, which have to expire ...\n"; |
||
| 75 | |||
| 76 | $progress = new ProgressBar( |
||
| 77 | new ConsoleAdapter( |
||
| 78 | array( |
||
| 79 | 'elements' => array( |
||
| 80 | ConsoleAdapter::ELEMENT_TEXT, |
||
| 81 | ConsoleAdapter::ELEMENT_BAR, |
||
| 82 | ConsoleAdapter::ELEMENT_PERCENT, |
||
| 83 | ConsoleAdapter::ELEMENT_ETA |
||
| 84 | ), |
||
| 85 | 'textWidth' => 20, |
||
| 86 | 'barLeftChar' => '-', |
||
| 87 | 'barRightChar' => ' ', |
||
| 88 | 'barIndicatorChar' => '>', |
||
| 89 | ) |
||
| 90 | ), |
||
| 91 | 0, |
||
| 92 | count($jobs) |
||
| 93 | ); |
||
| 94 | |||
| 95 | $i = 0; |
||
| 96 | |||
| 97 | /* @var \Jobs\Entity\Job $job */ |
||
| 98 | foreach ($jobs as $job) { |
||
| 99 | $progress->update($i++, 'Job ' . $i . ' / ' . $count); |
||
| 100 | |||
| 101 | $job->changeStatus('expired'); |
||
| 102 | |||
| 103 | if (0 == $i % 500) { |
||
| 104 | $progress->update($i, 'Write to database...'); |
||
| 105 | $repositories->flush(); |
||
| 106 | } |
||
| 107 | } |
||
| 108 | $progress->update($i, 'Write to database...'); |
||
| 109 | $repositories->flush(); |
||
| 110 | $progress->update($i, 'Done'); |
||
| 111 | $progress->finish(); |
||
| 112 | |||
| 113 | return PHP_EOL; |
||
| 114 | } |
||
| 115 | |||
| 116 | public function setpermissionsAction() |
||
| 117 | { |
||
| 118 | $services = $this->getServiceLocator(); |
||
| 119 | $repositories = $services->get('repositories'); |
||
| 120 | $repository = $repositories->get('Jobs/Job'); |
||
| 121 | $userRep = $repositories->get('Auth/User'); |
||
| 122 | $jobs = $repository->findAll(); |
||
| 123 | $count = count($jobs); |
||
| 124 | $progress = new CoreProgressBar($count); |
||
| 125 | $i = 0; |
||
| 126 | /* @var Job $job */ |
||
| 127 | foreach ($jobs as $job) { |
||
| 128 | $progress->update($i++, 'Job ' . $i . ' / ' . $count); |
||
| 129 | |||
| 130 | $permissions = $job->getPermissions(); |
||
| 131 | $user = $job->getUser(); |
||
| 132 | if (!$user instanceof UserInterface) { |
||
| 133 | continue; |
||
| 134 | } |
||
| 135 | try { |
||
| 136 | $group = $user->getGroup($job->getCompany()); |
||
|
|
|||
| 137 | } catch (\Exception $e) { |
||
| 138 | continue; |
||
| 139 | } |
||
| 140 | if ($group) { |
||
| 141 | $permissions->grant($group, 'view'); |
||
| 142 | } |
||
| 143 | foreach ($job->getApplications() as $application) { |
||
| 144 | $progress->update($i, 'set app perms...'); |
||
| 163 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.