PHPackages                             itrocks/class-use - 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. itrocks/class-use

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

itrocks/class-use
=================

The "Where is this class used, and what for?" index-and-query library

03PHP

Since Oct 6Pushed 2y ago2 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

PHP class use scanner
---------------------

[](#php-class-use-scanner)

This it.rocks library gives your software the ability to get a quick answer to the **"Where and what is this class used for?"** question.

It offers a programming API and command lines to scan your PHP project for class references, store them into an indexed class use cache into your filesystem, then allow you to search where a class is used into your whole project.

It is designed to be simple to apply to any PHP project, and fast to execute. Its code aims for simplicity and lightweight: no library dependency, and I tried to limit it to the fewer abstraction layers I could in order to get a code simple to understand and to update.

Pre-requisites
--------------

[](#pre-requisites)

- This works with PHP 8.2 only. I wanted to make full use of the current PHP version features.
    To install php 8.2 on a Debian/Ubuntu/Mint system: .

Command line usage
------------------

[](#command-line-usage)

Command line is available for usage demonstration purpose and benchmarking: it displays operation duration, memory usage, and counters. It makes it easy to test the library without having to write source code.

### Installation

[](#installation)

```
git clone itrocks/class-use

# make it available from any directory (Linux systems):
sudo ln -s `pwd`/class-use/bin/run /usr/local/bin/class-use
```

### Update cache

[](#update-cache)

From any subdirectory of your PHP project (e.g. here from the project root directory):

```
class-use vendor

# OR: if you did not add a direct link to the console script, you can do the same with (Linux systems):
/path/to/your/clone/of/itrocks/class-use/bin/run vendor

# OR: if you have php installed on a non-Linux system (e.g. Windows):
php /path/to/your/clone/of/itrocks/class-use/bin/run.php vendor
```

#### Options

[](#options)

- `reset`: Fully recalculate your class use cache. If not set, only files modified since the last update will be scanned for update.
- `pretty`: Class use cache json files will be human-readable, including spaces and carriage returns; Nevertheless, cache files will be bigger.
- `vendor`: Updates class uses concerning php files from the `vendor` directory too. If not set, only your project files will be scanned, which will be quite faster, and enough only if you don't need third-party PHP scripts class use information.

### Search for occurrences

[](#search-for-occurrences)

From any directory of your PHP project (e.g. here from the project root directory):

```
class-use type=declare-class use=ITRocks/Class_Use/Index data
```

This example will output all uses of the class use Index into all your project scripts.

If you love escaping antislashes, feel free to type them to match PHP class path naming rules:

```
class-use type=declare-class use=ITRocks\\Class_Use\\Index data
```

#### Search keys

[](#search-keys)

You can use one or several search criterion, identified by these keys:

- `class`: Search class uses only into this class source code
- `use`: Search class uses of this class
- `type`: Search class uses of this type (type lists below)

#### Options

[](#options-1)

These options can be added to your command line:

- `associative`: Result record keys will be text instead of arbitrary numeric counter.
- `benchmark`: Display a benchmark measure of search speed and memory consumption.
- `data`: Display found class uses into a compact json format.
- `total`: Display the total results count, e.g. "2 results".
- `pretty`: Display found class uses into a pretty json format.

If no `associative`/`data`/`pretty`/`total` option is set, the `total` option will be applied by default.

Associative result keys are:

- `class`: The name of the class context where the use is
- `type`: The use type (type lists below)
- `use`: The used class name
- `file`: The name of the file where the use is
- `line`: The line number
- `token`: The index of the token where the used class name is into the source code

Programming API usage
---------------------

[](#programming-api-usage)

### Installation

[](#installation-1)

To add this to your project:

```
composer require itrocks/class-use
```

### Update cache

[](#update-cache-1)

When your project need to update the cache, these are the update steps to follow:

```
use ITRocks\Class_Use\Index;

$index = new Index(Index::VENDOR);
$index->scanDirectory();
$index->classify();
$index->save();
```

#### Option flags

[](#option-flags)

- `Index::VENDOR`: Updates class use cache concerning php files from the `vendor` directory too. If not set, only your project files will be scanned, which will be quite faster, and enough only if you don't need third-party PHP scripts class use information.
- `Index::RESET`: Fully recalculate your class use cache. If not set, only files modified since the last update will be scanned for update.
- `Index::PRETTY`: Class use cache json files will be human-readable, including spaces and carriage returns; Nevertheless, cache files will be bigger.

The constructor of `Index` has a second argument, `$home`, to force the directory where to scan classes and save class use cache from. If not set, this will scan your project files, found from the current working directory.

### Search for occurrences

[](#search-for-occurrences-1)

```
use ITRocks\Class_Use\Index;

echo "These are where the Index class is used:\n";
$index = new Index();
foreach ($index->search([T_USE => Index::class]) as $reference) {
  [$class, $type, $use, $file, $line, $token] = $reference;
	echo "#$key. $type into $file";
	if ($class) echo " class $class";
	echo " token $token line $line";
	echo "\n";
}
```

This example will output all the references to the class use Index into all your project scripts.

You can see multiple examples in action running the scripts into the `examples` directory. e.g.:

```
php examples/complete.php
```

The unit test into `tests/scanner.references.proviver` and `Scanner_Test.php` contain a lot of other examples with expected results.

#### Search keys

[](#search-keys-1)

You can use one or several search criterion, identified by these keys:

- T\_CLASS: Search class uses into this class source code
- T\_TYPE: Search class uses of this type (type lists below)
- T\_USE: Search class uses of this class, everywhere

Class use Types
---------------

[](#class-use-types)

When it is a numeric, each found class use reference is qualified with any of these class use type identifiers:

- T\_ARGUMENT: the class is used as a function argument type
- T\_ATTRIBUTE: the class is an attribute used into a `#[...]` statement
- T\_CLASS: an explicit use of the name of the class into the source code, ie `Class_Name::class`
- T\_DECLARE\_CLASS: the class declaration
- T\_DECLARE\_INTERFACE: the interface declaration
- T\_DECLARE\_TRAIT: the trait declaration
- T\_EXTENDS: the class appears into an `extends` statement of another class declaration
- T\_IMPLEMENTS: the class appears into an `implements` statement of another class declaration
- T\_INSTANCEOF: the class appears after an `instanceof` statement
- T\_INSTEADOF: the class appears after an `insteadof` statement
- T\_NEW: the class is used to instantiate an object
- T\_RETURN: the class is used into a function return type
- T\_STATIC: the class is used for a static call, e.g. `Class_Name::static` or `Class_Name::CONSTANT`
- T\_USE: the class appears into a class `use` statement
- T\_VARIABLE: the class is used into a class property type definition

From command line calls: the type name is almost the same as the type list constant name: instead of passing `T_DECLARE_CLASS` in command line, pass `declare-class` or `declare_class`. All these variants will work, and the integer value matching the constant name too if you prefer.

When it is a string, attribute names are used as types: every class use into an attribute will be referred with a type being the name of the attribute. Only `::class` as an argument, or as a value into an array argument, are taken in account.

###  Health Score

13

—

LowBetter than 1% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity21

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/9c59494f987e0e7b01198896224a0ed287c0406c2d216b9c6d7a239d912fb7c5?d=identicon)[itrocks](/maintainers/itrocks)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/itrocks-class-use/health.svg)

```
[![Health](https://phpackages.com/badges/itrocks-class-use/health.svg)](https://phpackages.com/packages/itrocks-class-use)
```

###  Alternatives

[epigra/trstringhelper

PHP Türkçe Karakter Destekli String Fonksiyonları (toupper,tolower,ucfirst,ucwords,capitalizefirst) Kütüphanesi

244.1k](/packages/epigra-trstringhelper)

PHPackages © 2026

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