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

FetchFromCommand::execute()   A

Complexity

Conditions 2
Paths 4

Size

Total Lines 13
Code Lines 8

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
dl 13
loc 13
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 4
nop 2
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 FetchFromCommand 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:fetchFrom')
17
            ->setDefinition(array(
18
                new InputArgument('remoteFile', InputArgument::REQUIRED, 'Full path to remote file'),
19
                new InputArgument('localFile', InputArgument::REQUIRED, 'Full path to local file')
20
            ))
21
            ->setDescription('Copy file from remote SFTP server to local machine')
22
            ->setHelp("
23
                The <info>./app/console sftp:copy</info> command copies file from remote SFTP server to your local machine by specified path:
24
                Command example:
25
                  <info>./app/console sftp:copy /path/to/remoteFile.txt /path/to/localFile.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 fetching file from remote SFTP server.');
39
            $sftp->fetchFrom($input->getArgument('remoteFile'), $input->getArgument('localFile'));
40
            $output->writeln('Successful file transfer from the SFTP server.');
41
        } catch (\Exception $e) {
42
            $output->writeln('File transfer failed.');
43
        }
44
    }
45
}
46