Chapter 9. The Command-Line

The command-line interface is the easiest way to try and learn the basic Reflect features.

[Note]

For all users.

9.1. Command-Line Options

Without plugins and analysers sections in your phpreflect.json configuration file, when you invoke the phpreflect command, you should obtain the following commands and options :

        _           ____       __ _           _
  _ __ | |__  _ __ |  _ \ ___ / _| | ___  ___| |_
 | '_ \| '_ \| '_ \| |_) / _ \ |_| |/ _ \/ __| __|
 | |_) | | | | |_) |  _ <  __/  _| |  __/ (__| |_
 | .__/|_| |_| .__/|_| \_\___|_| |_|\___|\___|\__|
 |_|         |_|

phpReflect version 3.0.1

Usage:
 [options] command [arguments]

Options:
 --help (-h)           Display this help message
 --quiet (-q)          Do not output any message
 --verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
 --version (-V)        Display this application version
 --ansi                Force ANSI output
 --no-ansi             Disable ANSI output
 --no-interaction (-n) Do not ask any interactive question
 --no-plugins          Disables all plugins.
 --profile             Display timing and memory usage information.
 --progress            Show progress bar.
 --output              Write results to file or URL.
 --manifest            Show which versions of dependencies are bundled.

Available commands:
 help                  Displays help for a command
 list                  Lists commands
analyser
 analyser:list         List all analysers available.
 analyser:run          Analyse a data source and display results.
cache
 cache:clear           Clear cache (any adapter and backend).
config
 config:validate       Validates a JSON configuration file.
diagnose
 diagnose:run          Diagnoses the system to identify common errors.
diagram
 diagram:class         Generates diagram about a user class present in a data source.
 diagram:package       Generates diagram about namespaces in a data source.
plugin
 plugin:list           List all plugins installed.
reflection
 reflection:class      Reports information about a user class present in a data source.
 reflection:function   Reports information about a user function present in a data source.

config:validate

Validates an optional JSON config file.

$ phpreflect config:validate
"/etc/phpreflect.json" config file is valid.

diagnose:run

Diagnoses the system to identify common errors.

$ phpreflect diagnose:run
Checking php settings:
- Requires PHP 5.3.2 or better OK
- php.ini file loaded C:\UwAmp\bin\php\php-5.6.7\php.ini
- date extension loaded YES
- json extension loaded YES
- pcre extension loaded YES
- phar extension loaded YES
- reflection extension loaded YES
- spl extension loaded YES
- tokenizer extension loaded YES
[Tip]

Use verbose level 2 for more details, and level 3 to get raw response

diagram:class

Generates diagram about a user class present in a data source.

$ phpreflect diagram:class Bartlett\Reflect\Plugin\LogPlugin ./src

diagram:package

Generates diagram about namespaces in a data source.

$ phpreflect diagram:package --engine=graphviz ./src

plugin:list

List all plugins configured (and correctly installed) in plugins section of your phpreflect.json config file.

Without plugins, you will get. 

$ phpreflect plugin:list

No plugin installed.

With only Cache plugin configured, you will get. 

$ phpreflect plugin:list

 Plugin Class                           Events Subscribed
 Bartlett\Reflect\Plugin\CachePlugin    reflect.progress
                                        reflect.success
                                        reflect.complete

analyser:list

List all analysers configured in analysers section of your phpreflect.json config file, and available by default.

With only default analysers, you will get. 

$ phpreflect analyser:list

 Analyser Name Analyser Class
 loc           Bartlett\Reflect\Analyser\LocAnalyser
 reflection    Bartlett\Reflect\Analyser\ReflectionAnalyser
 structure     Bartlett\Reflect\Analyser\StructureAnalyser

analyser:run

Parse a data source and display results. May vary depending of the data source and analyser used.

With structure analyser and the Reflect source code, you will get something like. 

$ phpreflect analyser:run .

Possible alternative (if you use the default json config file). 

$ phpreflect analyser:run --alias current

Data Source Analysed

Directories                                         20
Files                                               73

Structure
  Namespaces                                        20
  Interfaces                                         8
  Traits                                             0
  Classes                                           65
    Abstract Classes                                 6 (9.23%)
    Concrete Classes                                59 (90.77%)
  Methods                                          295
    Scope
      Non-Static Methods                           282 (95.59%)
      Static Methods                                13 (4.41%)
    Visibility
      Public Method                                251 (85.08%)
      Protected Method                              34 (11.53%)
      Private Method                                10 (3.39%)
  Functions                                         12
    Named Functions                                  0 (0.00%)
    Anonymous Functions                             12 (100.00%)
  Constants                                         22
    Global Constants                                 0 (0.00%)
    Magic Constants                                  3 (13.64%)
    Class Constants                                 19 (86.36%)
  Tests
    Classes                                          0
    Methods                                          0

reflection:class

Reports information about a user class present in a data source.

With the Reflect source code (./src), and Bartlett\Reflect class. 

$ phpreflect reflection:class Bartlett\Reflect ./src

Class [ <user> class Bartlett\Reflect extends Bartlett\Reflect\Event\AbstractDispatcher ] {
  @@ C:\home\github\php-reflect\src\Bartlett\Reflect.php 45 - 340

  - Constants [0] {
  }

  - Properties [2] {
    Property [ private $analysers ]
    Property [ private $dataSourceId ]
  }

  - Methods [6] {
    Method [ <user> public method __construct ] {
      @@ C:\home\github\php-reflect\src\Bartlett\Reflect.php 53 - 57

      - Parameters [0] {
      }
    }

    Method [ <user> public method addAnalyser ] {
      @@ C:\home\github\php-reflect\src\Bartlett\Reflect.php 66 - 71

      - Parameters [1] {
        Parameter #0 [ <required> PhpParser\NodeVisitor $analyser ]
      }
    }

    Method [ <user> public method getAnalysers ] {
      @@ C:\home\github\php-reflect\src\Bartlett\Reflect.php 78 - 81

      - Parameters [0] {
      }
    }

    Method [ <user> public method setDataSourceId ] {
      @@ C:\home\github\php-reflect\src\Bartlett\Reflect.php 90 - 94

      - Parameters [1] {
        Parameter #0 [ <required> $id ]
      }
    }

    Method [ <user> public method getDataSourceId ] {
      @@ C:\home\github\php-reflect\src\Bartlett\Reflect.php 101 - 104

      - Parameters [0] {
      }
    }

    Method [ <user> public method parse ] {
      @@ C:\home\github\php-reflect\src\Bartlett\Reflect.php 113 - 339

      - Parameters [1] {
        Parameter #0 [ <required> Symfony\Component\Finder\Finder $finder ]
      }
    }
  }
}