LanguageFileService::buildFileContent()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 0
cts 14
cp 0
rs 9.7
c 0
b 0
f 0
cc 3
nc 4
nop 0
crap 12
1
<?php
2
3
namespace Webfactor\Laravel\Generators\Services;
4
5
use Webfactor\Laravel\Generators\Contracts\ServiceAbstract;
6
use Webfactor\Laravel\Generators\Contracts\ServiceInterface;
7
use Webfactor\Laravel\Generators\Helper\ShortSyntaxArray;
8
use Webfactor\Laravel\Generators\Traits\CanGenerateFile;
9
10
class LanguageFileService extends ServiceAbstract implements ServiceInterface
11
{
12
    use CanGenerateFile;
13
14
    protected $key = 'languageFile';
15
16
    public function getConsoleOutput()
17
    {
18
        return 'Added translatable names for this entity to '.$this->command->naming[$this->key]->getRelativeFilePath();
19
    }
20
21
    /**
22
     * Build the language file.
23
     *
24
     * @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...
25
     *
26
     * @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...
27
     */
28
    private function buildFileContent()
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
29
    {
30
        if ($this->filesystem->exists($this->naming->getFile())) {
31
            $translation = include $this->naming->getFile();
32
        }
33
34
        if (!isset($translation)) {
35
            $translation = [];
36
        }
37
38
        $translation = array_add($translation, $this->naming->getName(), [
39
            'singular' => $this->naming->getSingular(),
40
            'plural'   => $this->naming->getPlural(),
41
        ]);
42
43
        $this->fileContent = $this->getTranslationFileContent($translation);
44
    }
45
46
    private function getTranslationFileContent(array $translation)
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...
47
    {
48
        $content = ShortSyntaxArray::parse($translation);
49
50
        return <<<FILE
51
<?php
52
53
return {$content};
54
FILE;
55
    }
56
}
57