Skip to content
This repository has been archived by the owner on Sep 24, 2020. It is now read-only.

Commit

Permalink
Merge pull request #258 from ddmler/missing-docblock-config
Browse files Browse the repository at this point in the history
Give some analyzers more configs
  • Loading branch information
ovr authored Nov 6, 2016
2 parents ac2f154 + 6f14853 commit 7c55c5f
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 13 deletions.
7 changes: 7 additions & 0 deletions .phpsa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ phpsa:
# Checks for a missing docblock for: class, property, class constant, trait, interface, class method, function.
missing_docblock:
enabled: true
class: true
class_method: true
class_const: true
class_property: true
function: true
interface: true
trait: true

# Checks for use of PHP 4 constructors and discourages it.
old_constructor:
Expand Down
2 changes: 1 addition & 1 deletion src/Analyzer/Pass/Metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static function create($name, $description = null)
* @param null $description
* @param NodeDefinition|null $config
*/
private function __construct($name, NodeDefinition $config, $description = null)
public function __construct($name, NodeDefinition $config, $description = null)
{
$this->name = $name;
$this->configuration = $config;
Expand Down
70 changes: 58 additions & 12 deletions src/Analyzer/Pass/Statement/MissingDocblock.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,48 @@
namespace PHPSA\Analyzer\Pass\Statement;

use PhpParser\Node\Stmt;
use PHPSA\Analyzer\Helper\DefaultMetadataPassTrait;
use PHPSA\Analyzer\Pass\AnalyzerPassInterface;
use PHPSA\Context;
use PHPSA\Analyzer\Pass\Metadata;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;

class MissingDocblock implements AnalyzerPassInterface
{
use DefaultMetadataPassTrait;

const DESCRIPTION = 'Checks for a missing docblock for: class, property, class constant, trait, interface, class method, function.';

/**
* Contains the Nodes that are registered
*/
public $register = [];

/**
* @param array $config The config values for the analyzer
*/
public function __construct(array $config)
{
if ($config["class"] == true) {
$this->register[] = Stmt\Class_::class;
}
if ($config["class_method"] == true) {
$this->register[] = Stmt\ClassMethod::class;
}
if ($config["class_const"] == true) {
$this->register[] = Stmt\ClassConst::class;
}
if ($config["class_property"] == true) {
$this->register[] = Stmt\Property::class;
}
if ($config["function"] == true) {
$this->register[] = Stmt\Function_::class;
}
if ($config["interface"] == true) {
$this->register[] = Stmt\Interface_::class;
}
if ($config["trait"] == true) {
$this->register[] = Stmt\Trait_::class;
}
}

/**
* @param Stmt $stmt
* @param Context $context
Expand All @@ -38,14 +70,28 @@ public function pass(Stmt $stmt, Context $context)
*/
public function getRegister()
{
return [
Stmt\Class_::class,
Stmt\ClassMethod::class,
Stmt\Property::class,
Stmt\Function_::class,
Stmt\Trait_::class,
Stmt\Interface_::class,
Stmt\ClassConst::class,
];
return $this->register;
}

/**
* @return Metadata
*/
public static function getMetadata()
{
$treebuilder = new TreeBuilder();
$config = $treebuilder->root("missing_docblock")
->info(self::DESCRIPTION)
->canBeDisabled()
->children()
->booleanNode("class")->defaultTrue()->end()
->booleanNode("class_method")->defaultTrue()->end()
->booleanNode("class_const")->defaultTrue()->end()
->booleanNode("class_property")->defaultTrue()->end()
->booleanNode("function")->defaultTrue()->end()
->booleanNode("interface")->defaultTrue()->end()
->booleanNode("trait")->defaultTrue()->end()
->end();

return new Metadata("missing_docblock", $config, self::DESCRIPTION);
}
}

0 comments on commit 7c55c5f

Please sign in to comment.