germania-kg/nullfactory

Factory callable that returns null or any other default value

1.0.2 2022-03-30 10:01 UTC

This package is auto-updated.

Last update: 2024-10-29 05:16:29 UTC


README

Packagist PHP version Build Status Scrutinizer Code Quality Code Coverage Build Status

Installation with Composer

$ composer require germania-kg/nullfactory

Usage

<?php
use Germania\NullFactory\NullFactory;

$nf = new NullFactory;
$result = $nf( "anything" );
// null

To make NullFactory return something else, pass it to the constructor:

<?php
use Germania\NullFactory\NullFactory;

$default_value = array("foo", "bar");

$nf = new NullFactory( $default_value );
$result = $nf( "anything" );
// array("foo", "bar")

The NullFactory also accepts a PSR3-Logger which defaults to NullLogger

<?php
use Germania\NullFactory\NullFactory;
use Psr\Log\NullLogger;

$nf = new NullFactory( null, new NullLogger );
$result = $nf( "anything" );

Issues

See full issues list.

Roadmap

Fill in planned or desired features

Development

$ git clone https://github.com/GermaniaKG/NullFactory.git
$ cd NullFactory
$ composer install

Unit tests

Either copy phpunit.xml.dist to phpunit.xml and adapt to your needs, or leave as is. Run PhpUnit test or composer scripts like this:

$ composer test
# or
$ vendor/bin/phpunit