PHP code example of glhd / laralint

1. Go to this page and download the library: Download glhd/laralint library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

glhd / laralint example snippets


class Foo
{
  public function bar()
  {
    return 'baz';
  }
}

(new TreeMatcher())
    // (1) Find a method declaration where the method name is "bar"
    ->withChild(function(MethodDeclaration $node) {
        return 'bar' === $node->getName();
    })
    // (2) Find any return statement
    ->withChild(ReturnStatement::class)
    // (3) Find a string literal that matches the string "baz"
    ->withChild(function(StringLiteral $node) {
        return 'baz' === $node->getStringContentsText();
    })
    ->onMatch(function(Collection $all_matched_nodes) {
        // Create a linting result using the matched nodes.
        // LaraLint will automatically map the AST nodes to line
        // numbers when printing the results.
    });
bash
php artisan laralint:lint
bash
php artisan laralint:lint --diff
bash
php artisan laralint:lint app/Http/Controllers/HomeController.php
bash
php artisan vendor:publish --tag=laralint-config
bash
php artisan laralint:dump barbaz_source.php

┏━━ ClassDeclaration ━━━━━━┓
┃                          ┃
┃ class Foo                ┃
┃ {                        ┃
┃   public function bar()  ┃
┃   {                      ┃
┃     return 'baz';        ┃
┃   }                      ┃
┃ }                        ┃
┃                          ┃
┃   ┏━━ ClassMembersNode ━━━━━━┓
┃   ┃                          ┃
┃   ┃ {                        ┃
┃   ┃   public function bar()  ┃
┃   ┃   {                      ┃
┃   ┃     return 'baz';        ┃
┃   ┃   }                      ┃
┃   ┃ }                        ┃
┃   ┃                          ┃
┃   ┃   ┏━━ MethodDeclaration ━━━┓
┃   ┃   ┃                        ┃
┃   ┃   ┃ public function bar()  ┃
┃   ┃   ┃   {                    ┃
┃   ┃   ┃     return 'baz';      ┃
┃   ┃   ┃   }                    ┃
┃   ┃   ┃                        ┃
┃   ┃   ┃   ┏━━ CompoundStatementNode ━━┓
┃   ┃   ┃   ┃                           ┃
┃   ┃   ┃   ┃ {                         ┃
┃   ┃   ┃   ┃     return 'baz';         ┃
┃   ┃   ┃   ┃   }                       ┃
┃   ┃   ┃   ┃                           ┃
┃   ┃   ┃   ┃   ┏━━ ReturnStatement ━━┓
┃   ┃   ┃   ┃   ┃                     ┃
┃   ┃   ┃   ┃   ┃ return 'baz';       ┃
┃   ┃   ┃   ┃   ┃                     ┃
┃   ┃   ┃   ┃   ┃   ┏━━ StringLiteral ━━┓
┃   ┃   ┃   ┃   ┃   ┃                   ┃
┃   ┃   ┃   ┃   ┃   ┃ 'baz'             ┃
┃   ┃   ┃   ┃   ┃   ┃                   ┃
┃   ┃   ┃   ┃   ┃   ┗━━━━━━━━━━━━━━━━━━━┛
┃   ┃   ┃   ┃   ┗━━━━━━━━━━━━━━━━━━━━━┛
┃   ┃   ┃   ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
┃   ┃   ┗━━━━━━━━━━━━━━━━━━━━━━━━━┛
┃   ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
bash
php artisan laralint:lint --printer=phpcs