PHPackages                             mattjmattj/maybe - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. mattjmattj/maybe

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

mattjmattj/maybe
================

Fake objects for cleaner code and error handling

1.0.2(11y ago)252[1 issues](https://github.com/mattjmattj/maybe/issues)1BSD-2-ClausePHP

Since Mar 18Pushed 11y ago2 watchersCompare

[ Source](https://github.com/mattjmattj/maybe)[ Packagist](https://packagist.org/packages/mattjmattj/maybe)[ RSS](/packages/mattjmattj-maybe/feed)WikiDiscussions master Synced today

READMEChangelog (4)Dependencies (3)Versions (5)Used By (1)

Maybe
=====

[](#maybe)

[![Build Status](https://camo.githubusercontent.com/4f413c02f93405ed965881a422daf8c20a6246bae6bf3faa9ebdd0e1ab4c1db3/68747470733a2f2f7472617669732d63692e6f72672f6d6174746a6d6174746a2f6d617962652e737667)](https://travis-ci.org/mattjmattj/maybe)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/74fc9d4c4b045cef01933762bc55e084997efe6f9a505b64e29af88fd20662a0/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d6174746a6d6174746a2f6d617962652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mattjmattj/maybe/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/336f44a83f9437d05982c59e1d0d5b6791169c12caa7d2833df07903026f14b4/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d6174746a6d6174746a2f6d617962652f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mattjmattj/maybe/?branch=master)

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.

Installation
============

[](#installation)

with composer

```
composer.phar require mattjmattj/maybe ~1.0

```

Basic usage
===========

[](#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
=======

[](#example)

Examples are provided in the "example" folder:

- **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
=======

[](#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.

License
=======

[](#license)

Maybe is licensed under BSD-2-Clause license.

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance10

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 94.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

4

Last Release

4123d ago

Major Versions

0.1.0 → 1.02015-03-19

### Community

Maintainers

![](https://www.gravatar.com/avatar/f3dcd17447ceec1afbedb4b996b0365645feb858ebb7c9d161566343faaeb66d?d=identicon)[mattjmattj](/maintainers/mattjmattj)

---

Top Contributors

[![mattjmattj](https://avatars.githubusercontent.com/u/1842012?v=4)](https://github.com/mattjmattj "mattjmattj (35 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mattjmattj-maybe/health.svg)

```
[![Health](https://phpackages.com/badges/mattjmattj-maybe/health.svg)](https://phpackages.com/packages/mattjmattj-maybe)
```

###  Alternatives

[drupal/core-dev

require-dev dependencies from drupal/drupal; use in addition to drupal/core-recommended to run tests from drupal/core.

2022.6M343](/packages/drupal-core-dev)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
