Coder Social home page Coder Social logo

autodoc-facades's Introduction

Autodoc Facades

A facade documenter for your Laravel application.


Autodoc Facades uses the official Laravel Facade Documenter to easily generate doc annotations for your application's Laravel facades inside your app directory using the @see annotation with a single command:

php artisan autodoc:facades app

Before:

namespace App\Facades;

/**
 * @see \App\Services\ServiceManager
 */
class Service extends Facade
{
    // ...
}
namespace App\Services;

class ServiceManager
{
    public function all(string $param): array
    {
        // ...    
    }
}

After:

namespace App\Facades;

/**
+* @method static array all(string $param)
+* 
 * @see \App\Services\ServiceManager
 */
class Service extends Facade
{
    // ...
}

Installation

Install via composer:

composer require --dev stevebauman/autodoc-facades

Usage

Inside the terminal:

php artisan autodoc:facades {paths} {--only=} {--except=}

Inside a Laravel command:

namespace App\Console\Commands;

class GenerateFacadeDocs extends Command
{
    // ...

    public function handle(): int
    {
        return $this->call('autodoc:facades', [
            'paths' => ['app'],
            '--except' => ['...'],
            '--only' => ['...'],
        ]);
    }
}

Getting started

To begin, your facades must contain an @see annotation with the fully-qualified namespace.

It will not resolve short-name classnames of classes that were imported.

For example, this will not work:

namespace App\Facades;

use App\Services\ServiceManager;

/**
 * @see ServiceManager
 */
class Service extends Facade
{
    // ...
}

If the underlying class forwards calls to another class, add a @mixin annotation to the underlying class so it is picked up by the documenter:

namespace App\Facades;

use App\Services\ServiceManager;

/**
 * @see \App\Services\ServiceManager
 */
class Service extends Facade
{
    protected function getFacadeAccessor()
    {
        return ServiceManager::class
    }
}
namespace App\Services;

use Illuminate\Support\Traits\ForwardsCalls;

/**
 * @mixin \App\Services\SomeClass
 */
class ServiceManager
{
    use ForwardsCalls;
    
    // ...
}

Generating annotations in path

To generate doc annotations for all facades in your app directory, supply "app" as the path:

All paths you provide that do not start with a directory separator will use the commands current working directory as the base path.

php artisan autodoc:facades app

Generating annotations in many paths

Space separate paths to generate annotations for facades in those directories:

php artisan autodoc:facades app/Services/Facades app/Api/Facades

Generating annotations for specific facades

Specify "only" classes to generate annotations only for those given:

You may provide multiple "only" classes by space separating them.

php artisan autodoc:facades app --only App\Facades\Service

Generating annotations for except specific facades

Specify "except" classes to generate annotations for all facades, except for those given:

You may provide multiple "except" classes by space separating them.

php artisan autodoc:facades app --except App\Facades\Service

autodoc-facades's People

Contributors

stevebauman avatar michaelnabil230 avatar

Stargazers

 avatar Thang Nguyen avatar Hugo-T avatar amir yousefi avatar  avatar Luca Patera avatar Noah Gillard avatar Luca Ubiali avatar Lukas Mateffy avatar carlin-rj avatar A Long Way avatar Socola Đại Ca avatar springlee avatar Sebastiaan avatar  avatar  avatar Vladimir avatar Rafael Acioly avatar Riju Ghosh avatar Victor Allen avatar Juha Vehnia avatar Haydar ŞAHİN avatar Irfaq Syed avatar Tobi avatar SUNAOKA Norifumi avatar Lucas Yang avatar Zainal Hasan avatar Gábor Szentpéteri avatar Krzysztof Bielecki avatar Patrick Samson avatar Wandes Cardoso avatar Muhammad Huzaifa avatar Ján Hamrák avatar Yılmaz Demir avatar Peter Fox avatar K-Kostas avatar Clem Blanco avatar Muath Alsowadi avatar Watheq Alshowaiter avatar 咸鱼 avatar P. K. Tharindu avatar chris-lee-lb avatar Daniel Ignacio Fernández avatar Jacek Andrzejewski avatar Turan Karatuğ avatar Juhász Zsolt avatar Martin Lechêne avatar Reece May avatar  avatar Mo Khosh avatar Murshal Akhtar Ansari avatar mitoop avatar Nasrul Hazim Bin Mohamad avatar Jonathan Finlay avatar Marco Germani avatar Kit Burton-Senior avatar Mahammad Nabiyev avatar Wisliy Lopes avatar sasin91 avatar Danylo Kolodij avatar  avatar Mohammad Mohammadi avatar Cooper avatar Dennis avatar Vladislav Stoitsov avatar Raphael Sefakor Adinkrah avatar D.C. Mastenbroek avatar Arne Ziegert avatar  avatar EverForge avatar Tristan Bendixen avatar Diaa Fares avatar Rokas Šleinius avatar Neil Carlo Sucuangco avatar Ruben Robles avatar Isaac Chargoy Vivaldo avatar Madalin Tache avatar Oluwatobi Samuel Omisakin avatar 8ack2Lobby avatar Enzo Innocenzi avatar guanguans avatar Brian Faust avatar Daniel Hartmann avatar Yunus Emre Deligöz avatar

Watchers

 avatar Socola Đại Ca avatar  avatar

autodoc-facades's Issues

[bug] laravel9 Class "Illuminate\Support\Facades\Process" not found

laravel9 Execution error!Process only runs on laravel10, Can you consider an implementation method that is compatible with lower versions?

php artisan autodoc:facades app
   Error 

  Class "Illuminate\Support\Facades\Process" not found

  at vendor/stevebauman/autodoc-facades/src/Commands/DocumentFacades.php:45
     41▕                 fn (string $classname) => ! in_array($classname, $except)
     42▕             );
     43▕         }
     44▕ 
  ➜  45▕         $result = Process::run(sprintf('php -f vendor/bin/facade.php -- %s', $facades->map(
     46▕             fn (string $classname) => str_replace('\\', '\\\\', $classname)
     47▕         )->join(' ')));
     48▕ 
     49▕         $result->successful()

      +13 vendor frames 
  14  artisan:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

Useful for decorators too

Hi, I wonder if it wouldn't be possible to extend this package to also be able to generate docblocks on classes that use the decorator pattern (like using the ForwardsCalls trait). I suppose the only real differences are that (1) they don't extend a common class like Facade, and (2) their methods are dynamic, not static.
Would you be interested in a PR that adds an additional autodoc:decorators command?
Or maybe just a common autodoc:generate which uses a publishable config file to determine what to generate.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.