AliasManagementTaskFactory::create()   D
last analyzed

Complexity

Conditions 9
Paths 8

Size

Total Lines 32
Code Lines 20

Duplication

Lines 15
Ratio 46.88 %

Code Coverage

Tests 11
CRAP Score 17.7468

Importance

Changes 0
Metric Value
dl 15
loc 32
ccs 11
cts 21
cp 0.5238
rs 4.909
c 0
b 0
f 0
cc 9
eloc 20
nc 8
nop 2
crap 17.7468
1
<?php
2
namespace Samurai\Alias\Task\Factory;
3
4
use Pimple\Container;
5
use Samurai\Alias\AliasCommand;
6
use Samurai\Alias\Task\Listing;
7
use Samurai\Alias\Task\Removing;
8
use Samurai\Alias\Task\Saving;
9
use Samurai\Task\ITask;
10
use SimilarText\Finder;
11
use Symfony\Component\Console\Input\InputInterface;
12
13
/**
14
 * Class TaskFactory
15
 * @package Samurai\Alias\Task\Factory
16
 * @author Raphaël Lefebvre <[email protected]>
17
 */
18
class AliasManagementTaskFactory
19
{
20
    /**
21
     * @param InputInterface $input
22
     * @param Container $services
23
     * @return ITask
24
     */
25 9
    public function create(InputInterface $input, Container $services)
26
    {
27 9
        if(!$input->getArgument('action')){
28
            throw new \InvalidArgumentException(sprintf('An action param is required: %s', json_encode(AliasCommand::$actions)));
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 129 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
29
        }
30
31 9
        if($input->getArgument('action') === 'list'){
32 4
            return new Listing($services);
33
        }
34 5 View Code Duplication
        if($input->getArgument('action') === 'save'){
35 2
            if(!$input->getArgument('name')){
36
                throw new \InvalidArgumentException('name param is mandatory for this action');
37
            }
38 2
            if(!$input->getArgument('bootstrap')){
39
                throw new \InvalidArgumentException('bootstrap param is mandatory for this action');
40
            }
41 2
            return new Saving($services);
42
        }
43 3 View Code Duplication
        if($input->getArgument('action') === 'rm' || $input->getArgument('action') === 'remove'){
44 3
            if(!$input->getArgument('name')){
45
                throw new \InvalidArgumentException('name param is mandatory for this action');
46
            }
47 3
            return new Removing($services);
48
        }
49
50
        $textFinder = new Finder($input->getArgument('action'), AliasCommand::$actions);
51
        throw new \InvalidArgumentException(sprintf(
52
            'Action "%s" not supported. Did you mean "%s"?',
53
            $input->getArgument('action'),
54
            $textFinder->first()
55
        ));
56
    }
57
}
58