Completed
Push — develop ( 6c7b5f...11a3b8 )
by Novikov
01:25
created

SendToCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 8

Duplication

Lines 15
Ratio 100 %

Importance

Changes 0
Metric Value
dl 15
loc 15
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
namespace SF2Helpers\SFTPBundle\Command;
4
5
use SF2Helpers\SFTPBundle\SFTP\SFTP;
6
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11 View Code Duplication
class SendToCommand extends ContainerAwareCommand
0 ignored issues
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...
12
{
13
    protected function configure()
14
    {
15
        $this
16
            ->setName('sf2h:sftp:sendTo')
17
            ->setDefinition(array(
18
                new InputArgument('localFile', InputArgument::REQUIRED, 'Full path to local file'),
19
                new InputArgument('remoteFile', InputArgument::REQUIRED, 'Full path to remote file')
20
            ))
21
            ->setDescription('Send file to remote SFTP server from local machine')
22
            ->setHelp("
23
                The <info>./app/console sftp:send</info> command copies file to remote SFTP server from your local machine by specified path:
24
                Command example:
25
                  <info>./app/console sftp:send /path/to/localFile.txt /path/to/remoteFile.txt</info>
26
            ");
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    protected function execute(InputInterface $input, OutputInterface $output)
33
    {
34
        /** @var SFTP $sftp */
35
        $sftp = $this->get('sftp');
36
37
        try {
38
            $output->writeln('Started sending file to remote SFTP server.');
39
            $sftp->sendTo($input->getArgument('localFile'), $input->getArgument('remoteFile'));
40
            $output->writeln('Successful sending file to the SFTP server.');
41
        } catch (\Exception $e) {
42
            $output->writeln('File transfer failed.');
43
        }
44
    }
45
}
46