communicator->get('/mailboxes/registered'); $body = $response->getBody()->getContents(); if (trim($body) === '') { return []; } return json_decode($body)->mailboxes; } protected function checkMailbox($mailbox): bool { if ((new \DateTimeImmutable())->diff(new \DateTimeImmutable($mailbox->last_checked->date->date))->days < $this->min_check_days) { return true; } $response = $this->communicator->get("/mailbox/{$mailbox->id}/check"); $body = $response->getBody()->getContents(); if (trim($body) === '') { return true; } return json_decode($body)->status; } public function execute(InputInterface $input, OutputInterface $output): int { $section1 = $output->section(); $section2 = $output->section(); $io1 = new SymfonyStyle($input, $section1); $io2 = new SymfonyStyle($input, $section2); $io1->title('Checking for New Messages'); $mailboxes = $this->getMailboxes(); $notice = 'Found ' . count($mailboxes) . ' mailboxes'; $io1->text($notice); if (count($mailboxes) > 0) { $io1->section('Checking for new messages'); $io1->progressStart(count($mailboxes)); foreach ($mailboxes as $mailbox) { $section2->clear(); $io2->text("Checking {$mailbox->name}"); if ($this->checkMailbox($mailbox)) { $io2->success("Found new emails in {$mailbox->name}"); } else { $io2->info("No new emails in {$mailbox->name}"); } $io1->progressAdvance(); } $io1->progressFinish(); } $section2->clear(); $io2->success('Done'); return Command::SUCCESS; } }