This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php namespace Anomaly\Streams\Platform\Image; |
||
2 | |||
3 | use Anomaly\FilesModule\File\Contract\FileInterface; |
||
4 | use Anomaly\Streams\Platform\Application\Application; |
||
5 | use Illuminate\Contracts\Config\Repository; |
||
6 | use Illuminate\Http\Request; |
||
7 | |||
8 | /** |
||
9 | * Class ImagePaths |
||
10 | * |
||
11 | * @link http://pyrocms.com/ |
||
12 | * @author PyroCMS, Inc. <[email protected]> |
||
13 | * @author Ryan Thompson <[email protected]> |
||
14 | */ |
||
15 | class ImagePaths |
||
16 | { |
||
17 | |||
18 | /** |
||
19 | * Predefined paths. |
||
20 | * |
||
21 | * @var array |
||
22 | */ |
||
23 | protected $paths = []; |
||
24 | |||
25 | /** |
||
26 | * The config repository. |
||
27 | * |
||
28 | * @var Repository |
||
29 | */ |
||
30 | protected $config; |
||
31 | |||
32 | /** |
||
33 | * The request object. |
||
34 | * |
||
35 | * @var Request |
||
36 | */ |
||
37 | protected $request; |
||
38 | |||
39 | /** |
||
40 | * The application object. |
||
41 | * |
||
42 | * @var Application |
||
43 | */ |
||
44 | protected $application; |
||
45 | |||
46 | /** |
||
47 | * Create a new ImagePaths instance. |
||
48 | * |
||
49 | * @param Repository $config |
||
50 | * @param Request $request |
||
51 | * @param Application $application |
||
52 | */ |
||
53 | View Code Duplication | public function __construct(Repository $config, Request $request, Application $application) |
|
0 ignored issues
–
show
Bug
introduced
by
![]() This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
54 | { |
||
55 | $this->config = $config; |
||
56 | $this->request = $request; |
||
57 | $this->application = $application; |
||
58 | |||
59 | $this->paths = $config->get('streams::images.paths', []); |
||
0 ignored issues
–
show
It seems like
$config->get('streams::images.paths', array()) of type * is incompatible with the declared type array of property $paths .
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property. Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.. ![]() |
|||
60 | } |
||
61 | |||
62 | /** |
||
63 | * Get the paths. |
||
64 | * |
||
65 | * @return array|mixed |
||
66 | */ |
||
67 | public function getPaths() |
||
68 | { |
||
69 | return $this->paths; |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * Set the paths. |
||
74 | * |
||
75 | * @param array $paths |
||
76 | * @return $this |
||
77 | */ |
||
78 | public function setPaths(array $paths) |
||
79 | { |
||
80 | $this->paths = $paths; |
||
81 | |||
82 | return $this; |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | * Add an image path hint. |
||
87 | * |
||
88 | * @param $namespace |
||
89 | * @param $path |
||
90 | * @return $this |
||
91 | */ |
||
92 | public function addPath($namespace, $path) |
||
93 | { |
||
94 | $this->paths[$namespace] = rtrim($path, '/\\'); |
||
95 | |||
96 | return $this; |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * Return the real path for a given path. |
||
101 | * |
||
102 | * @param $path |
||
103 | * @return string |
||
104 | * @throws \Exception |
||
105 | */ |
||
106 | public function realPath($path) |
||
107 | { |
||
108 | if (str_contains($path, '::')) { |
||
109 | list($namespace, $path) = explode('::', $path); |
||
110 | |||
111 | if (!isset($this->paths[$namespace])) { |
||
112 | throw new \Exception("Path hint [{$namespace}::{$path}] does not exist!"); |
||
113 | } |
||
114 | |||
115 | return rtrim($this->paths[$namespace], '/') . '/' . $path; |
||
116 | } |
||
117 | |||
118 | return $path; |
||
119 | } |
||
120 | |||
121 | /** |
||
122 | * Return the output path for an image. |
||
123 | * |
||
124 | * @param $path |
||
125 | * @return string |
||
126 | */ |
||
127 | public function outputPath(Image $image) |
||
128 | { |
||
129 | $path = $image->getImage(); |
||
130 | |||
131 | if ($path instanceof FileInterface) { |
||
0 ignored issues
–
show
The class
Anomaly\FilesModule\File\Contract\FileInterface does not exist. Did you forget a USE statement, or did you not list all dependencies?
This error could be the result of: 1. Missing dependenciesPHP Analyzer uses your Are you sure this class is defined by one of your dependencies, or did you maybe
not list a dependency in either the 2. Missing use statementPHP does not complain about undefined classes in if ($x instanceof DoesNotExist) {
// Do something.
}
If you have not tested against this specific condition, such errors might go unnoticed. ![]() |
|||
132 | $path = $path->path(); |
||
133 | } |
||
134 | |||
135 | /* |
||
136 | * If the path is already public |
||
137 | * then just use it as it is. |
||
138 | */ |
||
139 | if (str_contains($path, public_path())) { |
||
140 | return str_replace(public_path(), '', $path); |
||
141 | } |
||
142 | |||
143 | /* |
||
144 | * If the path is a file or file path then |
||
145 | * put it in /app/{$application}/files/disk/folder/filename.ext |
||
146 | */ |
||
147 | if (is_string($path) && str_is('*://*', $path)) { |
||
148 | |||
149 | $application = $this->application->getReference(); |
||
150 | |||
151 | list($disk, $folder, $filename) = explode('/', str_replace('://', '/', $path)); |
||
152 | |||
153 | View Code Duplication | if ($image->getAlterations() || $image->getQuality()) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
154 | $filename = md5( |
||
155 | var_export([$path, $image->getAlterations()], true) . $image->getQuality() |
||
156 | ) . '.' . $image->getExtension(); |
||
157 | } |
||
158 | |||
159 | if ($rename = $image->getFilename()) { |
||
160 | |||
161 | $filename = $rename; |
||
162 | |||
163 | if (strpos($filename, DIRECTORY_SEPARATOR)) { |
||
164 | $directory = null; |
||
0 ignored issues
–
show
$directory is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
165 | } |
||
166 | } |
||
167 | |||
168 | return "/app/{$application}/files/{$disk}/{$folder}/{$filename}"; |
||
169 | } |
||
170 | |||
171 | /* |
||
172 | * Get the real path relative to our installation. |
||
173 | */ |
||
174 | $path = str_replace(base_path(), '', $this->realPath($path)); |
||
175 | |||
176 | /* |
||
177 | * Build out path parts. |
||
178 | */ |
||
179 | $filename = basename($path); |
||
180 | $directory = ltrim(dirname($path), '/\\') . '/'; |
||
181 | $application = $this->application->getReference(); |
||
182 | |||
183 | View Code Duplication | if ($image->getAlterations() || $image->getQuality()) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
184 | $filename = md5( |
||
185 | var_export([$path, $image->getAlterations()], true) . $image->getQuality() |
||
186 | ) . '.' . $image->getExtension(); |
||
187 | } |
||
188 | |||
189 | if ($rename = $image->getFilename()) { |
||
190 | $directory = null; |
||
191 | $filename = ltrim($rename, '/\\'); |
||
192 | } |
||
193 | |||
194 | return "/app/{$application}/assets/{$directory}{$filename}"; |
||
195 | } |
||
196 | } |
||
197 |