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(2y ago)012.7k↑114.2%1[1 PRs](https://github.com/lexide/k-switch/pulls)2MITPHPPHP &gt;=8.0CI failing

Since Mar 2Pushed 5mo 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 2d 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

44

—

FairBetter than 90% of packages

Maintenance49

Moderate activity, may be stable

Popularity26

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

757d 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://avatars.githubusercontent.com/u/4508388?v=4)[Danny Smart](/maintainers/downsider)[@downsider](https://github.com/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

[himiklab/yii2-sortable-grid-view-widget

Sortable modification of standard Yii2 GridView widget

79361.2k7](/packages/himiklab-yii2-sortable-grid-view-widget)[opensky/runtime-config-bundle

This bundle provides a way to inject parameters into services at runtime by exposing a RuntimeParameterBag service, which functions exactly like Symfony2's own ParameterBags.

10949.6k1](/packages/opensky-runtime-config-bundle)[nsavinov/nova-percent-field

A Laravel Nova field.

21280.0k](/packages/nsavinov-nova-percent-field)

PHPackages © 2026

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