Commit 12d34849 by Carsten Brandt

improved phpdoc command

parent 83a63f23
...@@ -84,6 +84,7 @@ class PhpDocController extends Controller ...@@ -84,6 +84,7 @@ class PhpDocController extends Controller
$lines = preg_split('/(\r\n|\n|\r)/', $contents); $lines = preg_split('/(\r\n|\n|\r)/', $contents);
$this->fixFileDoc($lines); $this->fixFileDoc($lines);
$this->fixDocBlockIndentation($lines);
$newContent = implode("\n", $lines); $newContent = implode("\n", $lines);
if ($sha !== sha1($newContent)) { if ($sha !== sha1($newContent)) {
...@@ -194,6 +195,48 @@ class PhpDocController extends Controller ...@@ -194,6 +195,48 @@ class PhpDocController extends Controller
} }
} }
/**
* Markdown aware fix of whitespace issues in doc comments
*/
protected function fixDocBlockIndentation(&$lines)
{
$docBlock = false;
$codeBlock = false;
$listIndent = false;
$indent = '';
foreach($lines as $i => $line) {
if (preg_match('~^(\s+)/\*\*$~', $line, $matches)) {
$docBlock = true;
$indent = $matches[1];
} elseif (preg_match('~^(\s+)\*/~', $line)) {
$docBlock = false;
$codeBlock = false;
$listIndent = '';
$lines[$i] = $indent . ' */';
} elseif ($docBlock) {
$docLine = trim($line, " \t*");
if (empty($docLine)) {
$listIndent = '';
} elseif ($docLine[0] === '@') {
$listIndent = '';
$codeBlock = false;
$docLine = preg_replace('/\s+/', ' ', $docLine);
} elseif (preg_match('/^(~~~|```)/', $docLine)) {
$codeBlock = !$codeBlock;
} elseif (preg_match('/^([0-9]+\.|-|\*|\+) /', $docLine, $matches)) {
$listIndent = str_repeat(' ', strlen($matches[0]));
$lines[$i] = $indent . ' * ' . $docLine;
continue;
}
if ($codeBlock) {
$lines[$i] = rtrim($indent . ' * ' . substr(ltrim($line), 2));
} else {
$lines[$i] = rtrim($indent . ' * ' . $listIndent . $docLine);
}
}
}
}
protected function updateClassPropertyDocs($file, $className, $propertyDoc) protected function updateClassPropertyDocs($file, $className, $propertyDoc)
{ {
$ref = new \ReflectionClass($className); $ref = new \ReflectionClass($className);
......
<?php <?php
/** /**
* @link http://www.yiiframework.com/ * @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment