Passed
Pull Request — master (#2)
by Thomas
03:05
created

RouteService::getRouteString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Webfactor\Laravel\Generators\Services;
4
5
use Illuminate\Filesystem\Filesystem;
6
use Webfactor\Laravel\Generators\Commands\MakeEntity;
7
use Webfactor\Laravel\Generators\Contracts\ServiceAbstract;
8
use Webfactor\Laravel\Generators\Contracts\ServiceInterface;
9
10
class RouteService extends ServiceAbstract implements ServiceInterface
11
{
12
    protected $relativeToBasePath = 'routes';
13
14
    private $adminFile;
15
16
    public function call()
17
    {
18
        $this->adminFile = $this->getFilePath();
19
20
        if ($this->filesystem->exists($this->adminFile)) {
21
            $this->writeFile();
22
        }
23
24
        $this->addLatestFileToIdeStack();
25
    }
26
27
    private function getRouteName(): string
28
    {
29
        return strtolower($this->command->entity);
30
    }
31
32
    private function getControllerName(): string
33
    {
34
        return ucfirst($this->command->entity) . 'CrudController';
35
    }
36
37
    /**
38
     * Build the class with the given name.
39
     *
40
     * @param string $name
0 ignored issues
show
Bug introduced by
There is no parameter named $name. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
41
     *
42
     * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be string|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
43
     */
44
    private function writeFile()
45
    {
46
        $this->filesystem->append($this->adminFile, $this->getRouteString());
47
    }
48
49
    private function getFilePath()
50
    {
51
        return base_path('routes') . '/admin.php';
52
    }
53
54
    private function getRouteString()
55
    {
56
        return "\r\n" . 'CRUD::resource(\'' . $this->getRouteName() . '\', \'' . $this->getControllerName() . '\');';
57
    }
58
}
59