Completed
Push — master ( 6b6b0d...aff631 )
by Dominik
06:07
created

SendNewsLetterCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 5
dl 51
loc 51
ccs 20
cts 22
cp 0.9091
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 17 17 1
B execute() 22 22 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
namespace Azine\EmailBundle\Command;
3
4
use Symfony\Component\Console\Output\OutputInterface;
5
use Symfony\Component\Console\Input\InputInterface;
6
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
7
use Symfony\Component\Filesystem\LockHandler;
8
9
/**
10
 * Send Newsletter via email
11
 * @author dominik
12
 */
13 View Code Duplication
class SendNewsLetterCommand extends ContainerAwareCommand
1 ignored issue
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
14
{
15
    /**
16
     * (non-PHPdoc)
17
     * @see Symfony\Component\Console\Command.Command::configure()
18
     */
19 4
    protected function configure()
20
    {
21 4
        $this	->setName('emails:sendNewsletter')
22 4
                ->setDescription('Send Newsletter via email to all subscribers.')
23 4
                ->setHelp(<<<EOF
24
The <info>emails:sendNewsletter</info> command sends the newsletter email to all recipients who
25
indicate that they would like to recieve the newsletter (see Azine\EmailBundle\Entity\RecipientInterface.getNewsletter).
26
27
Depending on you Swiftmailer-Configuration the email will be send directly or will be written to the spool.
28
29
If you configured Swiftmailer to spool email, then you need to run the <info>swiftmailer:spool:send</info>
30
command to actually send the emails from the spool.
31
32
EOF
33 4
                )
34
        ;
35 4
    }
36
37
    /**
38
     * (non-PHPdoc)
39
     * @see Symfony\Component\Console\Command.Command::execute()
40
     */
41 2
    protected function execute(InputInterface $input, OutputInterface $output)
42
    {
43
        // create the lock
44 2
        $lock = new LockHandler($this->getName());
45 2
        if (!$lock->lock()) {
46
            $output->writeln('The command is already running in another process.');
47
            return 0;
48
        }
49
50 2
        $failedAddresses = array();
51 2
        $output->writeln(date(\DateTime::RFC2822)." : starting to send newsletter emails.");
52
53 2
        $sentMails = $this->getContainer()->get('azine_email_notifier_service')->sendNewsletter($failedAddresses);
54
55 2
        $output->writeln(date(\DateTime::RFC2822)." : ".str_pad($sentMails, 4, " ", STR_PAD_LEFT)." newsletter emails have been sent.");
56 2
        if (sizeof($failedAddresses) > 0) {
57 1
            $output->writeln(date(\DateTime::RFC2822)." : "."The following email-addresses failed:");
58 1
            foreach ($failedAddresses as $address) {
59 1
                $output->writeln("       ".$address);
60 1
            }
61 1
        }
62 2
    }
63
}
64