cashwarden /
api
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace app\commands; |
||||
| 4 | |||||
| 5 | use Yii; |
||||
| 6 | use yii\console\Controller; |
||||
| 7 | use yii\helpers\Console; |
||||
| 8 | use yiier\helpers\Security; |
||||
| 9 | use yiithings\dotenv\Loader; |
||||
| 10 | |||||
| 11 | class GenerateController extends Controller |
||||
| 12 | { |
||||
| 13 | public function actionKey(bool $dryRun = false, string $filename = '.env') |
||||
| 14 | { |
||||
| 15 | $environmentFilePath = Yii::getAlias('@app/' . $filename); |
||||
| 16 | Loader::load('', $filename, true); |
||||
| 17 | foreach (['COOKIE_VALIDATION_KEY', 'JWT_SECRET'] as $item) { |
||||
| 18 | $escaped = preg_quote('=' . env($item), '/'); |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 19 | $keyReplacementPattern = "/^{$item}{$escaped}/m"; |
||||
| 20 | $key = Security::generateRealUniqId(32); |
||||
| 21 | if (!$dryRun) { |
||||
| 22 | file_put_contents($environmentFilePath, preg_replace( |
||||
|
0 ignored issues
–
show
It seems like
$environmentFilePath can also be of type false; however, parameter $filename of file_put_contents() does only seem to accept string, 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
Loading history...
|
|||||
| 23 | $keyReplacementPattern, |
||||
| 24 | "{$item}={$key}", |
||||
| 25 | file_get_contents($environmentFilePath) |
||||
|
0 ignored issues
–
show
It seems like
$environmentFilePath can also be of type false; however, parameter $filename of file_get_contents() does only seem to accept string, 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
Loading history...
|
|||||
| 26 | )); |
||||
| 27 | } |
||||
| 28 | $this->stdout("{$item} key [{$key}] set successfully.\n", Console::FG_GREEN); |
||||
| 29 | } |
||||
| 30 | } |
||||
| 31 | } |
||||
| 32 |