Install via composer req kero/typesafe-env
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
.
Currently using plain PSR-12 via Laravel Pint. Apply the code style via
make pint
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
PHPStan is configured to check ./src/
and ./tests/
via
make analyse
- normalize composer.json file via
ergebnis/composer-normalize
composer normalize