PHPackages                             nxu/php-nano-class-parser - 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. nxu/php-nano-class-parser

ActiveLibrary

nxu/php-nano-class-parser
=========================

A fully opinionated, extremely minimal, and very optimistic package to help add custom code to generated PHP classes.

v2.0(1y ago)05.9k↓46.9%MITPHPPHP &gt;=8.2CI passing

Since Aug 16Pushed 1y ago1 watchersCompare

[ Source](https://github.com/nxu/php-nano-class-parser)[ Packagist](https://packagist.org/packages/nxu/php-nano-class-parser)[ RSS](/packages/nxu-php-nano-class-parser/feed)WikiDiscussions main Synced 1mo ago

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

🏗️ php-nano-class-parser
========================

[](#️-php-nano-class-parser)

[![tests](https://github.com/nxu/php-nano-class-parser/actions/workflows/tests.yml/badge.svg)](https://github.com/nxu/php-nano-class-parser/actions/workflows/tests.yml)[![phpstan](https://github.com/nxu/php-nano-class-parser/actions/workflows/phpstan.yml/badge.svg)](https://github.com/nxu/php-nano-class-parser/actions/workflows/phpstan.yml)[![Packagist Version (custom server)](https://camo.githubusercontent.com/284c655f1f15fe385620bc616494ab220ebd4939f55bb75f155242d7be5070ab/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e78752f7068702d6e616e6f2d636c6173732d706172736572)](https://packagist.org/packages/nxu/php-nano-class-parser)

This is a very simple package that helps you parse *some* information about *some* PHP files.

[![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner2-direct.svg)](https://stand-with-ukraine.pp.ua)

Philosophy
----------

[](#philosophy)

The intended purpose of this package is to determine the presence and optionally the vertical position of some statements in a PHP file. This is useful in situations like programmatically adding extra boilerplate to generated files.

Provided analyses:

- Imports (`use ;`)
- Class definition (`class Someting {}`)
- Trait uses (`use ;`)
- First function of a class (`public static function Something {}`)

### My use case

[](#my-use-case)

I am maintaining a CMS that is based on Laravel and Filament. Part of the CMS are commands that generate PHP files (such as Laravel Models and Filament Resources). During generation, my goals are:

- Use the built-in generators
- Append some custom PHP boilerplate to it

This package helps me determine *where* to add custom namespace uses, member properties and member functions as crude strings.

### Main features / restrictions

[](#main-features--restrictions)

 Extremely mimimal The package only provides *what I need*, nothing more. Fully opinionated The package provides its functionality exactly *how I need it*. Very optimistic This is a very nice way of saying *"I don't really care about edge cases"*.How?
====

[](#how)

Install
-------

[](#install)

```
composer require nxu/php-nano-class-parser --dev
```

Use
---

[](#use)

### TLDR

[](#tldr)

```
$class = PhpClass::parse(
