PHPackages                             lifespikes/scramble-match-stmt - 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. lifespikes/scramble-match-stmt

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

lifespikes/scramble-match-stmt
==============================

Sample extension for Scramble usage with PhpParser

1.0.5(2y ago)0301[4 PRs](https://github.com/lifespikes/scramble-match-stmt/pulls)MITPHPPHP ^8.1.2

Since Nov 6Pushed 1y ago2 watchersCompare

[ Source](https://github.com/lifespikes/scramble-match-stmt)[ Packagist](https://packagist.org/packages/lifespikes/scramble-match-stmt)[ RSS](/packages/lifespikes-scramble-match-stmt/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (9)Used By (0)

scramble-match-stmt
===================

[](#scramble-match-stmt)

This Scramble extension was made as an experiment of how usable PhpParser may be when building extensions.

In essence, it allows you to scan `JsonResource` classes whose `toArray` features a dynamic return type through a `match` statement.

Install
-------

[](#install)

```
composer require lifespikes/scramble-match-stmt
```

Then, in your `scramble.php` config file:

```
use LifeSpikes\ScrambleMatchStmt\ResourceWithMatchExtension;

...

'extensions' => [
    ResourceWithMatchExtension::class
]
```

Analyzing the code
------------------

[](#analyzing-the-code)

Scramble gives us the FQN of the type being analyzed, using `ReflectionClass`, we get the file path of the class.

We fetch the contents and use Scramble's `FileParser` to get the AST of the file we intend to analyze. This returns a `FileParserResult` object that is essentially a `PhpParser` instance.

Once we have a file, we use the `getMethod` method to help us get to the `toArray` method easier.

Then, we traverse through the nodes:

- First we find the `return` statement
- Then the `match`
- And then we get the first `MatchArm_`

Lastly, we get the body of the `MatchArm_` and verify it is an array.

Casting to Scramble types
-------------------------

[](#casting-to-scramble-types)

We had to go digging and used code from the `MethodAnalyzer` and `ArrayItemHandler` classes.

Then we mimicked some of their behavior and re-used other internal classes like `Scope` and `TypeHelper` to cast our PhpParser nodes to Scramble types.

Lastly, we used the `TypeTransformer` to turn everything into an usable OpenAPI Schema.

More info?
----------

[](#more-info)

Read the code, and some comments I sprinkled around for more details.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

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

Total

4

Last Release

917d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/94c3c286f59366c2c026802c5bd9ebb963affa818afed9d63f8b16991552b481?d=identicon)[CristianHG](/maintainers/CristianHG)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/lifespikes-scramble-match-stmt/health.svg)

```
[![Health](https://phpackages.com/badges/lifespikes-scramble-match-stmt/health.svg)](https://phpackages.com/packages/lifespikes-scramble-match-stmt)
```

###  Alternatives

[leocarmo/graceful-shutdown-php

Graceful Shutdown for PHP

18108.2k](/packages/leocarmo-graceful-shutdown-php)[bogdaan/open-location-code

Open location code for php

1076.5k](/packages/bogdaan-open-location-code)

PHPackages © 2026

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