Code Duplication    Length = 21-22 lines in 2 locations

Command/ApnsPushCommand.php 1 location

@@ 45-65 (lines=21) @@
42
    /**
43
     * Command execution.
44
     */
45
    protected function execute(InputInterface $input, OutputInterface $output)
46
    {
47
        $message = (new ApnsMessage())
48
            ->setSimpleAlert($input->getArgument('message'))
49
            ->setBadge($input->getOption('badge'))
50
            ->addToken($token = $input->getArgument('token'))
51
        ;
52
53
        $apnsClients = $this->getContainer()->get('link_value_mobile_notif.clients')->getApnsClients();
54
55
        if ($apnsClients->count() == 0) {
56
            throw new \RuntimeException('You must configure at least one APNS client to be able to push messages with this command.');
57
        }
58
59
        $apnsClients->forAll(function ($key, ApnsClient $client) use ($message, $output) {
60
            $output->writeln(sprintf('Sending message "%s" using APNS [%s] client...', $message->getSimpleAlert(), $key));
61
            $client->push($message);
62
63
            return true;
64
        });
65
    }
66
}
67

Command/GcmPushCommand.php 1 location

@@ 46-67 (lines=22) @@
43
    /**
44
     * Command execution.
45
     */
46
    protected function execute(InputInterface $input, OutputInterface $output)
47
    {
48
        $message = (new GcmMessage())
49
            ->setNotificationBody($input->getArgument('message'))
50
            ->setNotificationTitle($input->getOption('title'))
51
            ->setNotificationIcon($input->getOption('myicon'))
52
            ->addToken($token = $input->getArgument('token'))
53
        ;
54
55
        $gcmClients = $this->getContainer()->get('link_value_mobile_notif.clients')->getGcmClients();
56
57
        if ($gcmClients->count() == 0) {
58
            throw new \RuntimeException('You must configure at least one GCM client to be able to push messages with this command.');
59
        }
60
61
        $gcmClients->forAll(function ($key, GcmClient $client) use ($message, $output) {
62
            $output->writeln(sprintf('Sending message "%s" using GCM [%s] client...', $message->getNotificationBody(), $key));
63
            $client->push($message);
64
65
            return true;
66
        });
67
    }
68
}
69