2017 © Pedro Peláez
 

library maybe

Fake objects for cleaner code and error handling

image

mattjmattj/maybe

Fake objects for cleaner code and error handling

  • Friday, March 20, 2015
  • by mattjmattj
  • Repository
  • 2 Watchers
  • 2 Stars
  • 27 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

Maybe

Build Status Scrutinizer Code Quality Code Coverage, (*1)

Maybe wraps a class and provides a way to abstract away error handling when dealing with undefined instances. It might help implement feature switches, dev/prod environments switches, etc., (*2)

Installation

with composer, (*3)

composer.phar require mattjmattj/maybe ~1.0

Basic usage

use Maybe\Maybe;

/*
 * Create a Maybe instance for the desired class or interface.
 */
$maybe = new Maybe('Some\Class');

/*
 * Wrap some object that you don't know much about : 
 * might be null or an actual instance of Some\Class.
 */
$wrapped = $maybe->wrap($someContainer->getSomeClassInstance());

/*
 * Call whatever you want on the wrapped object without having
 * to worry about whether $someContainer->getSomeClassInstance()
 * return something or not.
 */
$wrapped->doSomeInterestingThing();

/*
 * You can also call a method at a deeper level. Maybe will wrap returned types
 * if it finds proper @return annotations
 */
$wrapped->getSomeService()->doSomeJob();

Example

Examples are provided in the "example" folder:, (*4)

  • Log : An example of how to use Maybe with an IoC container to wrap a "log" feature and write code with no worries.
  • Email : An example of how to use Maybe to create fake objects from interfaces only. An example of "deep" wrapping.

Warning

Not every kind of object should be wrapped. Typically you will want to wrap classes that provide logs, debug, cache, events, etc. You don't want to wrap "useful" classes that actually alter the logic of your code., (*5)

License

Maybe is licensed under BSD-2-Clause license., (*6)

The Versions

20/03 2015

dev-master

9999999-dev

Fake objects for cleaner code and error handling

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

by Matthias Jouan

20/03 2015

1.0.2

1.0.2.0

Fake objects for cleaner code and error handling

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

by Matthias Jouan

19/03 2015

1.0.1

1.0.1.0

Fake objects for cleaner code and error handling

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

by Matthias Jouan

19/03 2015

1.0

1.0.0.0

Fake objects for cleaner code and error handling

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

by Matthias Jouan

18/03 2015

0.1.0

0.1.0.0

Wraps objects you don't care about

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

by Matthias Jouan