PHPackages                             monospice/spicy-identifier-tools - 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. monospice/spicy-identifier-tools

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

monospice/spicy-identifier-tools
================================

An easy way to parse, convert, and format identifier names.

1.0.3(10y ago)5983.7k↓46%2MITPHPPHP &gt;=5.4.0

Since Aug 11Pushed 10y ago2 watchersCompare

[ Source](https://github.com/monospice/spicy-identifier-tools)[ Packagist](https://packagist.org/packages/monospice/spicy-identifier-tools)[ RSS](/packages/monospice-spicy-identifier-tools/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (2)Versions (5)Used By (2)

Spicy Identifier Tools
======================

[](#spicy-identifier-tools)

[![Build Status](https://camo.githubusercontent.com/86290205449ba509d83ae1b1032ed8c3b86736f7cd59b76a8268d4aeee5e9b34/68747470733a2f2f7472617669732d63692e6f72672f6d6f6e6f73706963652f73706963792d6964656e7469666965722d746f6f6c732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/monospice/spicy-identifier-tools)

**An easy way to parse, convert, and format identifier names.**

These tools are helpful when working with dynamic identifier names such as dynamic methods or when working between different programming languages.

Simple Example
--------------

[](#simple-example)

```
$identifierParts = Parser::parseFromUnderscore('an_identifier_name');
// returns array('an', 'identifier', 'name');

echo Formatter::formatCamelCase($identifierParts);
// 'anIdentifierName'
```

Or just:

```
echo Converter::convert(
    'an_identifier_name',
    CaseFormat::UNDERSCORE,
    CaseFormat::CAMEL_CASE
);
// 'anIdentifierName'
```

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

[](#installation)

```
$ composer require monospice/spicy-identifier-tools

```

If you're autoloading classes (hopefully):

```
use Monospice\SpicyIdentifiers\Tools\CaseFormat;
use Monospice\SpicyIdentifiers\Tools\Parser;
use Monospice\SpicyIdentifiers\Tools\Formatter;
use Monospice\SpicyIdentifiers\Tools\Converter;
```

Basic Usage
-----------

[](#basic-usage)

The package comes with three tools:

- `Parser`: Converts identifier strings into arrays of parts
- `Formatter`: Comverts an array of identifier parts into a formatted string
- `Converter`: Parses and formats an identifier string in one step

**Parser**

```
Parser::parseFromCamelCase('anIdentifier');     // array('an', 'Identifier');
Parser::parseFromUnderscore('an_identifier');   // array('an', 'identifier');
Parser::parseFromHyphen('an-identifier');       // array('an', 'identifier');

// or use the generic method:
Parser::parse('anIdentifier', CaseFormat::CAMEL_CASE);
// array('an', 'Identifier');
```

*Note*: Although PHP doesn't support hyphens in identifier names, the hyphen methods may be useful when working between other languages that do, like HTML/CSS or Lisp (gasp!).

**Formatter**

```
$parts = array('an', 'identifier');

Formatter::formatUppercase($parts);         // 'ANIDENTIFIER'
Formatter::formatLowercase($parts);         // 'anidentifier'
Formatter::formatCamelCase($parts);         // 'anIdentifier'
Formatter::formatUpperCamelCase($parts);    // 'AnIdentifier'
Formatter::formatUnderscore($parts);        // 'an_identifier'
Formatter::formatUpperUnderscore($parts);   // 'An_Identifier'
Formatter::formatCapsUnderscore($parts);    // 'AN_IDENTIFIER'
Formatter::formatHyphen($parts);            // 'an-identifier'
Formatter::formatUpperHyphen($parts);       // 'An-Identifier'
Formatter::formatCapsHyphen($parts);        // 'AN-IDENTIFIER'

// or use the generic method:
Formatter::format($parts, CaseFormat::CAPS_UNDERSCORE); // AN_IDENTIFIER
```

**Converter**

At this time, the `Converter` class only provides a generic method:

```
// Converter::convert($partsArray, $inputFormat, $outputFormat);

Converter::convert(
    'anIdentifierName',
    CaseFormat::CAMEL_CASE,
    CaseFormat::UPPER_CAMEL_CASE
);
// 'AnIdentifierName'
```

Case Formats
------------

[](#case-formats)

The `CaseFormat` class contains constants that represent each case.

This package supports the following "cases" for identifiers:

Case FormatConstant NameExampleUppercaseUPPERCASEANIDENTIFIERLowercaseLOWERCASEanidentifierCamel CaseCAMEL\_CASEanIdentifierUpper Camel CaseUPPER\_CAMEL\_CASE or STUDLY\_CAPSAnIdentifierCamel Case with AcronymsCAMEL\_CASE\_WITH\_ACRONYMSanIdentifierACRNMUpper CC with AcronymsUPPER\_CAMEL\_CASE\_WITH\_ACRONYMSAnIdentifierACRNMUnderscore (snake case)UNDERSCORE or SNAKE\_CASEan\_identifierUpper UnderscoreUPPER\_UNDERSCOREAn\_IdentifierCapitalized UnderscoreCAPS\_UNDERSCOREAN\_IDENTIFIERUnderscore with AcronymsUNDERSCORE\_WITH\_ACRONYMSan\_identifier\_ACRNMUpper US with AcronymsUPPER\_UNDERSCORE\_WITH\_ACRONYMSAn\_Identifier\_ACRNMHyphenatedHYPHENan-identifierUpper HyphenatedUPPER\_HYPHENAn-IdentifierCapitalized HyphenatedCAPS\_HYPHENAN-IDENTIFIERHyphenated AcronymsHYPHEN\_WITH\_ACRONYMSan-identifier-ACRNMUpper Hy. with AcronymsUPPER\_HYPHEN\_WITH\_ACRONYMSAn-Identifier-ACRNM*Note*: Because the `Parser` class does not perform formatting, when using the `::parse()` method, one must choose a "base" case to parse from, such as `CAMEL_CASE`, not `UPPER_CAMEL_CASE` or `CAMEL_CASE_WITH_ACRONYMS`.

Acronyms in Identifier Names
----------------------------

[](#acronyms-in-identifier-names)

Sometimes identifier names contain acronyms, such as JavaScript's `XMLHttpRequest`. The `Parser` class preserves these acronyms:

```
$parts = Parser::parseFromCamelCase('XMLHttpRequest');
// array('XML', 'Http', 'Request');
```

However, the `Formatter` and `Converter` classes will not preserve these acronyms unless one chooses an output format with acronyms:

```
Formatter::formatCamelCase($parts);             // 'xmlHttpRequest'
Formatter::formatCamelCaseWithAcronyms($parts); // 'XMLHttpRequest'
```

This behavior provides flexibility when converting or normalizing identifier names.

Identifiers with Mixed Case
---------------------------

[](#identifiers-with-mixed-case)

Although mixed case identifiers are not recommended in practice, one may use the `Parser` to parse identifiers that contain multiple cases:

```
// Parser::parseFromMixedCase($identiferString, $arrayOfCases);

Parser::parseFromMixedCase('aMixed_case-identifier', [
    CaseFormat::CAMEL_CASE,
    CaseFormat::UNDERSCORE,
    CaseFormat::HYPHEN,
]);
// array('a', 'Mixed', 'case', 'identifier');
```

The package does not provide support to output identifiers in a mixed format.

Extended ASCII Identifiers (Experimental)
-----------------------------------------

[](#extended-ascii-identifiers-experimental)

PHP supports extended ASCII characters in identifier names. For example, the character `ä` in:

```
// From the php.net manual:
$täyte = 'mansikka';    // valid; 'ä' is (Extended) ASCII 228.
```

When parsing identifiers by underscore or hyphen, these characters have no effect. However, camel case identifiers may include words that are delimited by extended ASCII characters, such as `änÏdentifierNáme`.

The Spicy Identifier Tools package provides an **experimental** method to parse these identifiers:

```
Parser::parseFromCamelCaseExtended('änÏdentifierNáme');
// array('än', 'Ïdentifier', 'Náme');
```

The consistency of this method depends on the character encoding of the source files and the environment language and encoding settings. As a best practice, one should avoid using extended ASCII characters in identifier names.

For more information, visit the PHP Manual:

Testing
-------

[](#testing)

The Spicy Identifier Tools package uses PHPUnit to test input variations and PHPSpec for object behavior.

```
$ phpunit
$ vendor/bin/phpspec run
```

License
-------

[](#license)

The MIT License (MIT). Please see the [LICENSE File](LICENSE) for more information.

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity41

Moderate usage in the ecosystem

Community14

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 94.1% 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 ~28 days

Total

4

Last Release

3895d ago

PHP version history (2 changes)1.0.0PHP &gt;=5.0.0

1.0.1PHP &gt;=5.4.0

### Community

Maintainers

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

---

Top Contributors

[![cyrossignol](https://avatars.githubusercontent.com/u/4282384?v=4)](https://github.com/cyrossignol "cyrossignol (16 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/monospice-spicy-identifier-tools/health.svg)

```
[![Health](https://phpackages.com/badges/monospice-spicy-identifier-tools/health.svg)](https://phpackages.com/packages/monospice-spicy-identifier-tools)
```

PHPackages © 2026

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