Basic or Complex Strategy to identify the Data Source.
![]() | |
Now, and for the following chapters, we will not mention how you load the classes. Depending of the install strategy you’ve adopted, Composer or other, don’t forget to load your autoloader. |
Compare to version 2, Reflect 3 offers two simple strategies to identify the data source.
First, is to give the relative or absolute path to file or directory to parse (without limitation).
Second, is to specify options to customize parsing process, to the Symfony Finder Component.
With all SAPI, no JSON config file is required (as it was for Reflect 2). You have just to give the relative or absolute path to file or directory to parse.
It’s also possible to specify any archive (phar, zip, tar, tgz, gz, rar) as file source.
Example with a simple file or directory (absolute path).
$ phpreflect analyser:run /absolute/path/to/source
Example with a simple file or directory (relative path).
$ phpreflect analyser:run ./relative/path/to/source
Still as it was with Reflect 2, you will need to configure your data source in a JSON file.
Syntax is closed to the Symfony Finder Component that is used to limit data source contents to parse.
Example to parse an archive.
{ "source-providers": [ { "in": "phar:///var/dist/owncloud-7.0.2.tar as owncloud7", "name": "*.php", "exclude": ["3rdparty"] } ], "plugins": [ ], "analysers" : [ ] }
![]() | |
Do not forget the |
![]() | |
Use alias named here |
Example to parse a directory.
{ "source-providers": [ { "in": "/home/github/phing/ as phing2", "path": ["bin", "classes"], "exclude": ["test"], "name": "*.php" } ], "plugins": [ ], "analysers" : [ ] }
Learn more about directives, see Section 8.1, “section Source Providers”
Whatever SAPI you use, all metrics (for each analysers asked) are available at end of parse, in the same format.
With CLI, and Reflect source code, to get a structure report, you have to invoke the following command :
$ phpreflect analyser:run /home/github/php-reflect/src
With others SAPI, use example https://raw.githubusercontent.com/llaville/php-reflect/master/examples/api_analyser_run.php
and you should obtain something like this :
Data Source Analysed Directories 22 Files 77 Structure Namespaces 22 Interfaces 10 Traits 0 Classes 67 Abstract Classes 8 (11.94%) Concrete Classes 59 (88.06%) Methods 312 Scope Non-Static Methods 299 (95.83%) Static Methods 13 (4.17%) Visibility Public Method 268 (85.90%) Protected Method 35 (11.22%) Private Method 9 (2.88%) Functions 11 Named Functions 0 (0.00%) Anonymous Functions 11 (100.00%) Constants 21 Global Constants 0 (0.00%) Magic Constants 3 (14.29%) Class Constants 18 (85.71%) Tests Classes 0 Methods 0
This is the default render. But, if you want to compare with other SAPI,
activate the debug verbose mode (-vvv
) to get the raw response.
You should obtain something like this :
Array ( [files] => Array ( [0] => /home/github/php-reflect/src/Bartlett/Reflect/Analyser/AbstractAnalyser.php [1] => /home/github/php-reflect/src/Bartlett/Reflect/Analyser/AbstractSniffAnalyser.php [2] => /home/github/php-reflect/src/Bartlett/Reflect/Analyser/AnalyserInterface.php [3] => /home/github/php-reflect/src/Bartlett/Reflect/Analyser/AnalyserManager.php [4] => /home/github/php-reflect/src/Bartlett/Reflect/Analyser/LocAnalyser.php [5] => /home/github/php-reflect/src/Bartlett/Reflect/Analyser/ReflectionAnalyser.php [6] => /home/github/php-reflect/src/Bartlett/Reflect/Analyser/StructureAnalyser.php [7] => /home/github/php-reflect/src/Bartlett/Reflect/Api/Analyser.php [8] => /home/github/php-reflect/src/Bartlett/Reflect/Api/BaseApi.php [9] => /home/github/php-reflect/src/Bartlett/Reflect/Api/Cache.php [10] => /home/github/php-reflect/src/Bartlett/Reflect/Api/Config.php [11] => /home/github/php-reflect/src/Bartlett/Reflect/Api/Diagnose.php [12] => /home/github/php-reflect/src/Bartlett/Reflect/Api/Diagram.php [13] => /home/github/php-reflect/src/Bartlett/Reflect/Api/Plugin.php [14] => /home/github/php-reflect/src/Bartlett/Reflect/Api/Reflection.php [15] => /home/github/php-reflect/src/Bartlett/Reflect/Api/V3/Analyser.php [16] => /home/github/php-reflect/src/Bartlett/Reflect/Api/V3/Cache.php [17] => /home/github/php-reflect/src/Bartlett/Reflect/Api/V3/Common.php [18] => /home/github/php-reflect/src/Bartlett/Reflect/Api/V3/Config.php [19] => /home/github/php-reflect/src/Bartlett/Reflect/Api/V3/Diagnose.php [20] => /home/github/php-reflect/src/Bartlett/Reflect/Api/V3/Diagram.php [21] => /home/github/php-reflect/src/Bartlett/Reflect/Api/V3/Plugin.php [22] => /home/github/php-reflect/src/Bartlett/Reflect/Api/V3/Reflection.php [23] => /home/github/php-reflect/src/Bartlett/Reflect/Client/ClientInterface.php [24] => /home/github/php-reflect/src/Bartlett/Reflect/Client/LocalClient.php [25] => /home/github/php-reflect/src/Bartlett/Reflect/Client.php [26] => /home/github/php-reflect/src/Bartlett/Reflect/Collection/ReflectionCollection.php [27] => /home/github/php-reflect/src/Bartlett/Reflect/Console/Application.php [28] => /home/github/php-reflect/src/Bartlett/Reflect/Console/Command.php [29] => /home/github/php-reflect/src/Bartlett/Reflect/Console/CommandFactory.php [30] => /home/github/php-reflect/src/Bartlett/Reflect/Console/Formatter/LocOutputFormatter.php [31] => /home/github/php-reflect/src/Bartlett/Reflect/Console/Formatter/OutputFormatter.php [32] => /home/github/php-reflect/src/Bartlett/Reflect/Console/Formatter/StructureOutputFormatter.php [33] => /home/github/php-reflect/src/Bartlett/Reflect/Environment.php [34] => /home/github/php-reflect/src/Bartlett/Reflect/Event/AbstractDispatcher.php [35] => /home/github/php-reflect/src/Bartlett/Reflect/Event/CacheAwareEventDispatcher.php [36] => /home/github/php-reflect/src/Bartlett/Reflect/Event/DispatcherInterface.php [37] => /home/github/php-reflect/src/Bartlett/Reflect/Events.php [38] => /home/github/php-reflect/src/Bartlett/Reflect/Exception/Exception.php [39] => /home/github/php-reflect/src/Bartlett/Reflect/Exception/ModelException.php [40] => /home/github/php-reflect/src/Bartlett/Reflect/Model/AbstractFunctionModel.php [41] => /home/github/php-reflect/src/Bartlett/Reflect/Model/AbstractModel.php [42] => /home/github/php-reflect/src/Bartlett/Reflect/Model/ClassModel.php [43] => /home/github/php-reflect/src/Bartlett/Reflect/Model/ConstantModel.php [44] => /home/github/php-reflect/src/Bartlett/Reflect/Model/FunctionModel.php [45] => /home/github/php-reflect/src/Bartlett/Reflect/Model/MethodModel.php [46] => /home/github/php-reflect/src/Bartlett/Reflect/Model/ParameterModel.php [47] => /home/github/php-reflect/src/Bartlett/Reflect/Model/PropertyModel.php [48] => /home/github/php-reflect/src/Bartlett/Reflect/MonologConsoleLogger.php [49] => /home/github/php-reflect/src/Bartlett/Reflect/Output/Analyser.php [50] => /home/github/php-reflect/src/Bartlett/Reflect/Output/Cache.php [51] => /home/github/php-reflect/src/Bartlett/Reflect/Output/Config.php [52] => /home/github/php-reflect/src/Bartlett/Reflect/Output/Diagnose.php [53] => /home/github/php-reflect/src/Bartlett/Reflect/Output/Diagram.php [54] => /home/github/php-reflect/src/Bartlett/Reflect/Output/Plugin.php [55] => /home/github/php-reflect/src/Bartlett/Reflect/Output/Reflection.php [56] => /home/github/php-reflect/src/Bartlett/Reflect/PhpParser/NodeProcessor.php [57] => /home/github/php-reflect/src/Bartlett/Reflect/PhpParser/NodeProcessorAbstract.php [58] => /home/github/php-reflect/src/Bartlett/Reflect/Plugin/Cache/CacheAdapterInterface.php [59] => /home/github/php-reflect/src/Bartlett/Reflect/Plugin/Cache/CacheStorageInterface.php [60] => /home/github/php-reflect/src/Bartlett/Reflect/Plugin/Cache/DefaultCacheStorage.php [61] => /home/github/php-reflect/src/Bartlett/Reflect/Plugin/Cache/DoctrineCacheAdapter.php [62] => /home/github/php-reflect/src/Bartlett/Reflect/Plugin/CachePlugin.php [63] => /home/github/php-reflect/src/Bartlett/Reflect/Plugin/Log/DefaultLogger.php [64] => /home/github/php-reflect/src/Bartlett/Reflect/Plugin/LogPlugin.php [65] => /home/github/php-reflect/src/Bartlett/Reflect/Plugin/Notifier/GrowlNotifier.php [66] => /home/github/php-reflect/src/Bartlett/Reflect/Plugin/Notifier/NotifierInterface.php [67] => /home/github/php-reflect/src/Bartlett/Reflect/Plugin/NotifierPlugin.php [68] => /home/github/php-reflect/src/Bartlett/Reflect/Plugin/PluginInterface.php [69] => /home/github/php-reflect/src/Bartlett/Reflect/Plugin/PluginManager.php [70] => /home/github/php-reflect/src/Bartlett/Reflect/Plugin/ProfilerPlugin.php [71] => /home/github/php-reflect/src/Bartlett/Reflect/Sniffer/SniffAbstract.php [72] => /home/github/php-reflect/src/Bartlett/Reflect/Sniffer/SniffInterface.php [73] => /home/github/php-reflect/src/Bartlett/Reflect/Tokenizer/DefaultTokenizer.php [74] => /home/github/php-reflect/src/Bartlett/Reflect/Util/Timer.php [75] => /home/github/php-reflect/src/Bartlett/Reflect/Visitor/VisitorInterface.php [76] => /home/github/php-reflect/src/Bartlett/Reflect.php ) [Bartlett\Reflect\Analyser\StructureAnalyser] => Array ( [namespaces] => 22 [interfaces] => 10 [traits] => 0 [classes] => 67 [abstractClasses] => 8 [concreteClasses] => 59 [functions] => 11 [namedFunctions] => 0 [anonymousFunctions] => 11 [methods] => 312 [publicMethods] => 268 [protectedMethods] => 35 [privateMethods] => 9 [nonStaticMethods] => 299 [staticMethods] => 13 [constants] => 0 [classConstants] => 18 [globalConstants] => 0 [magicConstants] => 3 [testClasses] => 0 [testMethods] => 0 ) )
files
structure
analyser result
Each analyser as its own data structure and results, but you will always get the fully qualified class name that identify origin of analyser used.
Example with two analysers (structure
and loc
).
$ phpreflect analyser:run /home/github/php-reflect/src structure loc
Raw response Array ( [files] => Array ( ... ) [Bartlett\Reflect\Analyser\StructureAnalyser] => Array ( ... ) Array ( [files] => Array ( [0] => /home/github/php-reflect/src/Bartlett/Reflect/Analyser/AbstractAnalyser.php [1] => /home/github/php-reflect/src/Bartlett/Reflect/Analyser/AbstractSniffAnalyser.php [2] => /home/github/php-reflect/src/Bartlett/Reflect/Analyser/AnalyserInterface.php [3] => /home/github/php-reflect/src/Bartlett/Reflect/Analyser/AnalyserManager.php [4] => /home/github/php-reflect/src/Bartlett/Reflect/Analyser/LocAnalyser.php [5] => /home/github/php-reflect/src/Bartlett/Reflect/Analyser/ReflectionAnalyser.php [6] => /home/github/php-reflect/src/Bartlett/Reflect/Analyser/StructureAnalyser.php [7] => /home/github/php-reflect/src/Bartlett/Reflect/Api/Analyser.php [8] => /home/github/php-reflect/src/Bartlett/Reflect/Api/BaseApi.php [9] => /home/github/php-reflect/src/Bartlett/Reflect/Api/Cache.php [10] => /home/github/php-reflect/src/Bartlett/Reflect/Api/Config.php [11] => /home/github/php-reflect/src/Bartlett/Reflect/Api/Diagnose.php [12] => /home/github/php-reflect/src/Bartlett/Reflect/Api/Diagram.php [13] => /home/github/php-reflect/src/Bartlett/Reflect/Api/Plugin.php [14] => /home/github/php-reflect/src/Bartlett/Reflect/Api/Reflection.php [15] => /home/github/php-reflect/src/Bartlett/Reflect/Api/V3/Analyser.php [16] => /home/github/php-reflect/src/Bartlett/Reflect/Api/V3/Cache.php [17] => /home/github/php-reflect/src/Bartlett/Reflect/Api/V3/Common.php [18] => /home/github/php-reflect/src/Bartlett/Reflect/Api/V3/Config.php [19] => /home/github/php-reflect/src/Bartlett/Reflect/Api/V3/Diagnose.php [20] => /home/github/php-reflect/src/Bartlett/Reflect/Api/V3/Diagram.php [21] => /home/github/php-reflect/src/Bartlett/Reflect/Api/V3/Plugin.php [22] => /home/github/php-reflect/src/Bartlett/Reflect/Api/V3/Reflection.php [23] => /home/github/php-reflect/src/Bartlett/Reflect/Client/ClientInterface.php [24] => /home/github/php-reflect/src/Bartlett/Reflect/Client/LocalClient.php [25] => /home/github/php-reflect/src/Bartlett/Reflect/Client.php [26] => /home/github/php-reflect/src/Bartlett/Reflect/Collection/ReflectionCollection.php [27] => /home/github/php-reflect/src/Bartlett/Reflect/Console/Application.php [28] => /home/github/php-reflect/src/Bartlett/Reflect/Console/Command.php [29] => /home/github/php-reflect/src/Bartlett/Reflect/Console/CommandFactory.php [30] => /home/github/php-reflect/src/Bartlett/Reflect/Console/Formatter/LocOutputFormatter.php [31] => /home/github/php-reflect/src/Bartlett/Reflect/Console/Formatter/OutputFormatter.php [32] => /home/github/php-reflect/src/Bartlett/Reflect/Console/Formatter/StructureOutputFormatter.php [33] => /home/github/php-reflect/src/Bartlett/Reflect/Environment.php [34] => /home/github/php-reflect/src/Bartlett/Reflect/Event/AbstractDispatcher.php [35] => /home/github/php-reflect/src/Bartlett/Reflect/Event/CacheAwareEventDispatcher.php [36] => /home/github/php-reflect/src/Bartlett/Reflect/Event/DispatcherInterface.php [37] => /home/github/php-reflect/src/Bartlett/Reflect/Events.php [38] => /home/github/php-reflect/src/Bartlett/Reflect/Exception/Exception.php [39] => /home/github/php-reflect/src/Bartlett/Reflect/Exception/ModelException.php [40] => /home/github/php-reflect/src/Bartlett/Reflect/Model/AbstractFunctionModel.php [41] => /home/github/php-reflect/src/Bartlett/Reflect/Model/AbstractModel.php [42] => /home/github/php-reflect/src/Bartlett/Reflect/Model/ClassModel.php [43] => /home/github/php-reflect/src/Bartlett/Reflect/Model/ConstantModel.php [44] => /home/github/php-reflect/src/Bartlett/Reflect/Model/FunctionModel.php [45] => /home/github/php-reflect/src/Bartlett/Reflect/Model/MethodModel.php [46] => /home/github/php-reflect/src/Bartlett/Reflect/Model/ParameterModel.php [47] => /home/github/php-reflect/src/Bartlett/Reflect/Model/PropertyModel.php [48] => /home/github/php-reflect/src/Bartlett/Reflect/MonologConsoleLogger.php [49] => /home/github/php-reflect/src/Bartlett/Reflect/Output/Analyser.php [50] => /home/github/php-reflect/src/Bartlett/Reflect/Output/Cache.php [51] => /home/github/php-reflect/src/Bartlett/Reflect/Output/Config.php [52] => /home/github/php-reflect/src/Bartlett/Reflect/Output/Diagnose.php [53] => /home/github/php-reflect/src/Bartlett/Reflect/Output/Diagram.php [54] => /home/github/php-reflect/src/Bartlett/Reflect/Output/Plugin.php [55] => /home/github/php-reflect/src/Bartlett/Reflect/Output/Reflection.php [56] => /home/github/php-reflect/src/Bartlett/Reflect/PhpParser/NodeProcessor.php [57] => /home/github/php-reflect/src/Bartlett/Reflect/PhpParser/NodeProcessorAbstract.php [58] => /home/github/php-reflect/src/Bartlett/Reflect/Plugin/Cache/CacheAdapterInterface.php [59] => /home/github/php-reflect/src/Bartlett/Reflect/Plugin/Cache/CacheStorageInterface.php [60] => /home/github/php-reflect/src/Bartlett/Reflect/Plugin/Cache/DefaultCacheStorage.php [61] => /home/github/php-reflect/src/Bartlett/Reflect/Plugin/Cache/DoctrineCacheAdapter.php [62] => /home/github/php-reflect/src/Bartlett/Reflect/Plugin/CachePlugin.php [63] => /home/github/php-reflect/src/Bartlett/Reflect/Plugin/Log/DefaultLogger.php [64] => /home/github/php-reflect/src/Bartlett/Reflect/Plugin/LogPlugin.php [65] => /home/github/php-reflect/src/Bartlett/Reflect/Plugin/Notifier/GrowlNotifier.php [66] => /home/github/php-reflect/src/Bartlett/Reflect/Plugin/Notifier/NotifierInterface.php [67] => /home/github/php-reflect/src/Bartlett/Reflect/Plugin/NotifierPlugin.php [68] => /home/github/php-reflect/src/Bartlett/Reflect/Plugin/PluginInterface.php [69] => /home/github/php-reflect/src/Bartlett/Reflect/Plugin/PluginManager.php [70] => /home/github/php-reflect/src/Bartlett/Reflect/Plugin/ProfilerPlugin.php [71] => /home/github/php-reflect/src/Bartlett/Reflect/Sniffer/SniffAbstract.php [72] => /home/github/php-reflect/src/Bartlett/Reflect/Sniffer/SniffInterface.php [73] => /home/github/php-reflect/src/Bartlett/Reflect/Tokenizer/DefaultTokenizer.php [74] => /home/github/php-reflect/src/Bartlett/Reflect/Util/Timer.php [75] => /home/github/php-reflect/src/Bartlett/Reflect/Visitor/VisitorInterface.php [76] => /home/github/php-reflect/src/Bartlett/Reflect.php ) [Bartlett\Reflect\Analyser\LocAnalyser] => Array ( [llocClasses] => 1142 [llocByNoc] => 0 [llocByNom] => 0 [llocFunctions] => 68 [llocByNof] => 0 [llocGlobal] => 0 [classes] => 67 [functions] => 11 [methods] => 350 [cloc] => 137 [eloc] => 3293 [lloc] => 1210 [wloc] => 402 [loc] => 3832 [ccn] => 647 [ccnMethods] => 607 ) ) )