TaskExportCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 1
cbo 3
dl 38
loc 38
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 9 9 1
A execute() 12 12 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
/*
4
 * This file is part of Jitamin.
5
 *
6
 * Copyright (C) Jitamin Team
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Jitamin\Console;
13
14
use Jitamin\Foundation\Csv;
15
use Symfony\Component\Console\Input\InputArgument;
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Output\OutputInterface;
18
19
/**
20
 * Task export command class.
21
 */
22 View Code Duplication
class TaskExportCommand extends BaseCommand
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...
23
{
24
    /**
25
     * Configure the console command.
26
     *
27
     * @return void
28
     */
29
    protected function configure()
30
    {
31
        $this
32
            ->setName('export:tasks')
33
            ->setDescription('Tasks CSV export')
34
            ->addArgument('project_id', InputArgument::REQUIRED, 'Project id')
35
            ->addArgument('start_date', InputArgument::REQUIRED, 'Start date (YYYY-MM-DD)')
36
            ->addArgument('end_date', InputArgument::REQUIRED, 'End date (YYYY-MM-DD)');
37
    }
38
39
    /**
40
     * Execute the console command.
41
     *
42
     * @param InputInterface  $output
43
     * @param OutputInterface $output
44
     *
45
     * @return void
46
     */
47
    protected function execute(InputInterface $input, OutputInterface $output)
48
    {
49
        $data = $this->taskExport->export(
0 ignored issues
show
Documentation introduced by
The property taskExport does not exist on object<Jitamin\Console\TaskExportCommand>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
50
            $input->getArgument('project_id'),
51
            $input->getArgument('start_date'),
52
            $input->getArgument('end_date')
53
        );
54
55
        if (is_array($data)) {
56
            Csv::output($data);
57
        }
58
    }
59
}
60