kero / typesafe-env
Wrapper around Laravel's Env to support type safety.
0.1.0
2023-11-02 08:22 UTC
Requires
- php: ^8.1
- illuminate/support: ^10.0
- phpoption/phpoption: ^1.9
- vlucas/phpdotenv: ^5.5
Requires (Dev)
- ergebnis/composer-normalize: ^2.39
- laravel/pint: ^0.1.2 || ^1.0.0
- pestphp/pest: ^2.24
- pestphp/pest-plugin-type-coverage: ^2.4
- phpstan/phpstan: ^1.10
README
Install via composer req kero/typesafe-env
Usage
Assuming the following environment variables
API_URL=foo APP_STRING_OR_NULL=null APP_DEBUG=true APP_LOG=false APP_BOOL_OR_NULL=null APP_PI=3 APP_BETTER_PI=3.14
use Kero\TypeSafeEnv\Env; var_dump(Env::getString('API_URL')); // string(3) "foo" var_dump(Env::getNullableString('APP_STRING_OR_NULL')); // NULL var_dump(Env::getBool('APP_DEBUG')); // bool(true) var_dump(Env::getBool('APP_LOG')); // bool(false) var_dump(Env::getNullableBool('APP_BOOL_OR_NULL')); // NULL var_dump(Env::getInt('APP_PI')); // int(3) var_dump(Env::getFloat('APP_PI')); // float(3.14)
❗ Due to Laravel's implementation, both values null
and (null)
are treated as NULL
.
Local Development
Code Style
Currently using plain PSR-12 via Laravel Pint. Apply the code style via
make pint
Tests
Using Pest for testing. Run existing tests via
make test
❗ Tests are relying on the environment variables defined in .env.testing
Type Coverage can also be tested via Pest. Current implementation inside Makefile is buggy ... (TODO: fix so command in Makefile via Docker can be used)
./vendor/bin/pest --type-coverage --min=100
Code Analysis
PHPStan is configured to check ./src/
and ./tests/
via
make analyse
Various
- normalize composer.json file via
ergebnis/composer-normalize
composer normalize