Passed
Push — master ( 8cc9a0...f951ba )
by karam
06:13 queued 03:49
created

KMFile::getRequestFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
nc 1
nop 1
dl 0
loc 3
c 0
b 0
f 0
cc 1
rs 10
1
<?php
2
3
4
namespace KMLaravel\ApiGenerator\Helpers;
5
6
7
use Illuminate\Support\Facades\File;
1 ignored issue
show
Bug introduced by
The type Illuminate\Support\Facades\File was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
9
class KMFile
10
{
11
    /**
12
     * @param $fileName
13
     * @return string
14
     */
15
    public static function getFilesFromStubs($fileName)
16
    {
17
        return __DIR__ . "/../Stubs/$fileName.stub";
18
    }
19
20
    /**
21
     * @param $fileName
22
     * @return string
23
     */
24
    public static function getFilesFromStubsAsStream($fileName)
25
    {
26
        return File::get(__DIR__ . "/../Stubs/$fileName.stub");
27
    }
28
29
    /**
30
     * @param $fileName
31
     * @return string
32
     */
33
    public static function getRequestFile($fileName)
34
    {
35
        return app_path("Http/Requests/$fileName");
1 ignored issue
show
Bug introduced by
The function app_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

35
        return /** @scrutinizer ignore-call */ app_path("Http/Requests/$fileName");
Loading history...
36
    }
37
38
    /**
39
     * @param $fileName
40
     * @return string
41
     */
42
    public static function getResourceFile($fileName)
43
    {
44
        return app_path("Http/Resources/$fileName");
1 ignored issue
show
Bug introduced by
The function app_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

44
        return /** @scrutinizer ignore-call */ app_path("Http/Resources/$fileName");
Loading history...
45
    }
46
47
    /**
48
     * @param $fileName
49
     * @return string
50
     */
51
    public static function getModelFile($fileName)
52
    {
53
        return app_path("$fileName");
1 ignored issue
show
Bug introduced by
The function app_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

53
        return /** @scrutinizer ignore-call */ app_path("$fileName");
Loading history...
54
    }
55
56
    /**
57
     * @param $fileName
58
     * @return string
59
     */
60
    public static function getRequestFileAsStream($fileName)
61
    {
62
        return File::get(app_path("Http/Requests/$fileName"));
1 ignored issue
show
Bug introduced by
The function app_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

62
        return File::get(/** @scrutinizer ignore-call */ app_path("Http/Requests/$fileName"));
Loading history...
63
    }
64
65
    /**
66
     * @param $fileName
67
     * @return string
68
     */
69
    public static function getModelFileAsStream($fileName)
70
    {
71
        return File::get(app_path($fileName));
1 ignored issue
show
Bug introduced by
The function app_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

71
        return File::get(/** @scrutinizer ignore-call */ app_path($fileName));
Loading history...
72
    }
73
74
    /**
75
     * @param $type
76
     * @param $className
77
     * @return string
78
     */
79
    public static function getClassNameSpace($type, $className)
80
    {
81
        if ($type == "model") {
82
            return "App\\$className";
83
        }
84
        return "App\\Http\\$type\\$className";
85
    }
86
87
    /**
88
     * @return string
89
     */
90
    public static function getCredentialJsonFilePath()
91
    {
92
        if (File::exists(resource_path("Views/ApisGenerator/credential.json"))) {
1 ignored issue
show
Bug introduced by
The function resource_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

92
        if (File::exists(/** @scrutinizer ignore-call */ resource_path("Views/ApisGenerator/credential.json"))) {
Loading history...
93
            return resource_path("Views/ApisGenerator/credential.json");
94
        }
95
    }
96
97
    /**
98
     * @return mixed
99
     */
100
    public static function getCredentialJsonFileAsJson()
101
    {
102
        if (File::exists(resource_path("Views/ApisGenerator/credential.json"))) {
1 ignored issue
show
Bug introduced by
The function resource_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

102
        if (File::exists(/** @scrutinizer ignore-call */ resource_path("Views/ApisGenerator/credential.json"))) {
Loading history...
103
            return json_decode(File::get(self::getCredentialJsonFilePath()));
104
        }
105
    }
106
107
    /**
108
     * @param $newData
109
     */
110
    public static function setDataToCredentialJsonFile($newData)
111
    {
112
        $data = self::getCredentialJsonFileAsJson();
113
114
        array_push($data, $newData);
0 ignored issues
show
Bug introduced by
It seems like $data can also be of type null; however, parameter $array of array_push() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

114
        array_push(/** @scrutinizer ignore-type */ $data, $newData);
Loading history...
115
116
        File::put(self::getCredentialJsonFilePath(), json_encode($data));
117
    }
118
119
    /**
120
     * @return bool
121
     */
122
    public static function baseControllerExists()
123
    {
124
        return File::exists(static::baseControllerPath());
125
    }
126
127
    /**
128
     * @return string
129
     */
130
    public static function baseControllerPath()
131
    {
132
        return app_path("Http/Controllers/BaseController.php");
1 ignored issue
show
Bug introduced by
The function app_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

132
        return /** @scrutinizer ignore-call */ app_path("Http/Controllers/BaseController.php");
Loading history...
133
    }
134
}
135