PHPackages                             matthewbaggett/clamp - 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. matthewbaggett/clamp

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

matthewbaggett/clamp
====================

PHP clamp function to clamp a number between a minimum and a maximum.

v1.1(8y ago)13.5kMITPHPCI failing

Since Feb 7Pushed 8y ago1 watchersCompare

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

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

Clamp() for PHP
===============

[](#clamp-for-php)

PHP mathematical "Clamp" function. It clamps a variable between two numbers. Simple.

[![Build Status](https://camo.githubusercontent.com/293b56e138b0030312efa17c6165822aff98e4a0d8ecf30e9dfc53de6650695d/68747470733a2f2f7472617669732d63692e6f72672f6d617474686577626167676574742f7068702d636c616d702e7376673f6272616e63683d76312e30)](https://travis-ci.org/matthewbaggett/php-clamp)[![Coverage Status](https://camo.githubusercontent.com/cb1679f8a24a626bcd2b7a2103716934643f623d05c436c3e26aa8cfbd6438be/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6d617474686577626167676574742f7068702d636c616d702f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/matthewbaggett/php-clamp?branch=master)

Usage:
------

[](#usage)

```
    $value = clamp(
        $min,  // The minimum you will accept
        $max,  // The maximum you can take
        $value // The value you wish to clamp
    );
```

Why?
----

[](#why)

I got sick of writing what should be a core PHP function into a Util class, only to discover other people populating that util class with other nonsense that really shouldn't be in a Util class.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity64

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 ~0 days

Total

2

Last Release

3012d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5707be384b9daab9858223c5dfead9d692e8b5f6afa8dd23ad5c5cbc149316b2?d=identicon)[matthewbaggett](/maintainers/matthewbaggett)

---

Top Contributors

[![matthewbaggett](https://avatars.githubusercontent.com/u/943948?v=4)](https://github.com/matthewbaggett "matthewbaggett (11 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/matthewbaggett-clamp/health.svg)

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

###  Alternatives

[composer/composer

Composer helps you declare, manage and install dependencies of PHP projects. It ensures you have the right stack everywhere.

29.4k187.2M2.6k](/packages/composer-composer)[symfony/event-dispatcher

Provides tools that allow your application components to communicate with each other by dispatching events and listening to them

8.6k985.9M3.4k](/packages/symfony-event-dispatcher)[symfony/polyfill-php80

Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions

1.7k815.2M455](/packages/symfony-polyfill-php80)[symfony/var-exporter

Provides tools to export, instantiate, hydrate, clone and lazy-load PHP objects

2.1k378.1M437](/packages/symfony-var-exporter)[seld/phar-utils

PHAR file format utilities, for when PHP phars you up

875180.0M32](/packages/seld-phar-utils)[dansmith/laravel5-foundation

Zurb Foundation components for Laravel5

104.6k](/packages/dansmith-laravel5-foundation)

PHPackages © 2026

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