Commit 3c400dbc by Carsten Brandt

fixed file PHPdoc

issue #3026
parent c5ad45c7
......@@ -41,6 +41,73 @@ class PhpDocController extends Controller
*/
public function actionProperty($root = null)
{
$files = $this->findFiles($root);
$nFilesTotal = 0;
$nFilesUpdated = 0;
foreach ($files as $file) {
$result = $this->generateClassPropertyDocs($file);
if ($result !== false) {
list($className, $phpdoc) = $result;
if ($this->updateFiles) {
if ($this->updateClassPropertyDocs($file, $className, $phpdoc)) {
$nFilesUpdated++;
}
} elseif (!empty($phpdoc)) {
$this->stdout("\n[ " . $file . " ]\n\n", Console::BOLD);
$this->stdout($phpdoc);
}
}
$nFilesTotal++;
}
$this->stdout("\nParsed $nFilesTotal files.\n");
$this->stdout("Updated $nFilesUpdated files.\n");
}
/**
* Fix some issues with PHPdoc in files
*
* @param string $root the directory to parse files from. Defaults to YII_PATH.
*/
public function actionFix($root = null)
{
$files = $this->findFiles($root);
$nFilesTotal = 0;
$nFilesUpdated = 0;
foreach ($files as $file) {
$contents = file_get_contents($file);
$sha = sha1($contents);
// fix line endings
$lines = preg_split('/(\r\n|\n|\r)/', $contents);
$this->fixFileDoc($lines);
$newContent = implode("\n", $lines);
if ($sha !== sha1($newContent)) {
$nFilesUpdated++;
}
file_put_contents($file, $newContent);
$nFilesTotal++;
}
$this->stdout("\nParsed $nFilesTotal files.\n");
$this->stdout("Updated $nFilesUpdated files.\n");
}
/**
* @inheritdoc
*/
public function options($actionId)
{
return array_merge(parent::options($actionId), ['updateFiles']);
}
protected function findFiles($root)
{
$except = [];
if ($root === null) {
$root = dirname(YII_PATH);
......@@ -89,35 +156,42 @@ class PhpDocController extends Controller
'vendor/',
]),
];
$files = FileHelper::findFiles($root, $options);
$nFilesTotal = 0;
$nFilesUpdated = 0;
foreach ($files as $file) {
$result = $this->generateClassPropertyDocs($file);
if ($result !== false) {
list($className, $phpdoc) = $result;
if ($this->updateFiles) {
if ($this->updateClassPropertyDocs($file, $className, $phpdoc)) {
$nFilesUpdated++;
}
} elseif (!empty($phpdoc)) {
$this->stdout("\n[ " . $file . " ]\n\n", Console::BOLD);
$this->stdout($phpdoc);
return FileHelper::findFiles($root, $options);
}
protected function fixFileDoc(&$lines)
{
// find namespace
$namespace = false;
$namespaceLine = '';
$contentAfterNamespace = false;
foreach($lines as $i => $line) {
if (substr(trim($line), 0, 9) === 'namespace') {
$namespace = $i;
$namespaceLine = trim($line);
} elseif ($namespace !== false && trim($line) !== '') {
$contentAfterNamespace = $i;
break;
}
$nFilesTotal++;
}
$this->stdout("\nParsed $nFilesTotal files.\n");
$this->stdout("Updated $nFilesUpdated files.\n");
if ($namespace !== false && $contentAfterNamespace !== false) {
while($contentAfterNamespace > 0) {
array_shift($lines);
$contentAfterNamespace--;
}
$lines = array_merge([
"<?php",
"/**",
" * @link http://www.yiiframework.com/",
" * @copyright Copyright (c) 2008 Yii Software LLC",
" * @license http://www.yiiframework.com/license/",
" */",
"",
$namespaceLine,
""
], $lines);
}
/**
* @inheritdoc
*/
public function options($actionId)
{
return array_merge(parent::options($actionId), ['updateFiles']);
}
protected function updateClassPropertyDocs($file, $className, $propertyDoc)
......
......@@ -6,6 +6,7 @@
*/
namespace yii\apidoc\templates\bootstrap;
use yii\apidoc\models\Context;
use yii\console\Controller;
use Yii;
......
......@@ -6,6 +6,7 @@
*/
namespace yii\apidoc\templates\bootstrap;
use Yii;
use yii\helpers\Html;
......
<?php
/**
* @author Carsten Brandt <mail@cebe.cc>
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\apidoc\templates\bootstrap;
......
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\codeception;
......
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\debug\models\search;
......
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\debug\panels;
......
<?php
/**
* Smarty view renderer class file.
*
* @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008 Yii Software LLC
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
......
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008-2011 Yii Software LLC
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
......
<?php
/**
* Twig view renderer class file.
*
* @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008 Yii Software LLC
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
......
<?php
/**
* Twig ViewRendererStaticClassProxy class file.
*
* @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008 Yii Software LLC
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
......
<?php
/**
* Console Application class file.
*
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
......
<?php
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
......
<?php
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
......
<?php
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
......
<?php
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
......
<?php
/**
*
*
* @author Carsten Brandt <mail@cebe.cc>
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\db;
......
<?php
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
......
......@@ -6,6 +6,7 @@
*/
namespace yii\db;
use yii\di\Instance;
/**
......
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008-2011 Yii Software LLC
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
......
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008-2011 Yii Software LLC
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
......
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
......
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
......
<?php
/**
* @copyright Copyright (c) 2008 Yii Software LLC
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
......
<?php
/**
* @copyright Copyright (c) 2008 Yii Software LLC
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
......
<?php
/**
* Filesystem helper class file.
*
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
......
<?php
/**
* @copyright Copyright (c) 2008 Yii Software LLC
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\helpers;
/**
......
<?php
/**
* @copyright Copyright (c) 2008 Yii Software LLC
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
......
<?php
/**
* @copyright Copyright (c) 2008 Yii Software LLC
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
......
<?php
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008-2011 Yii Software LLC
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
......
<?php
/**
* Filesystem helper class file.
*
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
......
<?php
/**
* @copyright Copyright (c) 2008 Yii Software LLC
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
......
<?php
/**
* @copyright Copyright (c) 2008 Yii Software LLC
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
......
<?php
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008-2011 Yii Software LLC
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
......
<?php
/**
* Image validator class file.
*
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
......
......@@ -4,6 +4,7 @@
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\widgets;
use Yii;
......
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