PHPackages                             hostnet/type-inference-tool - 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. hostnet/type-inference-tool

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

hostnet/type-inference-tool
===========================

Tool to infer param- and return types and declare them as return type declarations and type hints.

702[1 PRs](https://github.com/hostnet/type-inference-tool/pulls)PHP

Since Nov 20Pushed 5y ago2 watchersCompare

[ Source](https://github.com/hostnet/type-inference-tool)[ Packagist](https://packagist.org/packages/hostnet/type-inference-tool)[ RSS](/packages/hostnet-type-inference-tool/feed)WikiDiscussions master Synced 5d ago

READMEChangelogDependenciesVersions (1)Used By (0)

**Abandoned**

This package is abandoned. Use alternative tools like:

- [PHPCS has great typehinting support out-of-the-box](https://github.com/slevomat/coding-standard)

Type-inference-tool
===================

[](#type-inference-tool)

As of PHP 7.0 it is possible to add [scalar type hints](https://wiki.php.net/rfc/scalar_type_hints) and [return type declarations](https://wiki.php.net/rfc/return_types). The type-inference-tool is created to add these type hints to PHP-applications by executing one command.

The type-inference-tool adds parameter- and return type hints to PHP-projects by using dynamic and static analysis. Dynamic analysis is done by analyzing traces generated during the execution of the target project its PHPUnit tests (runtime). Static analysis is done by parsing the PHP-code of the target project to abstract syntax tree's and analysing them. The data collected by the static- and dynamic analyzers are combined and used to infer parameter- and function types.

Prerequisites
-------------

[](#prerequisites)

- XDebug must be installed
- Requires PHP 7.1+
- Target project must have working PHPUnit tests (non-failing/not causing errors)
- Target project its Composer dependencies must be installed

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

[](#installation)

Clone `hostnet/type-inference-tool` and install the dependencies using Composer.

Usage
-----

[](#usage)

The type-inference-tool is used by executing a command. This section explains the available options for this command.

**Base command:**

The most basic command to execute is the following:

```
./application.php execute

```

**Options:**

Certain options can be set alongside the base command. These are the following:

- `--log-file=`: Specify a file to write logs to. The progress during execution can be followed by tailing the log file. Cases in which type hints cannot be added to parameters or functions will also be logged.
- `--storage-type=`: The dynamic analyzer uses [XDebug trace files](https://xdebug.org/docs/execution_trace) during analysis. Parsing these traces can take up a lot of space, depending on the size of the target project. To prevent the tool from exhausting the memory, three storage methods are provided: `mem` (default), `file` and `db`. `mem` will use the internal memory to save the parsed data to. This is usually the fastest method, but not recommended when running the tool on bigger projects. `file` will store the parsed data to external files, this results in less memory usage but a slower execution time. `db` is similar to `file`but will store data to a database. When running the tool on huge projects, `db` is recommended. Note that when using `db`, the following option `--db-config` must be provided.
- `--db-config=`: When using `--storage-type=db` this option must be provided. With this option a database configuration is set. See [/database/config.json.dist](/database/config.json.dist) for the structure of such configuration file. Make sure your database has same structure as defined in [DDL.sql](/database/config.json.dist)
- `--ignore-folders=`: Set folders to be ignored. Files within ignored folder will not receive type hints. The vendor-folder is always ignored. This option is especially useful to exclude generated files from being altered.
- `--trace=`: In case you already have an XDebug trace file for your target project, you can provide that trace file to be used during dynamic analysis. This is profitable for large projects where generating XDebug trace files can take quite some time and space.
- `--show-diff`: When enabled, the type-inference-tool will output all changes made (diffs) to the target project on the console.
- `--analyse-only`: By enabling this option the type-inference-tool will not modify the given target project. This is useful in combination with the `--show-diff` option for small projects to check what type hints would be added.
- `--help`: Shows help. Lists all available options with short descriptions.

Examples
--------

[](#examples)

This section provides some execution command examples. These examples are classified in three types of target projects: small, bigger and huge. Since these terms are quite subjective it is up to you to determine whether your target projects would be small, big or huge.

**Small projects**

When executing the tool on 'smaller' projects, the command below would be recommended. Using this command the in-memory data storage would be used.

```
./application.php execute /home/user/projects/my-project --log-file=/home/user/projects/logs/mylogs.log --ignore-folders=Generated,cache,test

```

**Bigger projects**

When executing the project on a 'bigger' project, the file storage type would be recommended. When executing the tool on 'bigger' or 'huge' projects it would be profitable to carefully set your `--ignore-folders` as this would decrease the execution time of the tool.

```
./application.php execute /home/user/projects/my-project --log-file=/home/user/projects/logs/mylogs.log --storage-type=file --ignore-folders=Generated,cache,test

```

**Huge projects**

When executing the tool on huge projects, the database storage type would be recommended. Important is that your database config (`--db-config`) is correct and your database already has the valid tables (database definition provided in [DDL.sql](/database/config.json.dist)). Note that executing the tool on 'huge' projects easily can take up to more than one hour (depending on the size of the target project). Providing an existing XDebug trace would decrease the execution time. If no trace is provided, the type-inference-tool generates a new one. The newly generated trace file will be deleted afterwards.

```
./application.php execute /home/user/projects/my-project --log-file=/home/user/projects/logs/mylogs.log --storage-type=db --db-config=/home/user/database-config.json --ignore-folders=Generated,cache,test

```

After execution
---------------

[](#after-execution)

The type-inference-tool does not guarantee that the resulting target project is entirely correct. Make sure you verify the state of your target project. This could be done by executing PHPUnit and checking whether no failures or errors occur.

The type-inference-tool does not add use-statements to project files, after adding type hints you may have to add use-statements yourself.

The type-inference-tool may cause violations to your PHP-coding style/conventions. Make sure you check this by hand or using a PHP code-sniffer. A violation the tool may cause is that certain lines of code exceed the maximum amount of characters per line after adding type hints.

Improvements
------------

[](#improvements)

The type-inference-tool currently has following limitations:

- The tool does not check for [PHP 7.2 covariance](https://wiki.php.net/rfc/parameter-no-type-variance)

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity31

Early-stage or recently created project

 Bus Factor2

2 contributors hold 50%+ of commits

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/65433e1ef6edb2e8f96e18614b6618c84eed20ad0de6de0d0da36a9032ec7a18?d=identicon)[hostnet](/maintainers/hostnet)

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

![](https://avatars.githubusercontent.com/u/9057191?v=4)[Mike de Heij](/maintainers/mdeheij)[@mdeheij](https://github.com/mdeheij)

---

Top Contributors

[![mdeheij](https://avatars.githubusercontent.com/u/9057191?v=4)](https://github.com/mdeheij "mdeheij (2 commits)")[![nutama](https://avatars.githubusercontent.com/u/9001392?v=4)](https://github.com/nutama "nutama (2 commits)")[![yannickl88](https://avatars.githubusercontent.com/u/5468127?v=4)](https://github.com/yannickl88 "yannickl88 (2 commits)")[![mvannes](https://avatars.githubusercontent.com/u/8969371?v=4)](https://github.com/mvannes "mvannes (1 commits)")[![ping-localhost](https://avatars.githubusercontent.com/u/37925797?v=4)](https://github.com/ping-localhost "ping-localhost (1 commits)")

### Embed Badge

![Health badge](/badges/hostnet-type-inference-tool/health.svg)

```
[![Health](https://phpackages.com/badges/hostnet-type-inference-tool/health.svg)](https://phpackages.com/packages/hostnet-type-inference-tool)
```

PHPackages © 2026

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