Download the PHP package omitobisam/conditional without Composer
On this page you can find all versions of the php package omitobisam/conditional. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download omitobisam/conditional
More information about omitobisam/conditional
Files in omitobisam/conditional
Package conditional
Short Description A fluent helper for object-oriented style of if-else statements
License MIT
Homepage https://omitobi.github.io/conditional/
Informations about the package conditional
About Conditional
if-else statements in a cleaner and beautiful way.
Installation
composer require omitobisam/conditional
Minimum Requirement
- PHP >=7.4
Usage
You can call it simply statically:
Conditional also comes with a helper function called conditional()
and its used like so:
:tada: Now like a tenary operator. Conditional at version 1.2 else()
immediately returns the value of the last truthy execution:
You can also evaluate a closure call on the conditional if
method:
Conditional also allows returning values passed in the conditions.
You use value()
method to get the values either the result of the closure passed or the values as they are.
Finally, then()
and else()
methods accepts invokable class or objects. Lets see:
You are also allowed to throw exception based on the condition like so:
Newly released
elseIf()
method of Conditional like so:
elseIf()
can be called multiple times on an instance:
Coming Soon
If()
and elseIf()
statement accepting a default value when no condition is met and else()
is not called like so:
Multiple conditional check like a && b && c && d
or a || b || c ||...
syntax
- Help wanted for this
Caveats (or Awareness)
- As at version 1.x, Calling
if()
method returns an instance of Condtional, so do not call it twice on the same instance for example:
See: tests/ConditionalTest::testEveryIfCallCreatesNewFreshInstance test. On the last line of that test, the two conditionals are not the same.
- Conditional relies on closures to return non closure values passed to then. In the future release it will be optional for
then
andelse
method
Contributions
- More tests are needed
- Issues have been opened
- How about those static properties, any idea how to reduce the number of static properties used?
- Performance optimization (?)
Development
For new feature, checkout with prefix feat-#issueid
e.g feature-#100-add-auto-deloy
- Clone this repository
- run
sh dockerizer.sh
orbash dockerizer.sh
- execute into the docker environment with
docker-compose exec conditional sh
(sh
can be another bash) - run tests with
vendor/bin/phpunit
Licence
MIT (see LICENCE file)
Additional Information
Other related packages:
- https://github.com/transprime-research/piper [A functional PHP pipe in object-oriented way]
- https://github.com/transprime-research/arrayed [A smart PHP array class object-oriented way]
- https://github.com/transprime-research/attempt [A smart PHP try...catch statement]
- https://github.com/omitobi/carbonate [A smart Carbon + Collection package]
- https://github.com/omitobi/laravel-habitue [Jsonable Http Request(er) package with Collections response]