mpscholten / value-or-default
Simple default values for your code
1.0.0
2015-10-05 13:38 UTC
Requires
- php: >=5.4
Requires (Dev)
- phpunit/phpunit: ^4.7
This package is auto-updated.
Last update: 2024-10-22 21:18:34 UTC
README
Simple default values for your php code.
Get started
Install via composer
composer install mpscholten/value-or-default
Basic Usage
// Env variables $tempDir = \MPScholten\valueOrDefault($_ENV['TEMP_DIR'], '/tmp'); // $tempDir is now either $_ENV['TEMP_DIR'] or '/tmp' dependending on whether $_ENV['TEMP_DIR'] is set // JSON input $user = json_decode(...); $userName = \MPScholten\valueOrDefault($user['name'], 'n/a'); // $userName is now either $user['name'] or 'n/a' depending on whether $user['name'] is set and non-null // Null values $value = null; \MPScholten\valueOrDefault($value, 0); // returns 0 because $value == null
Tests
You can run the phpunit
suite with make
make tests
Contributing
Feel free to send pull requests!