class GenerateMarkdownDoc extends BaseTask implements BuilderAwareInterface (View source)

Simple documentation generator from source files.

Takes classes, properties and methods with their docblocks and writes down a markdown file.

<?php
$this->taskGenDoc('models.md')
     ->docClass('Model\User') // take class Model\User
     ->docClass('Model\Post') // take class Model\Post
     ->filterMethods(function(\ReflectionMethod $r) {
         return $r->isPublic() or $r->isProtected(); // process public and protected methods
     })->processClass(function(\ReflectionClass $r, $text) {
         return "Class ".$r->getName()."\n\n$text\n\n###Methods\n";
     })->run();

By default this task generates a documentation for each public method of a class, interface or trait. It combines method signature with a docblock. Both can be post-processed.

<?php
$this->taskGenDoc('models.md')
     ->docClass('Model\User')
     ->processClassSignature(false) // false can be passed to not include class signature
     ->processClassDocBlock(function(\ReflectionClass $r, $text) {
         return "[This is part of application model]\n" . $text;
     })->processMethodSignature(function(\ReflectionMethod $r, $text) {
         return "#### {$r->name}()";
     })->processMethodDocBlock(function(\ReflectionMethod $r, $text) {
         return strpos($r->name, 'save')===0 ? "[Saves to the database]\n" . $text : $text;
     })->run();

Traits

Task input/output methods. TaskIO is 'used' in BaseTask, so any task that extends this class has access to all of the methods here.

Task input/output methods. TaskIO is 'used' in BaseTask, so any task that extends this class has access to all of the methods here.

LoggerAwareTrait

Properties

protected ConfigInterface $config from  ConfigAwareTrait
protected OutputAdapterInterface $outputAdapter from  VerbosityThresholdTrait
protected int $verbosityThreshold from  VerbosityThresholdTrait
protected OutputInterface $output from  OutputAwareTrait
protected TimeKeeper|null $timer from  Timer
protected null|ProgressIndicator $progressIndicator from  ProgressIndicatorAwareTrait
protected CollectionBuilder $builder from  BuilderAwareTrait
protected string[] $docClass
protected callable $filterMethods
protected callable $filterClasses
protected callable $filterProperties
protected callable $processClass
protected callable|false $processClassSignature
protected callable|false $processClassDocBlock
protected callable|false $processMethod
protected callable|false $processMethodSignature
protected callable|false $processMethodDocBlock
protected callable|false $processProperty
protected callable|false $processPropertySignature
protected callable|false $processPropertyDocBlock
protected callable $reorder
protected callable $reorderMethods
protected callable $reorderProperties
protected string $filename
protected string $prepend
protected string $append
protected string $text
protected string[] $textForClass

Methods

$this
setConfig(ConfigInterface $config)

Set the config management object.

ConfigInterface
getConfig()

Get the config management object.

static string
configPrefix()

Any class that uses ConfigAwareTrait SHOULD override this method , and define a prefix for its configuration items. This is usually done in a base class. When used, this method should return a string that ends with a "."; see BaseTask::configPrefix().

static 
configClassIdentifier($classname)

No description

static 
configPostfix()

No description

static 
configure(string $key, mixed $value, ConfigInterface|null $config = null)

No description

mixed|null
getConfigValue(string $key, mixed|null $default = null)

No description

$this
setVerbosityThreshold(int $verbosityThreshold)

Required verbosity level before any TaskIO output will be produced.

int
verbosityThreshold()

No description

bool
hasOutputAdapter()

No description

writeMessage(string $message)

Print a message if the selected verbosity level is over this task's verbosity threshold.

$this
setOutput(OutputInterface $output)

No description

OutputInterface
output()

No description

OutputInterface
stderr()

No description

OutputInterface
getOutput() deprecated

Backwards compatibility

null|LoggerInterface
logger() deprecated

No description

from  TaskIO
printTaskInfo(string $text, null|array $context = null)

Print information about a task in progress.

from  TaskIO
printTaskSuccess(string $text, null|array $context = null)

Provide notification that some part of the task succeeded.

from  TaskIO
printTaskWarning(string $text, null|array $context = null)

Provide notification that there is something wrong, but execution can continue.

from  TaskIO
printTaskError(string $text, null|array $context = null)

Provide notification that some operation in the task failed, and the task cannot continue.

from  TaskIO
printTaskDebug($text, null|array $context = null)

Provide debugging notification. These messages are only displayed if the log level is VERBOSITY_DEBUG.

from  TaskIO
printTaskOutput(string $level, string $text, null|array $context) deprecated

No description

from  TaskIO
bool
hideTaskProgress()

No description

from  TaskIO
showTaskProgress(bool $inProgress)

No description

from  TaskIO
string
formatBytes(int $size, int $precision = 2)

Format a quantity of bytes.

from  TaskIO
string
getPrintedTaskName(null|object $task = null)

Get the formatted task name for use in task output.

from  TaskIO
array
getTaskContext(null|array $context = null)

No description

from  TaskIO
startTimer()

No description

from  Timer
stopTimer()

No description

from  Timer
resetTimer()

No description

from  Timer
float|null
getExecutionTime()

No description

from  Timer
$this
setProgressIndicator(null|ProgressIndicator $progressIndicator)

No description

null|bool
hideProgressIndicator()

No description

restoreProgressIndicator(bool $visible)

No description

bool
inProgress()

No description

advanceProgressIndicator(int $steps = 1)

No description

$this
inflect(InflectionInterface|mixed $parent)

Ask the provided parent class to inject all of the dependencies that it has and we need.

injectDependencies(mixed $child)

Take all dependencies availble to this task and inject any that are needed into the provided task. The general pattern is that, for every FooAwareInterface that this class implements, it should test to see if the child also implements the same interface, and if so, should call $child->setFoo($this->foo).

from  BaseTask
$this
setBuilder(CollectionBuilder $builder)

No description

init(string $filename)

No description

__construct(string $filename)

No description

$this
docClass(string $item)

Put a class you want to be documented.

$this
filterMethods(callable $filterMethods)

Using a callback function filter out methods that won't be documented.

$this
filterClasses(callable $filterClasses)

Using a callback function filter out classes that won't be documented.

$this
filterProperties(callable $filterProperties)

Using a callback function filter out properties that won't be documented.

$this
processClass(callable $processClass)

Post-process class documentation.

$this
processClassSignature(callable|false $processClassSignature)

Post-process class signature. Provide false to skip.

$this
processClassDocBlock(callable|false $processClassDocBlock)

Post-process class docblock contents. Provide false to skip.

$this
processMethod(callable|false $processMethod)

Post-process method documentation. Provide false to skip.

$this
processMethodSignature(callable|false $processMethodSignature)

Post-process method signature. Provide false to skip.

$this
processMethodDocBlock(callable|false $processMethodDocBlock)

Post-process method docblock contents. Provide false to skip.

$this
processProperty(callable|false $processProperty)

Post-process property documentation. Provide false to skip.

$this
processPropertySignature(callable|false $processPropertySignature)

Post-process property signature. Provide false to skip.

$this
processPropertyDocBlock(callable|false $processPropertyDocBlock)

Post-process property docblock contents. Provide false to skip.

$this
reorder(callable $reorder)

Use a function to reorder classes.

$this
reorderMethods(callable $reorderMethods)

Use a function to reorder methods in class.

$this
reorderProperties(callable $reorderProperties)

No description

$this
filename(string $filename)

No description

$this
prepend(string $prepend)

Inserts text at the beginning of markdown file.

$this
append(string $append)

Inserts text at the end of markdown file.

$this
text(string $text)

No description

$this
textForClass(string $item)

No description

run()

No description

null|string
documentClass(string $class)

No description

string
documentClassSignature(ReflectionClass $reflectionClass)

No description

string
documentClassDocBlock(ReflectionClass $reflectionClass)

No description

string
documentMethod(ReflectionMethod $reflectedMethod)

No description

string
documentProperty(ReflectionProperty $reflectedProperty)

No description

string
documentPropertySignature(ReflectionProperty $reflectedProperty)

No description

string
documentPropertyDocBlock(ReflectionProperty $reflectedProperty)

No description

string
documentParam(ReflectionParameter $param)

No description

static string
indentDoc(string $doc, int $indent = 3)

No description

string
documentMethodSignature(ReflectionMethod $reflectedMethod)

No description

string
documentMethodDocBlock(ReflectionMethod $reflectedMethod)

No description

string
documentMethodParametersAndReturnType(ReflectionMethod $method, string $text)

No description

static string
stringifyNamedType(ReflectionNamedType $type, ReflectionClass $moduleClass)

No description

Details

$this setConfig(ConfigInterface $config)

Set the config management object.

Parameters

ConfigInterface $config

Return Value

$this

ConfigInterface getConfig()

Get the config management object.

Return Value

ConfigInterface

static protected string configPrefix()

Any class that uses ConfigAwareTrait SHOULD override this method , and define a prefix for its configuration items. This is usually done in a base class. When used, this method should return a string that ends with a "."; see BaseTask::configPrefix().

Return Value

string

static protected configClassIdentifier($classname)

No description

Parameters

$classname

static protected configPostfix()

No description

static configure(string $key, mixed $value, ConfigInterface|null $config = null)

No description

Parameters

string $key
mixed $value
ConfigInterface|null $config

protected mixed|null getConfigValue(string $key, mixed|null $default = null)

No description

Parameters

string $key
mixed|null $default

Return Value

mixed|null

$this setVerbosityThreshold(int $verbosityThreshold)

Required verbosity level before any TaskIO output will be produced.

e.g. OutputInterface::VERBOSITY_VERBOSE

Parameters

int $verbosityThreshold

Return Value

$this

int verbosityThreshold()

No description

Return Value

int

setOutputAdapter(OutputAdapterInterface $outputAdapter)

No description

Parameters

OutputAdapterInterface $outputAdapter

bool hasOutputAdapter()

No description

Return Value

bool

bool verbosityMeetsThreshold()

No description

Return Value

bool

writeMessage(string $message)

Print a message if the selected verbosity level is over this task's verbosity threshold.

Parameters

string $message

$this setOutput(OutputInterface $output)

No description

Parameters

OutputInterface $output

Return Value

$this

See also

\Robo\Contract\OutputAwareInterface::setOutput()

protected OutputInterface output()

No description

Return Value

OutputInterface

protected OutputInterface stderr()

No description

Return Value

OutputInterface

protected OutputInterface getOutput() deprecated

deprecated

Backwards compatibility

Return Value

OutputInterface

null|LoggerInterface logger() deprecated

deprecated

No description

Return Value

null|LoggerInterface

protected printTaskInfo(string $text, null|array $context = null)

Print information about a task in progress.

With the Symfony Console logger, NOTICE is displayed at VERBOSITY_VERBOSE and INFO is displayed at VERBOSITY_VERY_VERBOSE.

Robo overrides the default such that NOTICE is displayed at VERBOSITY_NORMAL and INFO is displayed at VERBOSITY_VERBOSE.

n.b. We should probably have printTaskNotice for our ordinary output, and use printTaskInfo for less interesting messages.

Parameters

string $text
null|array $context

protected printTaskSuccess(string $text, null|array $context = null)

Provide notification that some part of the task succeeded.

With the Symfony Console logger, success messages are remapped to NOTICE, and displayed in VERBOSITY_VERBOSE. When used with the Robo logger, success messages are displayed at VERBOSITY_NORMAL.

Parameters

string $text
null|array $context

protected printTaskWarning(string $text, null|array $context = null)

Provide notification that there is something wrong, but execution can continue.

Warning messages are displayed at VERBOSITY_NORMAL.

Parameters

string $text
null|array $context

protected printTaskError(string $text, null|array $context = null)

Provide notification that some operation in the task failed, and the task cannot continue.

Error messages are displayed at VERBOSITY_NORMAL.

Parameters

string $text
null|array $context

protected printTaskDebug($text, null|array $context = null)

Provide debugging notification. These messages are only displayed if the log level is VERBOSITY_DEBUG.

Parameters

$text
null|array $context

protected printTaskOutput(string $level, string $text, null|array $context) deprecated

deprecated

No description

Parameters

string $level

One of the \Psr\Log\LogLevel constant

string $text
null|array $context

protected bool hideTaskProgress()

No description

Return Value

bool

protected showTaskProgress(bool $inProgress)

No description

Parameters

bool $inProgress

protected string formatBytes(int $size, int $precision = 2)

Format a quantity of bytes.

Parameters

int $size
int $precision

Return Value

string

protected string getPrintedTaskName(null|object $task = null)

Get the formatted task name for use in task output.

This is placed in the task context under 'name', and used as the log label by Robo\Common\RoboLogStyle, which is inserted at the head of log messages by Robo\Common\CustomLogStyle::formatMessage().

Parameters

null|object $task

Return Value

string

protected array getTaskContext(null|array $context = null)

No description

Parameters

null|array $context

Return Value

array

Context information.

protected startTimer()

No description

protected stopTimer()

No description

protected resetTimer()

No description

protected float|null getExecutionTime()

No description

Return Value

float|null

int progressIndicatorSteps()

No description

Return Value

int

$this setProgressIndicator(null|ProgressIndicator $progressIndicator)

No description

Parameters

null|ProgressIndicator $progressIndicator

Return Value

$this

protected null|bool hideProgressIndicator()

No description

Return Value

null|bool

protected showProgressIndicator()

No description

protected restoreProgressIndicator(bool $visible)

No description

Parameters

bool $visible

protected int getTotalExecutionTime()

No description

Return Value

int

protected startProgressIndicator()

No description

protected bool inProgress()

No description

Return Value

bool

protected stopProgressIndicator()

No description

protected disableProgressIndicator()

No description

protected detatchProgressIndicator()

No description

protected advanceProgressIndicator(int $steps = 1)

No description

Parameters

int $steps

$this inflect(InflectionInterface|mixed $parent)

Ask the provided parent class to inject all of the dependencies that it has and we need.

Parameters

InflectionInterface|mixed $parent

Return Value

$this

injectDependencies(mixed $child)

Take all dependencies availble to this task and inject any that are needed into the provided task. The general pattern is that, for every FooAwareInterface that this class implements, it should test to see if the child also implements the same interface, and if so, should call $child->setFoo($this->foo).

The benefits of this are pretty large. Any time an object that implements InflectionInterface is created, just call $child->inflect($this), and any available optional dependencies will be hooked up via setter injection.

The required dependencies of an object should be provided via constructor injection, not inflection.

Parameters

mixed $child

An object with one or more *AwareInterfaces implemented.

$this setBuilder(CollectionBuilder $builder)

No description

Parameters

CollectionBuilder $builder

Return Value

$this

See also

BuilderAwareInterface::setBuilder

protected CollectionBuilder collectionBuilder(ConsoleIO $io = null)

No description

Parameters

ConsoleIO $io

Return Value

CollectionBuilder

static GenerateMarkdownDoc init(string $filename)

No description

Parameters

string $filename

Return Value

GenerateMarkdownDoc

__construct(string $filename)

No description

Parameters

string $filename

$this docClass(string $item)

Put a class you want to be documented.

Parameters

string $item

Return Value

$this

$this filterMethods(callable $filterMethods)

Using a callback function filter out methods that won't be documented.

Parameters

callable $filterMethods

Return Value

$this

$this filterClasses(callable $filterClasses)

Using a callback function filter out classes that won't be documented.

Parameters

callable $filterClasses

Return Value

$this

$this filterProperties(callable $filterProperties)

Using a callback function filter out properties that won't be documented.

Parameters

callable $filterProperties

Return Value

$this

$this processClass(callable $processClass)

Post-process class documentation.

Parameters

callable $processClass

Return Value

$this

$this processClassSignature(callable|false $processClassSignature)

Post-process class signature. Provide false to skip.

Parameters

callable|false $processClassSignature

Return Value

$this

$this processClassDocBlock(callable|false $processClassDocBlock)

Post-process class docblock contents. Provide false to skip.

Parameters

callable|false $processClassDocBlock

Return Value

$this

$this processMethod(callable|false $processMethod)

Post-process method documentation. Provide false to skip.

Parameters

callable|false $processMethod

Return Value

$this

$this processMethodSignature(callable|false $processMethodSignature)

Post-process method signature. Provide false to skip.

Parameters

callable|false $processMethodSignature

Return Value

$this

$this processMethodDocBlock(callable|false $processMethodDocBlock)

Post-process method docblock contents. Provide false to skip.

Parameters

callable|false $processMethodDocBlock

Return Value

$this

$this processProperty(callable|false $processProperty)

Post-process property documentation. Provide false to skip.

Parameters

callable|false $processProperty

Return Value

$this

$this processPropertySignature(callable|false $processPropertySignature)

Post-process property signature. Provide false to skip.

Parameters

callable|false $processPropertySignature

Return Value

$this

$this processPropertyDocBlock(callable|false $processPropertyDocBlock)

Post-process property docblock contents. Provide false to skip.

Parameters

callable|false $processPropertyDocBlock

Return Value

$this

$this reorder(callable $reorder)

Use a function to reorder classes.

Parameters

callable $reorder

Return Value

$this

$this reorderMethods(callable $reorderMethods)

Use a function to reorder methods in class.

Parameters

callable $reorderMethods

Return Value

$this

$this reorderProperties(callable $reorderProperties)

No description

Parameters

callable $reorderProperties

Return Value

$this

$this filename(string $filename)

No description

Parameters

string $filename

Return Value

$this

$this prepend(string $prepend)

Inserts text at the beginning of markdown file.

Parameters

string $prepend

Return Value

$this

$this append(string $append)

Inserts text at the end of markdown file.

Parameters

string $append

Return Value

$this

$this text(string $text)

No description

Parameters

string $text

Return Value

$this

$this textForClass(string $item)

No description

Parameters

string $item

Return Value

$this

Result run()

No description

Return Value

Result

protected null|string documentClass(string $class)

No description

Parameters

string $class

Return Value

null|string

protected string documentClassSignature(ReflectionClass $reflectionClass)

No description

Parameters

ReflectionClass $reflectionClass

Return Value

string

protected string documentClassDocBlock(ReflectionClass $reflectionClass)

No description

Parameters

ReflectionClass $reflectionClass

Return Value

string

protected string documentMethod(ReflectionMethod $reflectedMethod)

No description

Parameters

ReflectionMethod $reflectedMethod

Return Value

string

protected string documentProperty(ReflectionProperty $reflectedProperty)

No description

Parameters

ReflectionProperty $reflectedProperty

Return Value

string

protected string documentPropertySignature(ReflectionProperty $reflectedProperty)

No description

Parameters

ReflectionProperty $reflectedProperty

Return Value

string

protected string documentPropertyDocBlock(ReflectionProperty $reflectedProperty)

No description

Parameters

ReflectionProperty $reflectedProperty

Return Value

string

protected string documentParam(ReflectionParameter $param)

No description

Parameters

ReflectionParameter $param

Return Value

string

static string indentDoc(string $doc, int $indent = 3)

No description

Parameters

string $doc
int $indent

Return Value

string

protected string documentMethodSignature(ReflectionMethod $reflectedMethod)

No description

Parameters

ReflectionMethod $reflectedMethod

Return Value

string

protected string documentMethodDocBlock(ReflectionMethod $reflectedMethod)

No description

Parameters

ReflectionMethod $reflectedMethod

Return Value

string

protected string documentMethodParametersAndReturnType(ReflectionMethod $method, string $text)

No description

Parameters

ReflectionMethod $method
string $text

Return Value

string

static string stringifyNamedType(ReflectionNamedType $type, ReflectionClass $moduleClass)

No description

Parameters

ReflectionNamedType $type
ReflectionClass $moduleClass

Return Value

string