| Conditions | 8 |
| Paths | 18 |
| Total Lines | 81 |
| 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 |
||
| 74 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 75 | { |
||
| 76 | // get the ticket |
||
| 77 | $ticket = $input->getArgument('ticket'); |
||
| 78 | |||
| 79 | // we might need framing dates |
||
| 80 | $toDate = null; |
||
| 81 | $fromDate = null; |
||
| 82 | |||
| 83 | // there might be a limit |
||
| 84 | $limit = null; |
||
| 85 | |||
| 86 | // prepare all the input options |
||
| 87 | $this->prepareInputParams($input, $ticket, $fromDate, $toDate, $limit); |
||
| 88 | |||
| 89 | // filter by ticket if given |
||
| 90 | /** @var \Wicked\Timely\Storage\StorageFactory $storage */ |
||
| 91 | $storage = StorageFactory::getStorage(); |
||
| 92 | $bookings = $storage->retrieve($ticket, $toDate, $fromDate, $limit); |
||
|
|
|||
| 93 | |||
| 94 | // return if we did not find any bookings |
||
| 95 | if (empty($bookings)) { |
||
| 96 | $output->write('No bookings found, nothing to push ...', true); |
||
| 97 | return; |
||
| 98 | } |
||
| 99 | |||
| 100 | // get tasks from bookings |
||
| 101 | $tasks = TaskFactory::getTasksFromBookings($bookings); |
||
| 102 | |||
| 103 | // create unique identity of task to reduce duplicate tasks being pushed |
||
| 104 | // @TODO |
||
| 105 | |||
| 106 | // retrieve configuration |
||
| 107 | $configuration = new DotEnvConfiguration(); |
||
| 108 | |||
| 109 | try { |
||
| 110 | // get our issue service and push the tasks |
||
| 111 | $issueService = new IssueService($configuration); |
||
| 112 | foreach ($tasks as $task) { |
||
| 113 | // create a worklog from the task |
||
| 114 | $workLog = new Worklog(); |
||
| 115 | $workLog->setComment($task->getComment()) |
||
| 116 | ->setStarted($task->getStartTime()) |
||
| 117 | ->setTimeSpent(Date::secondsToUnits(Date::roundByInterval($task->getDuration(), 900))); |
||
| 118 | |||
| 119 | // check the sanity of our worklog and discard it if there is something missing |
||
| 120 | if (!$task->getTicketId() || empty($workLog->timeSpent) || empty($workLog->comment)) |
||
| 121 | { |
||
| 122 | $output->writeln('Not pushing one worklog as it misses vital information'); |
||
| 123 | continue; |
||
| 124 | } |
||
| 125 | |||
| 126 | // log the worklog about to being pushed if output is verbose |
||
| 127 | if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { |
||
| 128 | $output->writeln( |
||
| 129 | sprintf( |
||
| 130 | '%s : %s > %s', |
||
| 131 | $task->getTicketId(), |
||
| 132 | $workLog->timeSpent, |
||
| 133 | $workLog->comment |
||
| 134 | ) |
||
| 135 | ); |
||
| 136 | } |
||
| 137 | |||
| 138 | // push to remote |
||
| 139 | $issueService->addWorklog($task->getTicketId(), $workLog); |
||
| 140 | } |
||
| 141 | } catch (JiraException $e) { |
||
| 142 | $output->write( |
||
| 143 | sprintf( |
||
| 144 | 'Error while pushing. Status %s, with message: "%s"', |
||
| 145 | $e->getCode(), |
||
| 146 | $e->getMessage() |
||
| 147 | ) |
||
| 148 | ); |
||
| 149 | } |
||
| 150 | |||
| 151 | |||
| 152 | // write output |
||
| 153 | $output->write(sprintf('Successfully pushed %s tasks.', count($tasks)), true); |
||
| 154 | } |
||
| 155 | } |
||
| 156 |
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.