Factory::createCommand()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 9
Bugs 2 Features 0
Metric Value
c 9
b 2
f 0
dl 0
loc 26
ccs 0
cts 19
cp 0
rs 8.8571
cc 1
eloc 19
nc 1
nop 1
crap 2
1
<?php
2
/**
3
 * The MIT License (MIT)
4
 *
5
 * Copyright (c) 2016 Marco Muths
6
 *
7
 * Permission is hereby granted, free of charge, to any person obtaining a copy
8
 * of this software and associated documentation files (the "Software"), to deal
9
 * in the Software without restriction, including without limitation the rights
10
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
 * copies of the Software, and to permit persons to whom the Software is
12
 * furnished to do so, subject to the following conditions:
13
 *
14
 * The above copyright notice and this permission notice shall be included in all
15
 * copies or substantial portions of the Software.
16
 *
17
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
 * SOFTWARE.
24
 */
25
26
namespace Squeeze;
27
28
use Composer\Autoload\ClassLoader;
29
use Squeeze\MessageInterface as Message;
30
use Symfony\Component\Finder\Finder;
31
32
/**
33
 * @SuppressWarnings("PMD.CouplingBetweenObjects")
34
 */
35
class Factory
36
{
37
    /**
38
     * @param ClassLoader $loader
39
     * @return Application
40
     */
41
    public function create(ClassLoader $loader)
42
    {
43
        $app = new Application(Message::NAME, Message::VERSION);
44
        $app->add($this->createCommand($loader));
45
46
        return $app;
47
    }
48
49
    /**
50
     * @param ClassLoader $loader
51
     * @return Command
52
     */
53
    protected function createCommand(ClassLoader $loader)
54
    {
55
        $parser = new \PhpParser\Parser(new \PhpParser\Lexer\Emulative);
56
57
        $collector = new Collector;
58
        $filterTraverser = new \PhpParser\NodeTraverser;
59
        $filterTraverser->addVisitor(new \PhpParser\NodeVisitor\NameResolver);
60
        $filterTraverser->addVisitor($collector);
61
62
        $writerTraverser = new \PhpParser\NodeTraverser;
63
        $writerTraverser->addVisitor(new Converter);
64
        $filter = new Filter($parser, $filterTraverser, $collector, $loader);
65
        $writer = new Writer($parser, $writerTraverser, new Printer);
66
67
        $finder = new Finder;
68
        $finder->files()->name('*.php');
69
70
        $command = new Command(Message::COMMAND);
71
        $command->setHelp(Message::HELP);
72
        $command->setDescription(Message::NAME . ' (' . Message::VERSION . ')');
73
        $command->setFinder($finder);
74
        $command->setFilter($filter);
75
        $command->setWriter($writer);
76
77
        return $command;
78
    }
79
}
80