TestGenerator   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5
Metric Value
wmc 5
lcom 1
cbo 5
dl 0
loc 37
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A make() 0 4 1
A setData() 0 17 1
A write() 0 11 3
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