1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Fix update-docblocks command

This commit is contained in:
Matt Brown 2017-01-13 14:06:05 -05:00
parent fda96660fe
commit 93688dffe0
4 changed files with 28 additions and 23 deletions

View File

@ -128,7 +128,7 @@ if ($path_to_config) {
ProjectChecker::setConfigXML($path_to_config); ProjectChecker::setConfigXML($path_to_config);
} }
$project_checker = new ProjectChecker($use_color, $show_info, $output_format, $debug); $project_checker = new ProjectChecker($use_color, $show_info, $output_format, $debug, $update_docblocks);
\Psalm\IssueBuffer::setStartTime(microtime(true)); \Psalm\IssueBuffer::setStartTime(microtime(true));
@ -139,9 +139,9 @@ if (array_key_exists('self-check', $options)) {
} elseif ($paths_to_check) { } elseif ($paths_to_check) {
foreach ($paths_to_check as $path_to_check) { foreach ($paths_to_check as $path_to_check) {
if (is_dir($path_to_check)) { if (is_dir($path_to_check)) {
$project_checker->checkDir($path_to_check, $update_docblocks); $project_checker->checkDir($path_to_check);
} else { } else {
$project_checker->checkFile($path_to_check, $update_docblocks); $project_checker->checkFile($path_to_check);
} }
} }
} }

View File

@ -210,10 +210,10 @@ class FileChecker extends SourceChecker implements StatementsSource
$function_stmts = []; $function_stmts = [];
foreach ($stmts as $stmt) { foreach ($stmts as $stmt) {
if ($stmt instanceof PhpParser\Node\Stmt\Class_ if ($stmt instanceof PhpParser\Node\Stmt\Class_ ||
|| $stmt instanceof PhpParser\Node\Stmt\Interface_ $stmt instanceof PhpParser\Node\Stmt\Interface_ ||
|| $stmt instanceof PhpParser\Node\Stmt\Trait_ $stmt instanceof PhpParser\Node\Stmt\Trait_ ||
|| $stmt instanceof PhpParser\Node\Stmt\Namespace_ $stmt instanceof PhpParser\Node\Stmt\Namespace_
) { ) {
if ($stmt instanceof PhpParser\Node\Stmt\Class_ && $stmt->name) { if ($stmt instanceof PhpParser\Node\Stmt\Class_ && $stmt->name) {
$class_checker = new ClassChecker($stmt, $this, $stmt->name); $class_checker = new ClassChecker($stmt, $this, $stmt->name);
@ -296,7 +296,7 @@ class FileChecker extends SourceChecker implements StatementsSource
$config = Config::getInstance(); $config = Config::getInstance();
foreach ($this->namespace_checkers as $namespace_checker) { foreach ($this->namespace_checkers as $namespace_checker) {
$namespace_checker->analyze(clone $this->context, $preserve_checkers); $namespace_checker->analyze(clone $this->context, $preserve_checkers, $update_docblocks);
} }
foreach ($this->class_checkers as $class_checker) { foreach ($this->class_checkers as $class_checker) {

View File

@ -101,12 +101,13 @@ class NamespaceChecker extends SourceChecker implements StatementsSource
/** /**
* @param Context $context * @param Context $context
* @param bool $preserve_checkers * @param bool $preserve_checkers
* @param bool $update_docblocks
* @return void * @return void
*/ */
public function analyze(Context $context, $preserve_checkers = false) public function analyze(Context $context, $preserve_checkers = false, $update_docblocks = false)
{ {
foreach ($this->class_checkers as $class_checker) { foreach ($this->class_checkers as $class_checker) {
$class_checker->analyze(null, $context); $class_checker->analyze(null, $context, $update_docblocks);
} }
if (!$preserve_checkers) { if (!$preserve_checkers) {

View File

@ -48,6 +48,11 @@ class ProjectChecker
*/ */
public $debug_output = false; public $debug_output = false;
/**
* @var boolean
*/
public $update_docblocks = false;
/** /**
* @var boolean * @var boolean
*/ */
@ -146,16 +151,19 @@ class ProjectChecker
* @param boolean $show_info * @param boolean $show_info
* @param boolean $debug_output * @param boolean $debug_output
* @param string $output_format * @param string $output_format
* @param bool $update_docblocks
*/ */
public function __construct( public function __construct(
$use_color = true, $use_color = true,
$show_info = true, $show_info = true,
$output_format = self::TYPE_CONSOLE, $output_format = self::TYPE_CONSOLE,
$debug_output = false $debug_output = false,
$update_docblocks = false
) { ) {
$this->use_color = $use_color; $this->use_color = $use_color;
$this->show_info = $show_info; $this->show_info = $show_info;
$this->debug_output = $debug_output; $this->debug_output = $debug_output;
$this->update_docblocks = $update_docblocks;
if (!in_array($output_format, [self::TYPE_CONSOLE, self::TYPE_JSON])) { if (!in_array($output_format, [self::TYPE_CONSOLE, self::TYPE_JSON])) {
throw new \UnexpectedValueException('Unrecognised output format ' . $output_format); throw new \UnexpectedValueException('Unrecognised output format ' . $output_format);
@ -175,10 +183,9 @@ class ProjectChecker
/** /**
* @param boolean $is_diff * @param boolean $is_diff
* @param boolean $update_docblocks
* @return void * @return void
*/ */
public function check($is_diff = false, $update_docblocks = false) public function check($is_diff = false)
{ {
$cwd = getcwd(); $cwd = getcwd();
@ -208,7 +215,7 @@ class ProjectChecker
if ($diff_files === null || $deleted_files === null || count($diff_files) > 200) { if ($diff_files === null || $deleted_files === null || count($diff_files) > 200) {
foreach ($this->config->getProjectDirectories() as $dir_name) { foreach ($this->config->getProjectDirectories() as $dir_name) {
$this->checkDirWithConfig($dir_name, $this->config, $update_docblocks); $this->checkDirWithConfig($dir_name, $this->config);
} }
$this->visitFiles(); $this->visitFiles();
@ -277,16 +284,15 @@ class ProjectChecker
echo 'Analyzing ' . $file_checker->getFilePath() . PHP_EOL; echo 'Analyzing ' . $file_checker->getFilePath() . PHP_EOL;
} }
$file_checker->analyze(); $file_checker->analyze($this->update_docblocks);
} }
} }
/** /**
* @param string $dir_name * @param string $dir_name
* @param boolean $update_docblocks
* @return void * @return void
*/ */
public function checkDir($dir_name, $update_docblocks = false) public function checkDir($dir_name)
{ {
if (!$this->config) { if (!$this->config) {
$this->config = $this->getConfigForPath($dir_name); $this->config = $this->getConfigForPath($dir_name);
@ -299,7 +305,7 @@ class ProjectChecker
$start_checks = (int)microtime(true); $start_checks = (int)microtime(true);
$this->checkDirWithConfig($dir_name, $this->config, $update_docblocks); $this->checkDirWithConfig($dir_name, $this->config);
$this->visitFiles(); $this->visitFiles();
$this->analyzeFiles(); $this->analyzeFiles();
@ -310,10 +316,9 @@ class ProjectChecker
/** /**
* @param string $dir_name * @param string $dir_name
* @param Config $config * @param Config $config
* @param bool $update_docblocks
* @return void * @return void
*/ */
protected function checkDirWithConfig($dir_name, Config $config, $update_docblocks) protected function checkDirWithConfig($dir_name, Config $config)
{ {
$file_extensions = $config->getFileExtensions(); $file_extensions = $config->getFileExtensions();
@ -431,10 +436,9 @@ class ProjectChecker
/** /**
* @param string $file_name * @param string $file_name
* @param bool $update_docblocks
* @return void * @return void
*/ */
public function checkFile($file_name, $update_docblocks = false) public function checkFile($file_name)
{ {
if ($this->debug_output) { if ($this->debug_output) {
echo 'Checking ' . $file_name . PHP_EOL; echo 'Checking ' . $file_name . PHP_EOL;
@ -464,7 +468,7 @@ class ProjectChecker
echo 'Analyzing ' . $file_checker->getFilePath() . PHP_EOL; echo 'Analyzing ' . $file_checker->getFilePath() . PHP_EOL;
} }
$file_checker->analyze(); $file_checker->analyze($this->update_docblocks);
IssueBuffer::finish(false, $start_checks, $this->debug_output); IssueBuffer::finish(false, $start_checks, $this->debug_output);
} }