Passed
Push — master ( 3cb518...ba9ea6 )
by Thomas
40s
created

RouteService   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 49
ccs 0
cts 28
cp 0
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A call() 0 10 2
A getRouteName() 0 4 1
A getControllerName() 0 4 1
A writeFile() 0 4 1
A getFilePath() 0 4 1
A getRouteString() 0 4 1
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