Completed
Push — master ( 6077fa...f4e20a )
by Pascal
02:40
created

EndpointCommand::template()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 26
ccs 9
cts 9
cp 1
rs 8.8571
cc 1
eloc 12
nc 1
nop 3
crap 1
1
<?php
2
namespace Atog\Api\Console;
3
4
use Symfony\Component\Console\Input\InputInterface;
5
use Symfony\Component\Console\Output\OutputInterface;
6
7
/**
8
 * Class EndpointCommand
9
 * @package Atog\Console
10
 */
11
class EndpointCommand extends AbstractScaffoldingCommand
12
{
13
    /**
14
     * @var string
15
     */
16
    protected $type = 'endpoint';
17
18
    /**
19
     * Execute command
20
     * @param \Symfony\Component\Console\Input\InputInterface   $input
21
     * @param \Symfony\Component\Console\Output\OutputInterface $output
22
     * @return void
23
     */
24 2
    protected function execute(InputInterface $input, OutputInterface $output)
25
    {
26 2
        if ($this->getApplication() instanceof Application) {
27 2
            $this->createFileTemplate($input, $output, $this->getApplication()->endpointPath());
28 2
        }
29 2
    }
30
31
    /**
32
     * File Template
33
     * @param string $namespace
34
     * @param string $name
35
     * @param string $topNSPart
36
     * @return string
37
     */
38 2
    protected function template($namespace, $name, $topNSPart = "Endpoints")
39
    {
40 2
        $className = str_plural($name);
41 2
        $endpointName = strtolower($name);
42 2
        $namespace = "{$namespace}\\{$topNSPart}";
43
44
        return <<< EOT
45
<?php
46
namespace $namespace;
47
48
use Atog\Api\Endpoint;
49
50
/**
51 2
 * Class $className
52 2
 * @package $namespace
53
 */
54 2
class $className extends Endpoint
55
{
56
    /**
57
     * @var string
58
     */
59 2
    protected \$endpoint = '$endpointName';
60
}
61
62 2
EOT;
63
    }
64
}
65