TestGenerator::setData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 17
rs 9.4285
cc 1
eloc 10
nc 1
nop 1
1
<?php
2
3
namespace Factory\Generators;
4
5
use Illuminate\Support\Str;
6
use Factory\Utils;
7
8
class TestGenerator extends BaseGenerator
9
{
10
    function make()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
11
    {
12
        return $this->generate('test.txt', []);
13
    }
14
15
    public function setData($data)
16
    {
17
        $fullClassName = $this->composer->getClassNamespace($data['name']);
18
19
        $testName = str_replace("\\", "", Str::substr($fullClassName, strlen($this->composer->getRootNamespace()) + 1)) . 'Test';
20
21
        $data = array_merge([
22
            'namespace' => Utils::getJustNamespace($fullClassName),
23
            'className' => Utils::getJustClassName($fullClassName),
24
            'testName' => $testName
25
        ], $data);
26
27
28
29
        $this->data = $data;
30
        return $this;
31
    }
32
33
    public function write($data)
34
    {
35
        $destination = $this->composer->getTestPath($this->data['name']);
36
37
        if($this->force && $this->external->has($destination))
38
        {
39
            $this->external->delete($destination);
40
        }
41
42
        return $this->external->write($destination, $data);
43
    }
44
}
45