DocsGeneratorTrait   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 141
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 0
Metric Value
wmc 14
lcom 2
cbo 1
dl 0
loc 141
rs 10
c 0
b 0
f 0

13 Methods

Rating   Name   Duplication   Size   Complexity  
A getFullApiUrl() 0 4 1
A getAppUrl() 0 4 1
A getHtmlPath() 0 4 1
A getDocumentationPath() 0 4 1
A getJsonFilePath() 0 4 1
A getConfigFile() 0 4 1
A getTypeConfig() 0 4 1
A getExecutable() 0 4 1
A getSwaggerConverter() 0 4 1
A getUrl() 0 6 1
A getEndpointFiles() 0 14 2
A replace() 0 4 1
A minutesToTimeDisplay() 0 9 1
1
<?php
2
3
namespace App\Containers\Documentation\Traits;
4
5
use DateTime;
6
use Illuminate\Support\Facades\Config;
7
8
/**
9
 * Class DocsGeneratorTrait
10
 *
11
 * @author  Mahmoud Zalt  <[email protected]>
12
 */
13
trait DocsGeneratorTrait
14
{
15
16
    /**
17
     * @param $type
18
     *
19
     * @return mixed
20
     */
21
    private function getFullApiUrl($type)
22
    {
23
        return '> ' . $this->getAppUrl() . '/' . $this->getUrl($type);
24
    }
25
26
    /**
27
     * @return  mixed
28
     */
29
    private function getAppUrl()
30
    {
31
        return Config::get('app.url');
32
    }
33
34
    /**
35
     * @return  mixed
36
     */
37
    private function getHtmlPath()
38
    {
39
        return Config::get("{$this->getConfigFile()}.html_files");
40
    }
41
42
    /**
43
     * Where to generate the new documentation.
44
     *
45
     * @param $type
46
     *
47
     * @return string
48
     */
49
    private function getDocumentationPath($type)
50
    {
51
        return $this->getHtmlPath() . $this->getUrl($type);
52
    }
53
54
    /**
55
     * @param $type
56
     *
57
     * @return string
58
     */
59
    private function getJsonFilePath($type)
60
    {
61
        return "app/Containers/Documentation/ApiDocJs/{$type}";
62
    }
63
64
    /**
65
     * @return  string
66
     */
67
    private function getConfigFile()
68
    {
69
        return 'documentation-container';
70
    }
71
72
    /**
73
     * @return  mixed
74
     */
75
    private function getTypeConfig()
76
    {
77
        return Config::get($this->getConfigFile() . '.types');
78
    }
79
80
    /**
81
     * @return  mixed
82
     */
83
    private function getExecutable()
84
    {
85
        return Config::get($this->getConfigFile() . '.executable');
86
    }
87
88
    /**
89
     * @return  mixed
90
     */
91
    private function getSwaggerConverter()
92
    {
93
        return Config::get($this->getConfigFile() . '.swagger-converter');
94
    }
95
96
    /**
97
     * @param $type
98
     *
99
     * @return  mixed
100
     */
101
    private function getUrl($type)
102
    {
103
        $configs = $this->getTypeConfig();
104
105
        return $configs[$type]['url'];
106
    }
107
108
    /**
109
     * @param $type
110
     *
111
     * @return  string
112
     */
113
    private function getEndpointFiles($type)
114
    {
115
        $configs = $this->getTypeConfig();
116
117
        // what files types needs to be included
118
        $routeFilesCommand = '';
119
        $routes = $configs[$type]['routes'];
120
121
        foreach ($routes as $route) {
122
            $routeFilesCommand .= '-f ' . $route . '.php ';
123
        }
124
125
        return $routeFilesCommand;
126
    }
127
128
129
    /**
130
     * @param $templateKey
131
     * @param $value
132
     */
133
    private function replace($templateKey, $value)
134
    {
135
        $this->headerMarkdownContent = str_replace($templateKey, $value, $this->headerMarkdownContent);
0 ignored issues
show
Bug introduced by Mahmoud Zalt
The property headerMarkdownContent 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...
136
    }
137
138
    /**
139
     * @param $minutes
140
     *
141
     * @return  string
142
     */
143
    private function minutesToTimeDisplay($minutes)
144
    {
145
        $seconds = $minutes * 60;
146
147
        $dtF = new DateTime('@0');
148
        $dtT = new DateTime("@$seconds");
149
150
        return $dtF->diff($dtT)->format('%a days, %h hours, %i minutes and %s seconds');
151
    }
152
153
}
154