PHPackages                             orklah/psalm-strict-numeric-cast - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. orklah/psalm-strict-numeric-cast

ActivePsalm-plugin[Validation &amp; Sanitization](/categories/validation)

orklah/psalm-strict-numeric-cast
================================

Restrict the use of (int) and (float) to numeric-string only

v2.1.0(2y ago)856.0k↓30.8%21MITPHPPHP ^7.3|^8.0

Since Dec 5Pushed 2y ago2 watchersCompare

[ Source](https://github.com/orklah/psalm-strict-numeric-cast)[ Packagist](https://packagist.org/packages/orklah/psalm-strict-numeric-cast)[ RSS](/packages/orklah-psalm-strict-numeric-cast/feed)WikiDiscussions master Synced 1mo ago

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

psalm-strict-numeric-cast
=========================

[](#psalm-strict-numeric-cast)

A [Psalm](https://github.com/vimeo/psalm) plugin to restrict the use of (int) and (float) to numeric-string only

Installation:

```
$ composer require --dev orklah/psalm-strict-numeric-cast
$ vendor/bin/psalm-plugin enable orklah/psalm-strict-numeric-cast
```

Usage:

Run your usual Psalm command:

```
$ vendor/bin/psalm
```

Explanation:

This plugin aims to avoid code like this:

```
function a(string $potential_int){
    $int = (int) $potential_int;
    //...
}
```

This cast is performed on a string that could have any value from a static analysis point of view.

The issue can be resolved in a few ways that will force you to have a better confidence in your variables types.

- You can check that the variable is indeed numeric:

```
function a(string $potential_int){
    if(is_numeric($potential_int)){
        $int = (int) $potential_int;
    }
    else{
        //throw
    }
    //...
}
```

```
function a(string $potential_int){
    Assert::numeric($potential_int);
    $int = (int) $potential_int;
    //...
}
```

- You can make psalm understand that the function expects a numeric (this will force you to correctly type any input to this function):

```
/** @psalm-param numeric-string $potential_int */
function a(string $potential_int){
    $int = (int) $potential_int;
    //...
}
```

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity36

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 62.5% 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 ~369 days

Total

4

Last Release

877d ago

Major Versions

v1.0.1 → v2.0.02022-01-10

PHP version history (2 changes)v1.0.0PHP ^7.3

v1.0.1PHP ^7.3|^8.0

### Community

Maintainers

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

---

Top Contributors

[![orklah](https://avatars.githubusercontent.com/u/9605520?v=4)](https://github.com/orklah "orklah (10 commits)")[![kkmuffme](https://avatars.githubusercontent.com/u/11071985?v=4)](https://github.com/kkmuffme "kkmuffme (4 commits)")[![danog](https://avatars.githubusercontent.com/u/7339644?v=4)](https://github.com/danog "danog (2 commits)")

###  Code Quality

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/orklah-psalm-strict-numeric-cast/health.svg)

```
[![Health](https://phpackages.com/badges/orklah-psalm-strict-numeric-cast/health.svg)](https://phpackages.com/packages/orklah-psalm-strict-numeric-cast)
```

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[bensampo/laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k15.9M104](/packages/bensampo-laravel-enum)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[crazybooot/base64-validation

Laravel validators for base64 encoded files

1341.9M8](/packages/crazybooot-base64-validation)

PHPackages © 2026

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