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 MikeZange\LaravelDatabaseTranslation\Commands; |
||
4 | |||
5 | use Illuminate\Console\Command; |
||
6 | use Illuminate\Filesystem\Filesystem; |
||
7 | use Illuminate\Translation\FileLoader; |
||
8 | use MikeZange\LaravelDatabaseTranslation\Repositories\TranslationRepository; |
||
9 | |||
10 | /** |
||
11 | * Class LoadTranslationsFromFiles. |
||
12 | */ |
||
13 | class LoadTranslationsFromFiles extends Command |
||
14 | { |
||
15 | /** |
||
16 | * The name and signature of the console command. |
||
17 | * |
||
18 | * @var string |
||
19 | */ |
||
20 | protected $signature = 'trans-db:load {locale}'; |
||
21 | |||
22 | /** |
||
23 | * The console command description. |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $description = 'Loads the translations from file into the DB for a given locale'; |
||
28 | |||
29 | /** |
||
30 | * The Laravel File Loader. |
||
31 | * |
||
32 | * @var FileLoader |
||
33 | */ |
||
34 | protected $laravelLoader; |
||
35 | |||
36 | /** |
||
37 | * Translation repository. |
||
38 | * |
||
39 | * @var TranslationRepository |
||
40 | */ |
||
41 | protected $translationRepository; |
||
42 | |||
43 | /** |
||
44 | * Laravel Filesystem. |
||
45 | * |
||
46 | * @var Filesystem |
||
47 | */ |
||
48 | protected $filesystem; |
||
49 | |||
50 | /** |
||
51 | * The locale. |
||
52 | * |
||
53 | * @var string |
||
54 | */ |
||
55 | protected $locale; |
||
56 | |||
57 | /** |
||
58 | * Create a new command instance. |
||
59 | * |
||
60 | * @param Filesystem $filesystem |
||
61 | * @param TranslationRepository $translationRepository |
||
62 | */ |
||
63 | public function __construct(Filesystem $filesystem, TranslationRepository $translationRepository) |
||
64 | { |
||
65 | parent::__construct(); |
||
66 | |||
67 | //this is so we can benefit from namespaces that are already loaded |
||
68 | $this->laravelLoader = app()['translator']->getLoader()->getFileLoader(); |
||
69 | $this->translationRepository = $translationRepository; |
||
70 | $this->filesystem = $filesystem; |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * Execute the console command. |
||
75 | * |
||
76 | * @return mixed |
||
77 | */ |
||
78 | public function handle() |
||
79 | { |
||
80 | $this->locale = $this->argument('locale'); |
||
0 ignored issues
–
show
|
|||
81 | |||
82 | $this->loadGroupLines(); |
||
83 | |||
84 | $this->loadNameSpacedLines(); |
||
85 | |||
86 | return $this->info('Complete'); |
||
87 | } |
||
88 | |||
89 | protected function loadGroupLines() |
||
90 | { |
||
91 | $langFiles = $this->getLangFiles(resource_path().'/lang'); |
||
92 | |||
93 | $this->processFiles($langFiles); |
||
94 | } |
||
95 | |||
96 | protected function loadNameSpacedLines() |
||
97 | { |
||
98 | foreach ($this->laravelLoader->namespaces() as $namespace => $path) { |
||
99 | $langFiles = $this->getLangFiles($path); |
||
100 | $this->processFiles($langFiles, $namespace); |
||
101 | } |
||
102 | } |
||
103 | |||
104 | /** |
||
105 | * @param $files |
||
106 | * @param null|string $namespace |
||
107 | */ |
||
108 | protected function processFiles($files, $namespace = null) |
||
109 | { |
||
110 | foreach ($files as $file) { |
||
111 | $group = $this->getGroup($file); |
||
112 | $lines = $this->getLines($file); |
||
113 | $this->loadLines($lines, $namespace, $group, $this->locale); |
||
114 | } |
||
115 | } |
||
116 | |||
117 | /** |
||
118 | * Load the lines into the database. |
||
119 | * |
||
120 | * @param $lines |
||
121 | * @param $namespace |
||
122 | * @param $group |
||
123 | * @param $locale |
||
124 | */ |
||
125 | protected function loadLines($lines, $namespace, $group, $locale) |
||
126 | { |
||
127 | foreach ($lines as $key => $value) { |
||
128 | $line = $this->translationRepository->getItem($namespace, $group, $key); |
||
129 | if ($line) { |
||
130 | $this->translationRepository->updateTranslation($line, $this->locale, $value, false); |
||
0 ignored issues
–
show
$line of type object<Illuminate\Database\Eloquent\Builder> is not a sub-type of object<MikeZange\Laravel...ion\Models\Translation> . It seems like you assume a child class of the class Illuminate\Database\Eloquent\Builder to be always present.
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass. Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type. ![]() |
|||
131 | } else { |
||
132 | $attributes = [ |
||
133 | 'namespace' => $namespace, |
||
134 | 'group' => $group, |
||
135 | 'key' => $key, |
||
136 | 'values' => [ |
||
137 | "{$locale}" => $value, |
||
138 | ], |
||
139 | ]; |
||
140 | $this->translationRepository->create($attributes); |
||
141 | } |
||
142 | } |
||
143 | } |
||
144 | |||
145 | /** |
||
146 | * @param $file |
||
147 | * |
||
148 | * @return mixed |
||
149 | */ |
||
150 | protected function getGroup($file) |
||
151 | { |
||
152 | preg_match('/'.$this->locale.'\/([^\[]+).php/i', $file, $group); |
||
153 | |||
154 | return $group[1]; |
||
155 | } |
||
156 | |||
157 | /** |
||
158 | * @param $file |
||
159 | * |
||
160 | * @return array |
||
161 | */ |
||
162 | protected function getLines($file) |
||
163 | { |
||
164 | return array_dot($this->filesystem->getRequire($file)); |
||
165 | } |
||
166 | |||
167 | /** |
||
168 | * @param $path |
||
169 | * |
||
170 | * @return array |
||
171 | */ |
||
172 | protected function getLangFiles($path) |
||
173 | { |
||
174 | $dir = $this->getLocaleDirPath($path); |
||
175 | |||
176 | return $this->filesystem->files($dir); |
||
177 | } |
||
178 | |||
179 | /** |
||
180 | * @param $path |
||
181 | * |
||
182 | * @return string |
||
183 | */ |
||
184 | protected function getLocaleDirPath($path) |
||
185 | { |
||
186 | return $path.'/'.$this->locale; |
||
187 | } |
||
188 | } |
||
189 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.