PHPackages                             knuckleswtf/scribe-tags2attributes - 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. [API Development](/categories/api)
4. /
5. knuckleswtf/scribe-tags2attributes

ActiveLibrary[API Development](/categories/api)

knuckleswtf/scribe-tags2attributes
==================================

Automatically convert most Scribe v3 docblock tags to v4 PHP 8 attributes

0.1.0(3y ago)081[1 issues](https://github.com/knuckleswtf/scribe-tags2attributes/issues)MITPHPPHP &gt;=8.0

Since Sep 8Pushed 3y agoCompare

[ Source](https://github.com/knuckleswtf/scribe-tags2attributes)[ Packagist](https://packagist.org/packages/knuckleswtf/scribe-tags2attributes)[ Docs](http://github.com/knuckleswtf/scribe-tags2attributes)[ RSS](/packages/knuckleswtf-scribe-tags2attributes/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

Scribe
======

[](#scribe)

This package provides a [Rector](https://github.com/rectorphp/rector) rule to automatically convert most Scribe v3 docblock tags to v4 PHP 8 attributes.

This package **will** smartly transform the following tags on controller methods to their attribute equivalents:

- `header`, `urlParam`, `queryParam`, and `bodyParam`
- `responseField`, `response` and `responseFile`
- `apiResource`,`apiResourceCollection`, and `apiResourceModel`
- `transformer`, `transformerCollection`, and `transformerModel`
- `subgroup`
- `authenticated` and `unauthenticated`

It **won't** transform `@group` tags or endpoint titles and descriptions (because they can look ugly as attributes).

It will only work on methods in classes. Unfortunately, attributes can't be added to inline (closure) routes in a neat way.

Example:

```
  /*
   * Do a thing.
   *
   * Because you want to.
   *
   * @group Endpoints for doing things
-  * @subgroup Getting started
-  * @subgroupDescription Get started doing stuff
-  * @header Test Value
-  * @response 204 scenario="Nothing to see here"
-  * @apiResourceCollection App\Http\Resources\UserResource
-  * @apiResourceModel App\Models\User with=sideProjects,friends states=admin paginate=12,simple
-  * @responseFile 404 scenario="User not found" responses/not_found.json {"resource": "user"}
   */
+ #[Subgroup('Getting started', 'Get started doing stuff')]
+ #[Header('Test', 'Value')]
+ #[Response(status: 204, description: '204, Nothing to see here')]
+ #[ResponseFromApiResource(UserResource::class, User::class, collection: true, factoryStates: ['admin'], with: ['sideProjects', 'friends'], simplePaginate: 12)]
+ #[ResponseFromFile('responses/not_found.json', status: 404, merge: '{"resource": "user"}', description: '404, User not found')]
  public function doSomething()
```

Usage
-----

[](#usage)

- Make sure the minimum PHP version in your `composer.json` is 8 (ie you should have `"php": ">= 8.0"` or similar in your `"require"` section).
- Install this package

    ```
    composer require knuckleswtf/scribe-tags2attributes --dev
    ```
- Run the Rector `init` command to create a `rector.php` file in the root of your project

    ```
    ./vendor/bin/rector init
    ```
- Put this in the generated `rector.php` (delete whatever's in the file):

    ```
