PHPackages                             mention/kebab - 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. mention/kebab

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

mention/kebab
=============

Wrappers around the PHP standard library focused on safety and testability

1.4.2(2y ago)16138.5k—5.5%32MITPHPPHP &gt;=8.1

Since Mar 7Pushed 2y ago19 watchersCompare

[ Source](https://github.com/mentionapp/kebab)[ Packagist](https://packagist.org/packages/mention/kebab)[ RSS](/packages/mention-kebab/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (8)Versions (12)Used By (2)

Kebab 🌮
=======

[](#kebab-)

Kebab is a collection of safety wrappers and testing utilities around a few functions of the PHP standard library. It's so useful that we wanted to use it everywhere, including our personal projects. So we couldn't keep it for ourselves.

[![Build Status](https://camo.githubusercontent.com/85180c6efe123cbf139e1b268e8a41a9c7c2565c041f72262489640f24908b8f/68747470733a2f2f7472617669732d63692e6f72672f6d656e74696f6e6170702f6b656261622e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/mentionapp/kebab)[![Latest Version](https://camo.githubusercontent.com/81c12d218d9deb32674b599d98aa0610c9f3584865e58e8a543881f9acc6498f/68747470733a2f2f706f7365722e707567782e6f72672f6d656e74696f6e2f6b656261622f762f737461626c653f5f)](https://packagist.org/packages/mention/kebab)[![MIT License](https://camo.githubusercontent.com/832e0ffdd903dc6f53379a8399b61c6f5e776b0f7af0f501f79b46cf219918d2/68747470733a2f2f706f7365722e707567782e6f72672f6d656e74696f6e2f6b656261622f6c6963656e73653f5f)](https://choosealicense.com/licenses/mit/)[![PHPStan Enabled](https://camo.githubusercontent.com/441b5874ce4df0a2defc892979c96c46889b69cb32119d04f0b48626349f8bc9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d656e61626c65642d627269676874677265656e2e7376673f7374796c653d666c6174)](https://github.com/phpstan/phpstan)

Install
-------

[](#install)

```
composer require mention/kebab

```

Goals
-----

[](#goals)

The goals of this package are to:

- Provide wrappers that are safe by default (by throwing exceptions on error)
- Provide wrappers with better APIs
- Make static analyzers happy
- Make testing easier

Some functions in the PHP standard library have a notoriously bad API. Take for example `json_decode()`: If returns `null` if there was an error, or if the JSON string was the `NULL` literal. The package provides sane wrappers that automatically check for errors and throw exceptions on failure. The package also provides a wrapper for less broken functions like `file_get_contents()`, because throwing exceptions on errors is useful.

The wrappers do not only check for errors, they also try to improve the API. For instance, `json_decode()` is declined in two variants: `JsonUtils::decodeArray()` and `JsonUtils::decodeObject()`.

All wrappers have static, single return types, to make static analyzers happy. For example, there is `Clock::microtimeFloat()` and `Clock::microtimeString()` instead of a single function returning one of two possible types.

Finally, the package provides some tools to make testing easier, such as the `Clock` class that allows to fake the system time during tests.

Overview
--------

[](#overview)

### Clock

[](#clock)

Clock wraps `time()`, `microtime()`, `sleep()`, `usleep()` in a way that allows these functions to return a fake time during tests (and the system time otherwise).

Example:

```
