PHPackages                             ronanchilvers/utility - 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. ronanchilvers/utility

ActiveLibrary

ronanchilvers/utility
=====================

Handy utility classes for PHP

2.0(3y ago)03.4k[1 PRs](https://github.com/ronanchilvers/utility/pulls)1MITPHPPHP ^8.0CI failing

Since Apr 25Pushed 3y ago1 watchersCompare

[ Source](https://github.com/ronanchilvers/utility)[ Packagist](https://packagist.org/packages/ronanchilvers/utility)[ RSS](/packages/ronanchilvers-utility/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)Dependencies (2)Versions (17)Used By (1)

utility
=======

[](#utility)

[![Actions Status](https://github.com/ronanchilvers/utility/workflows/Unit%20Tests/badge.svg)](https://github.com/ronanchilvers/utility/actions)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/61de12b4fc94c96816224f555287755fb21c4c96a8f23d4cd846944af60704b3/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f726f6e616e6368696c766572732f7574696c6974792f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/ronanchilvers/utility/?branch=master)

The package is intended provides a set of classes and methods that help with common tasks in PHP projects.

Installation
------------

[](#installation)

```
composer require ronanchilvers/utility

```

Usage
-----

[](#usage)

### `Str` - String handling

[](#str---string-handling)

The `Str` class provides some useful methods for dealing with strings.

### `Str::plural($string, $count = 1, $plural = false)`

[](#strpluralstring-count--1-plural--false)

Pluralise a string. Provide a singular word and count and `plural()` will pluralise it if appropriate. If its an odd word that doesn't pluralise easily, you can supply the plural you want to use as a third argument.

### `Str::singular($string, $count = 1, $singular = false)`

[](#strsingularstring-count--1-singular--false)

Singularise a plural string. Provide a plural word and an optional count and `singular()` will do its best to singularise it for you. If it gets it wrong you can pass an explicit singular as a third argument.

### `Str::pascal($string,  $allowed = [])`

[](#strpascalstring--allowed--)

Convert a string to PascalCase. This method will by default remove any characters except a-z and 0-9. If you have additional characters you'd like to retain pass them as an array of strings in the `$allowed` argument.

### `Str::camel($string, $allowed = [])`

[](#strcamelstring-allowed--)

Convert a string to camelCase. This method returns the same result as `pascal()` except that the first character of the returned string is lowercased.

### `Str::snake($string, $allowed = [])`

[](#strsnakestring-allowed--)

Convert a string to snake\_case. As with `pascal()`, this method removes all characters except a-z and 0-9. You can use the second argument `$allowed` to pass an array of additional characters that you want to keep.

### `Str::truncate($string, $length, $suffix = '...', $words = false)`

[](#strtruncatestring-length-suffix---words--false)

Truncate a string to a given length. By default the string is suffixed with an ellipsis (`…`) but you can change this by passing a suffix string in the third argument (`$suffix`). In addition `truncate()` will split a string without regard for word boundaries. If you want to respect words pass `true` as the fourth `$words` argument.

### `Str::token($length = 64)`

[](#strtokenlength--64)

Generate a random string token of a given length.

### `Str::bool($string)`

[](#strboolstring)

Determine if a string means true or false.

Testing
-------

[](#testing)

The utility classes are very simple and consequently have 100% test coverage. You can run the tests by doing:

```
./vendor/bin/phpunit

```

The default phpunit.xml.dist file creates coverage information in a build/coverage subdirectory.

Contributing
------------

[](#contributing)

If anyone has any patches they want to contribute I'd be more than happy to review them. Please raise a PR. You should:

- Follow PSR2
- Maintain 100% test coverage or give the reasons why you aren't
- Follow a one feature per pull request rule

License
-------

[](#license)

This software is licensed under the MIT license. Please see the [License File](LICENSE.md) for more information.

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~139 days

Recently: every ~288 days

Total

13

Last Release

1265d ago

Major Versions

1.9 → 2.02022-11-25

PHP version history (3 changes)1.0PHP ^7.0

1.5PHP ^7.1.8

2.0PHP ^8.0

### Community

Maintainers

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

---

Top Contributors

[![ronanchilvers](https://avatars.githubusercontent.com/u/87890?v=4)](https://github.com/ronanchilvers "ronanchilvers (53 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ronanchilvers-utility/health.svg)

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

PHPackages © 2026

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