Completed
Push — master ( 1e6a21...8dd974 )
by Ma
05:29
created

DumpFileCommandAwareTrait   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 22
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 1
c 2
b 0
f 0
lcom 0
cbo 1
dl 22
loc 22
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A write() 12 12 1

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
/**
4
 * Aist Filesystem Component (http://mateuszsitek.com/projects/filesystem)
5
 *
6
 * @copyright Copyright (c) 2017 DIGITAL WOLVES LTD (http://digitalwolves.ltd) All rights reserved.
7
 * @license   http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause
8
 */
9
10
namespace Aist\Filesystem\Console\Command\Traits;
11
12
use Symfony\Component\Console\Input\ArrayInput;
13
use Symfony\Component\Console\Output\OutputInterface;
14
15 View Code Duplication
trait DumpFileCommandAwareTrait
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...
16
{
17
    /**
18
     * @param OutputInterface $output
19
     * @param $target
20
     * @param $content
21
     *
22
     * @return integer
23
     */
24
    private function write(OutputInterface $output, $target, $content)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
25
    {
26
        $command = $this->getApplication()->find('filesystem:dump-file');
0 ignored issues
show
Bug introduced by
It seems like getApplication() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
27
28
        $input = new ArrayInput([
29
            'command' => $command->getName(),
30
            '--target' => $target,
31
            '--content' => $content,
32
        ]);
33
34
        return $command->run($input, $output);
35
    }
36
}
37