PHPackages                             gregoriohc/byname - 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. gregoriohc/byname

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

gregoriohc/byname
=================

PHP trait for bynaming (nicknaming) classes/objects

v1.0.2(4y ago)0574MITPHPPHP ~5.6|~7.0|~8.0

Since Feb 5Pushed 4y ago1 watchersCompare

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

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

byname
======

[](#byname)

[![Latest Version on Packagist](https://camo.githubusercontent.com/d61028808c9bf95dd14bc277a880e14ae4571f1719d4b3a393ed57d9c7a5200a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f677265676f72696f68632f62796e616d652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/gregoriohc/byname)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/c70b702aca2b333f26c6d118de5c45b478cc370d6f33045aa55e40a1334de282/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f677265676f72696f68632f62796e616d652f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/gregoriohc/byname)[![Coverage Status](https://camo.githubusercontent.com/c75a418ea9832aaefeb9a239bdd8b21b132e65bfdacadaab682afd4d37ce9811/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f677265676f72696f68632f62796e616d652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/gregoriohc/byname/code-structure)[![Quality Score](https://camo.githubusercontent.com/c48e245f2002ba43523d01ef7763563d570e341f08ef946a7488a07a7ab442bc/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f677265676f72696f68632f62796e616d652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/gregoriohc/byname)[![Total Downloads](https://camo.githubusercontent.com/ae908f058e96659430672121ff88ed0987c1db3b3a5fb9dbe04d5bd02284f73c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f677265676f72696f68632f62796e616d652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/gregoriohc/byname)

PHP trait for bynaming (nicknaming) classes/objects.

Install
-------

[](#install)

Via Composer

```
$ composer require gregoriohc/byname
```

Usage
-----

[](#usage)

By default, the class byname is the class basename (without namespace).

```
class MyClass {
    use HasByname;
}

echo MyClass::byname();
// MyClass
```

### Removing prefix and/or suffix

[](#removing-prefix-andor-suffix)

You can remove some characters from the beginning (prefix) or the end (suffix) of the byname overriding the `bynamePrefix` and `bynameSuffix` methods and returning the string to remove or the number of characters.

```
class MyClass {
    use HasByname;
    protected static function bynamePrefix()
    {
        return 'My';
    }
}

echo MyClass::byname();
// Class
```

```
class MyClass {
    use HasByname;
    protected static function bynameSuffix()
    {
        return 5;
    }
}

echo MyClass::byname();
// My
```

A more complex example, mixing this with inheritance:

```
abstract class BaseController {
    use HasByname;
    protected static function bynameSuffix()
    {
        return 'Controller';
    }
    public function model()
    {
        $class = '\\App\\' . $this->byname();
        return new $class();
    }
}

class UserController extends BaseController {
    ...
}

echo UserController::byname();
// User

$user = (new UserController)->model();
print_r($user);
// App\User Object (...)
```

### Custom byname

[](#custom-byname)

You can set a custom byname overriding the `bynameValue` method.

```
class MyClass {
    use HasByname;
    protected static function bynameValue()
    {
        return 'Cool';
    }
}

echo MyClass::byname();
// Cool
```

### Case

[](#case)

Yu can also get the name in three diferent cases:

```
class MyClass {
    use HasByname;
}

echo MyClass::bynameSnake();
// my_class
echo MyClass::bynameCamel();
// myClass
echo MyClass::bynameStudly();
// MyClass
```

Testing
-------

[](#testing)

```
$ composer test
```

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Socialware
----------

[](#socialware)

You're free to use this package, but if it makes it to your production environment I highly appreciate you sharing it on any social network.

Credits
-------

[](#credits)

- [Gregorio Hernández Caso](https://github.com/gregoriohc)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

32

—

LowBetter than 71% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity70

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

Total

3

Last Release

1795d ago

PHP version history (2 changes)v1.0.0PHP ~5.6|~7.0

v1.0.2PHP ~5.6|~7.0|~8.0

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

gregoriohcbyname

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/gregoriohc-byname/health.svg)

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

###  Alternatives

[ozdemir/datatables

Simplify your Datatables server-side processing effortlessly using our lightning-fast PHP library, streamlining your workflow seamlessly.

273158.4k](/packages/ozdemir-datatables)[that0n3guy/transliteration

Transliteration provides one-way string transliteration (romanization) and cleans text by replacing unwanted characters.

1296.5k4](/packages/that0n3guy-transliteration)

PHPackages © 2026

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