Completed
Push — master ( 06b292...adafac )
by Nicolai
02:22
created

BaseGenerator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 71
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getTemplate() 0 4 1
A getSuite() 0 4 1
A produce() 0 4 1
A getNamespaceForTest() 0 4 1
1
<?php
2
3
4
namespace SmartWeb\ModuleTesting\Codeception\Generator;
5
6
use Codeception\Util\Shared\Namespaces;
7
use SmartWeb\ModuleTesting\Codeception\Template\TemplateFactory;
8
use SmartWeb\ModuleTesting\Codeception\Template\TemplateFactoryInterface;
9
use SmartWeb\ModuleTesting\Codeception\Template\TemplateInterface;
10
use SmartWeb\ModuleTesting\Util\UsesDisk;
11
12
13
abstract class BaseGenerator implements Generator
14
{
15
    
16
    use Namespaces, UsesDisk;
17
    
18
    /**
19
     * @var string
20
     */
21
    private $suite;
22
    
23
    /**
24
     * @var string
25
     */
26
    private $template;
27
    
28
    /**
29
     * @var TemplateFactoryInterface
30
     */
31
    private $factory;
32
    
33
    /**
34
     * @var array
35
     */
36
    protected $settings;
37
    
38
    /**
39
     * BaseGenerator constructor.
40
     *
41
     * @param string $suite
42
     * @param string $template
43
     */
44
    public function __construct(string $suite, string $template)
45
    {
46
        $this->suite = $suite;
47
        $this->template = $template;
48
        $this->factory = new TemplateFactory();
49
    }
50
    
51
    /**
52
     * @return TemplateInterface
53
     */
54
    final public function getTemplate() : TemplateInterface
55
    {
56
        return $this->factory->getTemplate($this->template);
57
    }
58
    
59
    /**
60
     * @return string
61
     */
62
    final protected function getSuite() : string
63
    {
64
        return $this->suite;
65
    }
66
    
67
    /**
68
     * @return string
69
     */
70
    public function produce() : string
71
    {
72
        return $this->getTemplate()->produceWith($this->settings);
73
    }
74
    
75
    /**
76
     * @return string
77
     */
78
    protected function getNamespaceForTest() : string
79
    {
80
        return $this->settings['namespace'] . '\\' . $this->settings['testsDir'] . '\\' . $this->getSuite() . '\\' . $this->getNamespaceString($this->name);
0 ignored issues
show
Bug introduced by
The property name does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
81
    }
82
    
83
}