mtolhuys / laravel-env-scanner
Checks environmental variables used in the env() and getenv() helper functions
Requires
- php: ^7.0
Requires (Dev)
- orchestra/testbench: ^3.5
- phpunit/phpunit: ^7.0
README
This package comes with a LaravelEnvScanner
class and artisan command which you can use to scan any folder in your app for potential .env related problems.
Example output of the command:
php artisan env:scan Scanning: laravel-app/config... 2 undefined variable(s) found in laravel-app/config/... +-------------------------------+----------+ | laravel-app/config/app.php:16 | APP_NAME | | laravel-app/config/app.php:29 | APP_ENV | +-------------------------------+----------+
Installation
You can install the package via composer:
composer require mtolhuys/laravel-env-scanner
Usage
You can call the artisan command to start the scan:
php artisan env:scan
Optionally you could specify a directory to run from (defaults to config_path()
):
php artisan env:scan -d app/Http/Controllers Scanning: app/Http/Controllers...
Or show all used variables:
php artisan env:scan -a Scanning: laravel-app/config... +------------------------------------+----------------+---------------------------+-------------------+ | Locations (2) | Defined (1) | Depending on default (1) | Undefined (0) | +------------------------------------+----------------+---------------------------+-------------------+ | laravel-app/config/database.php:36 | DB_CONNECTION | - | - | | laravel-app/config/database.php:42 | - | DB_HOST | - | +------------------------------------+----------------+---------------------------+-------------------+ php artisan env:scan -d app Scanning: app... Warning: env("RISKY_".$behavior) found in app/Http/Middleware/Authenticate.php php artisan env:scan -d storage Scanning: storage... Looking good!
Aside from the command you can use the LaravelEnvScanner
from anywhere you want:
(new LaravelEnvScanner(__DIR__))->scan()->results; // Or $this->scanner = new LaravelEnvScanner(__DIR__); $this->scanner->scan(); $this->scanner->results; // Example results [ "locations" => 1 "defined" => 1 "undefined" => 0 "depending_on_default" => 0, "columns" => [ 0 => [ "location" => "laravel-app/config/database.php:36" "defined" => "DB_HOST" "depending_on_default" => "-" "undefined" => "-" ] ] ]
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email mtolhuys@protonmail.com instead of using the issue tracker.
Credits
- Maarten Tolhuijs
- All Contributors
- Beyond Code For the boilerplate and having me come up with the idea for this package.
License
The MIT License (MIT). Please see License File for more information.