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

FetchFromCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 35
loc 35
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 15 15 1
A execute() 13 13 2

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
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