TestGenerator::write()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 11
rs 9.4285
cc 3
eloc 5
nc 2
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