Passed
Push — master ( 672a66...8833c5 )
by Thomas
04:32 queued 02:11
created

SidebarService::call()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 8
cp 0
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
crap 6
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 SidebarService extends ServiceAbstract implements ServiceInterface
11
{
12
    protected $relativeToBasePath = 'resources/views/vendor/backpack/base/inc';
13
14
    protected $fileName = 'sidebar_content.blade.php';
15
16
    private $sidebarFile;
17
18
    public function call()
19
    {
20
        $this->sidebarFile = $this->getFilePath();
21
22
        if ($this->filesystem->exists($this->sidebarFile)) {
23
            $this->writeFile();
24
            $this->addLatestFileToIdeStack();
25
        }
26
    }
27
28
    private function getRouteName(): string
29
    {
30
        return strtolower($this->command->entity);
31
    }
32
33
    private function getLanguageName(): string
34
    {
35
        return snake_case($this->command->entity);
36
    }
37
38
    /**
39
     * Build the class with the given name.
40
     *
41
     * @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...
42
     *
43
     * @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...
44
     */
45
    private function writeFile()
46
    {
47
        $this->filesystem->append($this->sidebarFile, $this->getRouteString());
48
    }
49
50
    private function getFilePath()
51
    {
52
        return base_path($this->relativeToBasePath) . '/' . $this->fileName;
53
    }
54
55
    private function getRouteString()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
56
    {
57
        return <<<FILE
58
59
<li>
60
    <a href="{{ backpack_url('{$this->getRouteName()}') }}">
61
        <i class="fa fa-question"></i><span>{{ trans('models.{$this->getLanguageName()}.plural') }}</span>
62
    </a>
63
</li>
64
FILE;
65
    }
66
}
67