PHPackages                             lexide/k-switch - 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. lexide/k-switch

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

lexide/k-switch
===============

A PHP library to switch cases of a property or element name

2.1.0(1y ago)011.0k↑50%1[1 PRs](https://github.com/lexide/k-switch/pulls)2MITPHPPHP &gt;=8.0CI passing

Since Mar 2Pushed 3mo ago1 watchersCompare

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

READMEChangelog (1)Dependencies (1)Versions (8)Used By (2)

K-Switch
========

[](#k-switch)

A PHP library to switch cases for property, field and element names

Say what, now?
--------------

[](#say-what-now)

When dealing with different sources of data, it is often the case that field names will be in one case, typically "snake\_case", and PHP classes will use "camelCase" for property names. Mapping between the two is non-trivial to do by hand.

K-Switch is a utility library to allow case switching with the minimum of fuss.

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

[](#installation)

Via composer OfC!

```
composer require lexide/k-switch

```

How to use
----------

[](#how-to-use)

Any class that needs to switch cases can use the `NameConverterTrait`. This trait adds private methods to convert name strings into "StudlyCaps", "camelCase", "snake\_case", "dash-case" and any other case that splits words with delimiters (spaces, pipes, etc...)

```
class Converter {
    use Lexide\KSwitch\NameConverterTrait;

    public function convertStudly($string)
    {
        return $this->toStudlyCaps($string);
    }

    public function convertCamel($string)
    {
        return $this->toCamelCase($string);
    }

    public function convertSnake($string)
    {
        return $this->toSplitCase($string);
    }

}

$converter = new Converter();

$converter->convertStudly("aCamelCaseName"); // ACamelCaseName
$studly = $converter->convertStudly("a_snake_case_name"); // returns "ASnakeCaseName"

$converter->convertSnake($studly); // back to "a_snake_case_name"
```

... and that's it?
------------------

[](#-and-thats-it)

Yup! Enjoy!

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance58

Moderate activity, may be stable

Popularity25

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 70% 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 ~762 days

Total

4

Last Release

711d ago

Major Versions

1.0.1 → 2.0.02021-02-09

PHP version history (2 changes)1.0.1PHP &gt;=5.4

2.0.0PHP &gt;=8.0

### Community

Maintainers

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

---

Top Contributors

[![Danny-Smart](https://avatars.githubusercontent.com/u/113538899?v=4)](https://github.com/Danny-Smart "Danny-Smart (14 commits)")[![downsider](https://avatars.githubusercontent.com/u/4508388?v=4)](https://github.com/downsider "downsider (3 commits)")[![UndeMa01](https://avatars.githubusercontent.com/u/117659219?v=4)](https://github.com/UndeMa01 "UndeMa01 (3 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/lexide-k-switch/health.svg)

```
[![Health](https://phpackages.com/badges/lexide-k-switch/health.svg)](https://phpackages.com/packages/lexide-k-switch)
```

###  Alternatives

[maize-tech/laravel-legal-consent

Laravel Legal Consent

521.8k](/packages/maize-tech-laravel-legal-consent)[millipress/millirules

A declarative rule engine for PHP that turns complex conditional logic into readable when-then rules. Features a fluent builder API, lazy-loaded context for performance, smart operator inference, and works seamlessly in pure PHP or WordPress.

111.3k4](/packages/millipress-millirules)

PHPackages © 2026

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