Commit 3c400dbc by Carsten Brandt

fixed file PHPdoc

issue #3026
parent c5ad45c7
...@@ -41,6 +41,73 @@ class PhpDocController extends Controller ...@@ -41,6 +41,73 @@ class PhpDocController extends Controller
*/ */
public function actionProperty($root = null) 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 = []; $except = [];
if ($root === null) { if ($root === null) {
$root = dirname(YII_PATH); $root = dirname(YII_PATH);
...@@ -89,35 +156,42 @@ class PhpDocController extends Controller ...@@ -89,35 +156,42 @@ class PhpDocController extends Controller
'vendor/', 'vendor/',
]), ]),
]; ];
$files = FileHelper::findFiles($root, $options); return 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);
} }
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"); if ($namespace !== false && $contentAfterNamespace !== false) {
$this->stdout("Updated $nFilesUpdated files.\n"); 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) protected function updateClassPropertyDocs($file, $className, $propertyDoc)
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
namespace yii\apidoc\templates\bootstrap; namespace yii\apidoc\templates\bootstrap;
use yii\apidoc\models\Context; use yii\apidoc\models\Context;
use yii\console\Controller; use yii\console\Controller;
use Yii; use Yii;
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
namespace yii\apidoc\templates\bootstrap; namespace yii\apidoc\templates\bootstrap;
use Yii; use Yii;
use yii\helpers\Html; use yii\helpers\Html;
......
<?php <?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; namespace yii\apidoc\templates\bootstrap;
......
<?php <?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\codeception; namespace yii\codeception;
......
<?php <?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\debug\models\search; namespace yii\debug\models\search;
......
<?php <?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\debug\panels; namespace yii\debug\panels;
......
<?php <?php
/** /**
* Smarty view renderer class file.
*
* @link http://www.yiiframework.com/ * @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/ * @license http://www.yiiframework.com/license/
*/ */
......
<?php <?php
/** /**
* @link http://www.yiiframework.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/ * @license http://www.yiiframework.com/license/
*/ */
......
<?php <?php
/** /**
* Twig view renderer class file.
*
* @link http://www.yiiframework.com/ * @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/ * @license http://www.yiiframework.com/license/
*/ */
......
<?php <?php
/** /**
* Twig ViewRendererStaticClassProxy class file.
*
* @link http://www.yiiframework.com/ * @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/ * @license http://www.yiiframework.com/license/
*/ */
......
<?php <?php
/** /**
* Console Application class file.
*
* @link http://www.yiiframework.com/ * @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC * @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
......
<?php <?php
/** /**
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/ * @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC * @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
......
<?php <?php
/** /**
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/ * @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC * @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
......
<?php <?php
/** /**
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/ * @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC * @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
......
<?php <?php
/** /**
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/ * @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC * @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
......
<?php <?php
/** /**
* * @link http://www.yiiframework.com/
* * @copyright Copyright (c) 2008 Yii Software LLC
* @author Carsten Brandt <mail@cebe.cc> * @license http://www.yiiframework.com/license/
*/ */
namespace yii\db; namespace yii\db;
......
<?php <?php
/** /**
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/ * @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC * @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
namespace yii\db; namespace yii\db;
use yii\di\Instance; use yii\di\Instance;
/** /**
......
<?php <?php
/** /**
* @link http://www.yiiframework.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/ * @license http://www.yiiframework.com/license/
*/ */
......
<?php <?php
/** /**
* @link http://www.yiiframework.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/ * @license http://www.yiiframework.com/license/
*/ */
......
<?php <?php
/** /**
* @link http://www.yiiframework.com/ * @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC * @copyright Copyright (c) 2008 Yii Software LLC
......
<?php <?php
/** /**
* @link http://www.yiiframework.com/ * @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC * @copyright Copyright (c) 2008 Yii Software LLC
......
<?php <?php
/** /**
* @copyright Copyright (c) 2008 Yii Software LLC
* @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/
*/ */
......
<?php <?php
/** /**
* @copyright Copyright (c) 2008 Yii Software LLC
* @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/
*/ */
......
<?php <?php
/** /**
* Filesystem helper class file.
*
* @link http://www.yiiframework.com/ * @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC * @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
......
<?php <?php
/** /**
* @copyright Copyright (c) 2008 Yii Software LLC
* @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/
*/ */
namespace yii\helpers; namespace yii\helpers;
/** /**
......
<?php <?php
/** /**
* @copyright Copyright (c) 2008 Yii Software LLC
* @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/
*/ */
......
<?php <?php
/** /**
* @copyright Copyright (c) 2008 Yii Software LLC
* @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/
*/ */
......
<?php <?php
/** /**
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.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/ * @license http://www.yiiframework.com/license/
*/ */
......
<?php <?php
/** /**
* Filesystem helper class file.
*
* @link http://www.yiiframework.com/ * @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC * @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
......
<?php <?php
/** /**
* @copyright Copyright (c) 2008 Yii Software LLC
* @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/
*/ */
......
<?php <?php
/** /**
* @copyright Copyright (c) 2008 Yii Software LLC
* @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/
*/ */
......
<?php <?php
/** /**
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.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/ * @license http://www.yiiframework.com/license/
*/ */
......
<?php <?php
/** /**
* Image validator class file.
*
* @link http://www.yiiframework.com/ * @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC * @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
* @copyright Copyright (c) 2008 Yii Software LLC * @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yii\widgets; namespace yii\widgets;
use Yii; 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