DocsGeneratorTrait   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 133
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

Changes 0
Metric Value
wmc 13
lcom 2
cbo 0
dl 0
loc 133
rs 10
c 0
b 0
f 0

12 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 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
     * @param $type
90
     *
91
     * @return  mixed
92
     */
93
    private function getUrl($type)
94
    {
95
        $configs = $this->getTypeConfig();
96
97
        return $configs[$type]['url'];
98
    }
99
100
    /**
101
     * @param $type
102
     *
103
     * @return  string
104
     */
105
    private function getEndpointFiles($type)
106
    {
107
        $configs = $this->getTypeConfig();
108
109
        // what files types needs to be included
110
        $routeFilesCommand = '';
111
        $routes = $configs[$type]['routes'];
112
113
        foreach ($routes as $route) {
114
            $routeFilesCommand .= '-f ' . $route . '.php ';
115
        }
116
117
        return $routeFilesCommand;
118
    }
119
120
121
    /**
122
     * @param $templateKey
123
     * @param $value
124
     */
125
    private function replace($templateKey, $value)
126
    {
127
        $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...
128
    }
129
130
    /**
131
     * @param $minutes
132
     *
133
     * @return  string
134
     */
135
    private function minutesToTimeDisplay($minutes)
136
    {
137
        $seconds = $minutes * 60;
138
139
        $dtF = new DateTime('@0');
140
        $dtT = new DateTime("@$seconds");
141
142
        return $dtF->diff($dtT)->format('%a days, %h hours, %i minutes and %s seconds');
143
    }
144
145
}
146