PHPackages                             feolius/hell2shape - 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. feolius/hell2shape

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

feolius/hell2shape
==================

Generate PHPStan type annotations from var\_dump output

0.4.4(1mo ago)473232[1 issues](https://github.com/Feolius/hell2shape/issues)MITPHPPHP ^8.3CI passing

Since Dec 30Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/Feolius/hell2shape)[ Packagist](https://packagist.org/packages/feolius/hell2shape)[ RSS](/packages/feolius-hell2shape/feed)WikiDiscussions main Synced today

READMEChangelog (5)Dependencies (8)Versions (14)Used By (0)

hell2shape
==========

[](#hell2shape)

> Generate PHPStan type annotations from var\_dump output

A CLI tool that analyzes PHP `var_dump()` output and generates PHPStan-compatible type annotations, helping you add type hints to legacy code or complex data structures.

Use It Online
-------------

[](#use-it-online)

🌐 **[Try hell2shape in your browser](https://hell2shape.netlify.app/)** - No installation required. Works locally in your browser, no data transferred -- thanks to php-wasm.

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

[](#installation)

### Option 1: Install via Composer (Recommended for Programmatic Usage)

[](#option-1-install-via-composer-recommended-for-programmatic-usage)

```
composer require --dev feolius/hell2shape
```

This allows you to use hell2shape both programmatically in your code and via CLI.

### Option 2: Download PHAR (Standalone Executable)

[](#option-2-download-phar-standalone-executable)

Download the latest `hell2shape.phar` from the [releases page](https://github.com/Feolius/hell2shape/releases) and use it directly:

```
# Download the PHAR
curl -L https://github.com/Feolius/hell2shape/releases/latest/download/hell2shape.phar -o hell2shape.phar

# Make it executable
chmod +x hell2shape.phar

# Use it
php -r 'var_dump($myArray);' | ./hell2shape.phar
```

### Option 3: Use [cpx](https://cpx.dev/)

[](#option-3-use-cpx)

```
php -r 'var_dump($myArray);' | cpx feolius/hell2shape
```

**Requirements:**

- PHP 8.3 or higher

Usage
-----

[](#usage)

### Programmatic Usage

[](#programmatic-usage)

Use hell2shape directly in your PHP code to generate type annotations:

```
use Feolius\Hell2Shape\Hell2Shape;
use Feolius\Hell2Shape\Generator\GeneratorConfig;
use Feolius\Hell2Shape\Generator\KeyQuotingStyle;

// Simple usage with default config (generates PSR-5 doc-comment format)
$data = ['name' => 'John', 'age' => 30];
$shape = Hell2Shape::generate($data);
// Result: /**
//          * array{
//          *     name: string,
//          *     age: int,
//          * }
//          */

// Without doc-comment wrapper
$config = GeneratorConfig::withoutDocComment();
$shape = Hell2Shape::generate($data, $config);
// Result: array{
//     name: string,
//     age: int,
// }

// Single-line output without doc-comment
$config = GeneratorConfig::withoutDocComment(indentSize: 0);
$shape = Hell2Shape::generate($data, $config);
// Result: array{name: string, age: int}

// With custom formatting (doc-comment is default)
$config = new GeneratorConfig(
    keyQuotingStyle: KeyQuotingStyle::SingleQuotes,
    indentSize: 2,
);
$shape = Hell2Shape::generate($data, $config);
// Result: /**
//          * array{
//          *   'name': string,
//          *   'age': int,
//          * }
//          */
```

### CLI Usage

[](#cli-usage)

Pipe any `var_dump()` output to `hell2shape`:

```
# From a PHP script
php script.php | vendor/bin/hell2shape

# From a one-liner
php -r 'var_dump(["name" => "John", "age" => 30]);' | vendor/bin/hell2shape
```

### Output Example

[](#output-example)

**Input (var\_dump):**

```
array(2) {
  ["name"]=>
  string(4) "John"
  ["age"]=>
  int(30)
}

```

**Output (PHPStan type with doc-comment - default):**

```
/**
 * array{
 *     name: string,
 *     age: int,
 * }
 */
```

**Output (without doc-comment using `--no-doc-comment`):**

```
array{
    name: string,
    age: int,
}
```

Options
-------

[](#options)

### `--no-doc-comment`

[](#--no-doc-comment)

Disable PSR-5 doc-comment wrapper around the output (by default, output is wrapped in `/** */`)

```
# Default: with doc-comment wrapper
hell2shape
# Output: /**
#          * array{...}
#          */

# Without doc-comment wrapper
hell2shape --no-doc-comment
# Output: array{...}
```

### `--indent` / `-i`

[](#--indent---i)

Control indentation for multi-line output (default: 4 spaces)

```
# Single-line output
hell2shape --indent=0

# 2-space indentation
hell2shape -i 2

# Default 4-space indentation
hell2shape
```

### `--quotes`

[](#--quotes)

Control key quoting style in array shapes

```
# No quotes (default)
hell2shape --quotes=none
# Output: array{name: string}

# Single quotes
hell2shape --quotes=single
# Output: array{'name': string}

# Double quotes
hell2shape --quotes=double
# Output: array{"name": string}
```

### `--class` / `-c`

[](#--class---c)

Control how class names are formatted (default: unqualified)

```
# Unqualified - just the class name (default)
hell2shape --class=uqn
# Output: User

# Qualified - with namespace
hell2shape -c qn
# Output: App\Models\User

# Fully qualified - with leading backslash
hell2shape --class=fqn
# Output: \App\Models\User
```

Features
--------

[](#features)

- ✅ Scalar types (int, string, bool, float, null)
- ✅ Arrays and nested arrays
- ✅ Array shapes with optional keys
- ✅ Objects (class names)
- ✅ stdClass objects as object shapes
- ✅ Lists with union types
- ✅ Complex nested structures
- ✅ Configurable formatting

Examples
--------

[](#examples)

### Simple Array

[](#simple-array)

```
php -r 'var_dump(["id" => 1, "name" => "Alice"]);' | hell2shape
```

Output:

```
/**
 * array{
 *     id: int,
 *     name: string,
 * }
 */
```

### Nested Structure

[](#nested-structure)

```
php -r 'var_dump(["user" => ["name" => "Bob", "roles" => ["admin", "user"]]]);' | hell2shape
```

Output:

```
/**
 * array{
 *     user: array{
 *         name: string,
 *         roles: list,
 *     },
 * }
 */
```

### Without Doc-Comment

[](#without-doc-comment)

```
php -r 'var_dump(["id" => 1, "active" => true]);' | hell2shape --no-doc-comment
```

Output:

```
array{
    id: int,
    active: bool,
}
```

### Single-line Output

[](#single-line-output)

```
php -r 'var_dump(["id" => 1, "active" => true]);' | hell2shape --no-doc-comment --indent=0
```

Output:

```
array{id: int, active: bool}
```

### Optional Keys

[](#optional-keys)

When arrays have different structures, hell2shape marks missing keys as optional:

```
array{
    id: int,
    name: string,
    email?: string
}
```

### Object Types

[](#object-types)

```
php -r 'namespace App\Models; class User {} var_dump(new User());' | hell2shape
```

Output (default - unqualified):

```
/** User */
```

With qualified names:

```
php -r 'namespace App\Models; class User {} var_dump(new User());' | hell2shape -c qn
```

Output:

```
/** App\Models\User */
```

With fully qualified names:

```
php -r 'namespace App\Models; class User {} var_dump(new User());' | hell2shape --class=fqn
```

Output:

```
/** \App\Models\User */
```

Limitations
-----------

[](#limitations)

⚠️ **Important:** This tool provides a **starting point** for type annotations, not a complete solution.

- var\_dump doesn't show all possible values, only the current state
- Union types are inferred from visible data only
- You should review and refine the generated types based on your actual usage
- Empty arrays are typed as `array` (not `list`)

Development
-----------

[](#development)

```
# Run tests
vendor/bin/phpunit

# Run PHPStan
vendor/bin/phpstan analyse

# Run code style checks
vendor/bin/ecs check
```

License
-------

[](#license)

MIT License - see [LICENSE](LICENSE) file for details

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

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

###  Health Score

46

—

FairBetter than 92% of packages

Maintenance91

Actively maintained with recent releases

Popularity26

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 98.1% 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 ~12 days

Recently: every ~29 days

Total

13

Last Release

42d ago

PHP version history (2 changes)0.1.0PHP ^8.4

0.3.0PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/47be7ffaebc23ff0aee714982daef566bce12c67193aecfb624f7c66ae5596dd?d=identicon)[Feolius](/maintainers/Feolius)

---

Top Contributors

[![Feolius](https://avatars.githubusercontent.com/u/1930829?v=4)](https://github.com/Feolius "Feolius (102 commits)")[![ddanielou](https://avatars.githubusercontent.com/u/1174337?v=4)](https://github.com/ddanielou "ddanielou (1 commits)")[![vudaltsov](https://avatars.githubusercontent.com/u/2552865?v=4)](https://github.com/vudaltsov "vudaltsov (1 commits)")

---

Tags

php-typehintingphpstanpsalmPHPStanstatic analysisvar\_dumptype-annotations

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleECS

Type Coverage Yes

### Embed Badge

![Health badge](/badges/feolius-hell2shape/health.svg)

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

###  Alternatives

[friendsofphp/php-cs-fixer

A tool to automatically fix PHP code style

13.5k251.2M25.2k](/packages/friendsofphp-php-cs-fixer)[friendsoftypo3/content-blocks

TYPO3 CMS Content Blocks - Content Types API | Define reusable components via YAML

103519.9k53](/packages/friendsoftypo3-content-blocks)[phel-lang/phel-lang

Phel is a functional programming language that compiles to PHP

5186.0k18](/packages/phel-lang-phel-lang)[dagger/dagger

Dagger PHP SDK

261.1k](/packages/dagger-dagger)

PHPackages © 2026

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