mnabialek /
laravel-modular
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 |
||
| 2 | |||
| 3 | namespace Mnabialek\LaravelModular\Models; |
||
| 4 | |||
| 5 | use Mnabialek\LaravelModular\Services\Config; |
||
| 6 | use Mnabialek\LaravelModular\Traits\Replacer; |
||
| 7 | use Mnabialek\LaravelModular\Traits\Normalizer; |
||
| 8 | use Illuminate\Contracts\Foundation\Application; |
||
| 9 | |||
| 10 | class Module |
||
| 11 | { |
||
| 12 | use Normalizer, Replacer; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @var |
||
| 16 | */ |
||
| 17 | protected $name; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @var array |
||
| 21 | */ |
||
| 22 | protected $options; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var Config |
||
| 26 | */ |
||
| 27 | protected $config; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var Application |
||
| 31 | */ |
||
| 32 | protected $laravel; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Module constructor. |
||
| 36 | * |
||
| 37 | * @param string $name |
||
| 38 | * @param Application $application |
||
| 39 | * @param array $options |
||
| 40 | */ |
||
| 41 | public function __construct( |
||
| 42 | $name, |
||
| 43 | Application $application, |
||
| 44 | array $options = [] |
||
| 45 | ) { |
||
| 46 | $this->name = $name; |
||
| 47 | $this->options = collect($options); |
||
|
0 ignored issues
–
show
|
|||
| 48 | $this->laravel = $application; |
||
| 49 | $this->config = $application['modular.config']; |
||
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Get module name |
||
| 54 | * |
||
| 55 | * @return string |
||
| 56 | */ |
||
| 57 | public function name() |
||
| 58 | { |
||
| 59 | return $this->name; |
||
| 60 | } |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Get module seeder class name (with namespace) |
||
| 64 | * |
||
| 65 | * @param string|null $class |
||
| 66 | * |
||
| 67 | * @return string |
||
| 68 | */ |
||
| 69 | public function seederClass($class = null) |
||
| 70 | { |
||
| 71 | return $this->fileClass('seeder', $class); |
||
| 72 | } |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Get module service provider class |
||
| 76 | * |
||
| 77 | * @return string |
||
| 78 | */ |
||
| 79 | public function serviceProviderClass() |
||
| 80 | { |
||
| 81 | return $this->fileClass('serviceProvider'); |
||
| 82 | } |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Get file class |
||
| 86 | * |
||
| 87 | * @param string $type |
||
| 88 | * @param string|null $class |
||
| 89 | * |
||
| 90 | * @return string |
||
| 91 | */ |
||
| 92 | protected function fileClass($type, $class = null) |
||
| 93 | { |
||
| 94 | $filename = $type . 'File'; |
||
| 95 | $namespace = $type . 'Namespace'; |
||
| 96 | |||
| 97 | $class = $class ?: basename($this->config->$filename(), '.php'); |
||
| 98 | |||
| 99 | return $this->replace($this->config->modulesNamespace() . '\\' . |
||
| 100 | $this->name() . '\\' . $this->config->$namespace() . '\\' . |
||
| 101 | $class, $this); |
||
| 102 | } |
||
| 103 | |||
| 104 | /** |
||
| 105 | * Get module directory |
||
| 106 | * |
||
| 107 | * @return string |
||
| 108 | */ |
||
| 109 | public function directory() |
||
| 110 | { |
||
| 111 | return $this->normalizePath($this->config->directory()) . |
||
| 112 | DIRECTORY_SEPARATOR . $this->name(); |
||
| 113 | } |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Get module migrations path |
||
| 117 | * |
||
| 118 | * @param bool $relative |
||
| 119 | * |
||
| 120 | * @return string |
||
| 121 | */ |
||
| 122 | public function migrationsPath($relative = false) |
||
| 123 | { |
||
| 124 | $path = $this->normalizePath($this->config->migrationsPath()); |
||
| 125 | |||
| 126 | return $relative ? $path : $this->directory() . DIRECTORY_SEPARATOR . $path; |
||
| 127 | } |
||
| 128 | |||
| 129 | /** |
||
| 130 | * Verify whether module has service provider |
||
| 131 | * |
||
| 132 | * @return bool |
||
| 133 | */ |
||
| 134 | public function hasServiceProvider() |
||
| 135 | { |
||
| 136 | return $this->hasFile('provider', 'serviceProviderFilePath'); |
||
| 137 | } |
||
| 138 | |||
| 139 | /** |
||
| 140 | * Verifies whether module has factory |
||
| 141 | * |
||
| 142 | * @return bool |
||
| 143 | */ |
||
| 144 | public function hasFactory() |
||
| 145 | { |
||
| 146 | return $this->hasFile('factory', 'factoryFilePath'); |
||
| 147 | } |
||
| 148 | |||
| 149 | /** |
||
| 150 | * Verifies whether module has routes file |
||
| 151 | * |
||
| 152 | * @param array $data |
||
| 153 | * |
||
| 154 | * @return bool |
||
| 155 | */ |
||
| 156 | public function hasRoutes(array $data = []) |
||
| 157 | { |
||
| 158 | $prefix = $this->routePrefix($data); |
||
| 159 | |||
| 160 | return $this->hasFile('routes', 'routesFilePath', $prefix); |
||
| 161 | } |
||
| 162 | |||
| 163 | /** |
||
| 164 | * Verifies whether module has seeder file |
||
| 165 | * |
||
| 166 | * @return bool |
||
| 167 | */ |
||
| 168 | public function hasSeeder() |
||
| 169 | { |
||
| 170 | return $this->hasFile('seeder', 'seederFilePath'); |
||
| 171 | } |
||
| 172 | |||
| 173 | /** |
||
| 174 | * Verifies whether module has file of given type either checking config |
||
| 175 | * and if it's not exist by checking whether file exists |
||
| 176 | * |
||
| 177 | * @param string $option |
||
| 178 | * @param string $pathFunction |
||
| 179 | * @param string $prefix |
||
| 180 | * |
||
| 181 | * @return bool |
||
| 182 | */ |
||
| 183 | protected function hasFile($option, $pathFunction, $prefix = '') |
||
| 184 | { |
||
| 185 | return (bool)($this->options->has($prefix . $option) ? |
||
|
0 ignored issues
–
show
|
|||
| 186 | $this->options->get($prefix . $option) : |
||
|
0 ignored issues
–
show
|
|||
| 187 | $this->laravel['files']->exists($this->laravel['path.base'] . |
||
| 188 | DIRECTORY_SEPARATOR . $this->$pathFunction($prefix))); |
||
| 189 | } |
||
| 190 | |||
| 191 | /** |
||
| 192 | * Get controller namespace for routing |
||
| 193 | * |
||
| 194 | * @return string |
||
| 195 | */ |
||
| 196 | public function routingControllerNamespace() |
||
| 197 | { |
||
| 198 | return $this->config->modulesNamespace() . '\\' . $this->name() . '\\' . |
||
| 199 | $this->config->routingControllerNamespace(); |
||
| 200 | } |
||
| 201 | |||
| 202 | /** |
||
| 203 | * Get module routes file (with path) |
||
| 204 | * |
||
| 205 | * @param string $prefix |
||
| 206 | * |
||
| 207 | * @return string |
||
| 208 | */ |
||
| 209 | public function routesFilePath($prefix) |
||
| 210 | { |
||
| 211 | return $this->getPath('routingFile', $prefix); |
||
| 212 | } |
||
| 213 | |||
| 214 | /** |
||
| 215 | * Get route prefix |
||
| 216 | * |
||
| 217 | * @param array $data |
||
| 218 | * |
||
| 219 | * @return string |
||
| 220 | */ |
||
| 221 | public function routePrefix(array $data) |
||
| 222 | { |
||
| 223 | return isset($data['type']) ? $data['type'] . '_' : ''; |
||
| 224 | } |
||
| 225 | |||
| 226 | /** |
||
| 227 | * Get module factory file path |
||
| 228 | * |
||
| 229 | * @return string |
||
| 230 | */ |
||
| 231 | public function factoryFilePath() |
||
| 232 | { |
||
| 233 | return $this->getPath('factoryFile'); |
||
| 234 | } |
||
| 235 | |||
| 236 | /** |
||
| 237 | * Get module factory file path |
||
| 238 | * |
||
| 239 | * @return string |
||
| 240 | */ |
||
| 241 | public function seederFilePath() |
||
| 242 | { |
||
| 243 | return $this->getPath('seederFile'); |
||
| 244 | } |
||
| 245 | |||
| 246 | /** |
||
| 247 | * Get module service provider file path |
||
| 248 | * |
||
| 249 | * @return string |
||
| 250 | */ |
||
| 251 | public function serviceProviderFilePath() |
||
| 252 | { |
||
| 253 | return $this->getPath('serviceProviderFile'); |
||
| 254 | } |
||
| 255 | |||
| 256 | /** |
||
| 257 | * Get path |
||
| 258 | * |
||
| 259 | * @param string $configMethod |
||
| 260 | * @param string $prefix |
||
| 261 | * |
||
| 262 | * @return string |
||
| 263 | */ |
||
| 264 | protected function getPath($configMethod, $prefix = '') |
||
| 265 | { |
||
| 266 | return $this->directory() . DIRECTORY_SEPARATOR . |
||
| 267 | $this->replace($this->config->$configMethod($prefix), $this); |
||
| 268 | } |
||
| 269 | |||
| 270 | /** |
||
| 271 | * Verifies whether given module is active |
||
| 272 | * |
||
| 273 | * @return bool |
||
| 274 | */ |
||
| 275 | public function active() |
||
| 276 | { |
||
| 277 | return $this->options->get('active', true); |
||
|
0 ignored issues
–
show
|
|||
| 278 | } |
||
| 279 | } |
||
| 280 |
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..