Completed
Push — master ( c4ad0d...36d425 )
by Nikolay
03:34
created

Gen::getTemplate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
class Gen
4
{
5
    /** @var string */
6
    protected $test_dir_path;
7
8
    /** @var string */
9
    protected $src_dir_path;
10
11
    protected $template_path;
12
13
    public function __construct()
14
    {
15
        $this->test_dir_path = __DIR__ . '/tests/Unit/Message/Traits/ModelField/';
16
        $this->src_dir_path  = __DIR__ . '/src/CloudPayments/Message/Traits/ModelField/';
17
        $this->template_path = __DIR__ . '/tests/Unit/Message/Traits/ModelField/AccountIdStringTest.php';
18
    }
19
20
    public function run()
21
    {
22
        $template = $this->getTemplate();
23
        foreach (glob(sprintf('%s*.php', $this->src_dir_path)) as $filename) {
24
            $basename = basename($filename, '.php');
25
26
            if (preg_match('/(.*)(Bool|BoolNull)$/', $basename, $matches)) {
27
                $class_name      = $matches[0];
28
                $method_sub_name = $matches[1];
29
                $type            = $matches[2];
0 ignored issues
show
Unused Code introduced by
The assignment to $type is dead and can be removed.
Loading history...
30
31
                $content = str_replace('AccountIdString', $class_name, $template);
32
                $content = str_replace('AccountId', $method_sub_name, $content);
33
34
35
                $test_file_path = str_replace('AccountIdStringTest', $class_name . 'Test', $this->template_path);
36
                file_put_contents($test_file_path, $content);
37
            }
38
        }
39
    }
40
41
    protected function getTemplate(): string
42
    {
43
        return file_get_contents($this->template_path);
44
    }
45
}
46
47
$gen = new Gen;
48
49
$gen->run();