<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Irfaq Syed</title>
    <description>The latest articles on DEV Community by Irfaq Syed (@irazasyed).</description>
    <link>https://dev.to/irazasyed</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F338493%2F0e29642a-043e-41d3-a142-9810ebeccec0.jpeg</url>
      <title>DEV Community: Irfaq Syed</title>
      <link>https://dev.to/irazasyed</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/irazasyed"/>
    <language>en</language>
    <item>
      <title>Tutorial: How to Resolve Method Not Found Warnings in Laravel Packages using Docgen</title>
      <dc:creator>Irfaq Syed</dc:creator>
      <pubDate>Sat, 18 Mar 2023 19:48:00 +0000</pubDate>
      <link>https://dev.to/irazasyed/tutorial-how-to-resolve-method-not-found-warnings-in-laravel-packages-using-docgen-2766</link>
      <guid>https://dev.to/irazasyed/tutorial-how-to-resolve-method-not-found-warnings-in-laravel-packages-using-docgen-2766</guid>
      <description>&lt;p&gt;Developing Laravel packages is a task that requires a lot of attention to detail. One of the most common problems that Laravel package developers face is not properly documenting their facades or maintaining the docs. This can lead to warnings and errors in the IDEs that are used by developers when trying to use the package's methods using Laravel Facade.&lt;/p&gt;

&lt;p&gt;Fortunately, there is a solution to this problem: Introducing &lt;strong&gt;&lt;a href="https://github.com/irazasyed/docgen" rel="noopener noreferrer"&gt;Docgen for Laravel Facade&lt;/a&gt;&lt;/strong&gt; This package automatically generates documentation for your Laravel package facade, eliminating the tedious task of maintaining it yourself. With this package, IDEs will provide you and the developers using your package with method suggestions, making your development journey a breeze.&lt;/p&gt;

&lt;p&gt;In this tutorial, we will walk through the process of installing and using &lt;strong&gt;Docgen for Laravel Facade&lt;/strong&gt;, and how it can help solve the "Method Not Found" warnings in IDEs due to the lack of phpdoc blocks in facade.&lt;/p&gt;

&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;p&gt;Before we start, make sure you have the following installed:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Composer&lt;/li&gt;
&lt;li&gt;A Laravel Package to work with.&lt;/li&gt;
&lt;li&gt;PHP 8.0+&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;To get started, you'll need to install the package via composer. Run the following command in your Laravel package's root directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer require irazasyed/docgen &lt;span class="nt"&gt;--dev&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Basic Usage
&lt;/h2&gt;

&lt;p&gt;The basic usage of Docgen for Laravel Facade is quite simple. You just need to call the command with the name of the facade you want to generate documentation for.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;vendor/bin/docgen &lt;span class="nt"&gt;-f&lt;/span&gt; &lt;span class="s2"&gt;"Namespace&lt;/span&gt;&lt;span class="se"&gt;\P&lt;/span&gt;&lt;span class="s2"&gt;ath&lt;/span&gt;&lt;span class="se"&gt;\T&lt;/span&gt;&lt;span class="s2"&gt;o&lt;/span&gt;&lt;span class="se"&gt;\L&lt;/span&gt;&lt;span class="s2"&gt;aravel&lt;/span&gt;&lt;span class="se"&gt;\F&lt;/span&gt;&lt;span class="s2"&gt;acade::class"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace &lt;code&gt;Namespace\Path\To\Laravel\Facade::class&lt;/code&gt; with the actual namespace and class of your package facade.&lt;/p&gt;

&lt;h2&gt;
  
  
  Advanced Usage
&lt;/h2&gt;

&lt;p&gt;If your Laravel facade is linked to a chain of classes that require documentation, you can use Docgen's advanced features. Here's how you can create a new config file in your package's root directory named &lt;code&gt;docgen.php&lt;/code&gt; and add the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s1"&gt;'facade'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Namespace\Path\To\Laravel\Facade&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="c1"&gt;// Optional&lt;/span&gt;
    &lt;span class="c1"&gt;// Path\To\Class::class =&amp;gt; [Excluded Methods Array]&lt;/span&gt;
    &lt;span class="s1"&gt;'classes'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt;

    &lt;span class="c1"&gt;// Global Excluded Methods&lt;/span&gt;
    &lt;span class="s1"&gt;'excludedMethods'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can provide an array of class names in the &lt;code&gt;classes&lt;/code&gt; key, and an array of excluded methods for each class. The &lt;code&gt;excludedMethods&lt;/code&gt; key can be used to globally exclude certain methods from the documentation.&lt;/p&gt;

&lt;p&gt;To generate the documentation and apply it to the facade, run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;vendor/bin/docgen
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By default, it's smart to exclude the magic methods and constructor but there may be cases where you'd want to manually exclude them.&lt;/p&gt;

&lt;p&gt;Docgen is designed to only document public methods, so anything private or protected will by default not be documented.&lt;/p&gt;

&lt;p&gt;If your &lt;code&gt;docgen.php&lt;/code&gt; config file is stored elsewhere, you can provide the path using the &lt;code&gt;-c&lt;/code&gt; or &lt;code&gt;--config&lt;/code&gt; option:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;vendor/bin/docgen &lt;span class="nt"&gt;-c&lt;/span&gt; path/to/docgen.php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Generate Docs for Multiclass Facade
&lt;/h2&gt;

&lt;p&gt;If you have a Laravel facade that is linked to a chain of classes that require documentation, you can provide an array of class names to Docgen's &lt;code&gt;classes&lt;/code&gt; key. You can also exclude certain methods from the documentation of a specific class, by passing an array containing the names of those methods.&lt;/p&gt;

&lt;p&gt;Here's an example of how to use this approach with the &lt;a href="https://github.com/irazasyed/telegram-bot-sdk/blob/3.x/docgen.php" rel="noopener noreferrer"&gt;Telegram Bot SDK&lt;/a&gt;'s Laravel Facade:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// docgen.php&lt;/span&gt;

&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s1"&gt;'facade'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Telegram\Bot\Laravel\Facades\Telegram&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="s1"&gt;'classes'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="nc"&gt;\Telegram\Bot\BotsManager&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nc"&gt;\Telegram\Bot\Api&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="s1"&gt;'setContainer'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'getWebhookUpdates'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="nc"&gt;\Telegram\Bot\Commands\CommandBus&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="s1"&gt;'getTelegram'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'setTelegram'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;

    &lt;span class="c1"&gt;// Global Excluded Methods&lt;/span&gt;
    &lt;span class="s1"&gt;'excludedMethods'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To generate and apply the docs, simply run the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;vendor/bin/docgen
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Adding CLI Command to composer.json
&lt;/h2&gt;

&lt;p&gt;To make using &lt;strong&gt;Docgen for Laravel Facade&lt;/strong&gt; even easier, you can add the following CLI command to your &lt;code&gt;composer.json&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"docgen"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"docgen"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"test:docgen"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"docgen -d"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this command in place, you can run &lt;code&gt;composer docgen&lt;/code&gt; to generate and apply the facade documentation, or &lt;code&gt;composer test:docgen&lt;/code&gt; to dry-run and display the generated docblock assuming &lt;code&gt;docgen.php&lt;/code&gt; config file exists in the root of the project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;With Docgen for Laravel Facade, you can streamline your Laravel package development by automatically generating documentation for your facade.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you like the tutorial and the tool, come ⭐️ star it on &lt;a href="https://github.com/irazasyed/docgen" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt; :)&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>laravel</category>
      <category>php</category>
      <category>tutorial</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
