diff --git a/build/controllers/PhpDocController.php b/build/controllers/PhpDocController.php index f584390b37..0276714c57 100644 --- a/build/controllers/PhpDocController.php +++ b/build/controllers/PhpDocController.php @@ -40,6 +40,73 @@ class PhpDocController extends Controller * @param string $root the directory to parse files from. Defaults to YII_PATH. */ 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) { @@ -72,15 +139,15 @@ class PhpDocController extends Controller $root = FileHelper::normalizePath($root); $options = [ 'filter' => function ($path) { - if (is_file($path)) { - $file = basename($path); - if ($file[0] < 'A' || $file[0] > 'Z') { - return false; + if (is_file($path)) { + $file = basename($path); + if ($file[0] < 'A' || $file[0] > 'Z') { + return false; + } } - } - return null; - }, + return null; + }, 'only' => ['*.php'], 'except' => array_merge($except, [ 'views/', @@ -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); - } - } - $nFilesTotal++; - } - - $this->stdout("\nParsed $nFilesTotal files.\n"); - $this->stdout("Updated $nFilesUpdated files.\n"); + return FileHelper::findFiles($root, $options); } - /** - * @inheritdoc - */ - public function options($actionId) + protected function fixFileDoc(&$lines) { - return array_merge(parent::options($actionId), ['updateFiles']); + // 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; + } + } + + if ($namespace !== false && $contentAfterNamespace !== false) { + while($contentAfterNamespace > 0) { + array_shift($lines); + $contentAfterNamespace--; + } + $lines = array_merge([ + " + * @link http://www.yiiframework.com/ + * @copyright Copyright (c) 2008 Yii Software LLC + * @license http://www.yiiframework.com/license/ */ namespace yii\apidoc\templates\bootstrap; diff --git a/extensions/codeception/BasePage.php b/extensions/codeception/BasePage.php index 32a12a38d7..521c412030 100644 --- a/extensions/codeception/BasePage.php +++ b/extensions/codeception/BasePage.php @@ -1,4 +1,9 @@ * @link http://www.yiiframework.com/ * @copyright Copyright (c) 2008 Yii Software LLC * @license http://www.yiiframework.com/license/ diff --git a/framework/console/controllers/MigrateController.php b/framework/console/controllers/MigrateController.php index 48fc381e61..83221c7ac2 100644 --- a/framework/console/controllers/MigrateController.php +++ b/framework/console/controllers/MigrateController.php @@ -1,6 +1,5 @@ * @link http://www.yiiframework.com/ * @copyright Copyright (c) 2008 Yii Software LLC * @license http://www.yiiframework.com/license/ diff --git a/framework/db/ActiveQuery.php b/framework/db/ActiveQuery.php index f5cdfe2aaf..bc28f3c747 100644 --- a/framework/db/ActiveQuery.php +++ b/framework/db/ActiveQuery.php @@ -1,6 +1,5 @@ * @link http://www.yiiframework.com/ * @copyright Copyright (c) 2008 Yii Software LLC * @license http://www.yiiframework.com/license/ diff --git a/framework/db/ActiveRecord.php b/framework/db/ActiveRecord.php index 26c4a8acb4..ba0badf682 100644 --- a/framework/db/ActiveRecord.php +++ b/framework/db/ActiveRecord.php @@ -1,6 +1,5 @@ * @link http://www.yiiframework.com/ * @copyright Copyright (c) 2008 Yii Software LLC * @license http://www.yiiframework.com/license/ diff --git a/framework/db/ActiveRecordInterface.php b/framework/db/ActiveRecordInterface.php index 8418581da3..3a23a2adb0 100644 --- a/framework/db/ActiveRecordInterface.php +++ b/framework/db/ActiveRecordInterface.php @@ -1,8 +1,8 @@ + * @link http://www.yiiframework.com/ + * @copyright Copyright (c) 2008 Yii Software LLC + * @license http://www.yiiframework.com/license/ */ namespace yii\db; diff --git a/framework/db/BaseActiveRecord.php b/framework/db/BaseActiveRecord.php index e0410865de..965a40db02 100644 --- a/framework/db/BaseActiveRecord.php +++ b/framework/db/BaseActiveRecord.php @@ -1,6 +1,5 @@ * @link http://www.yiiframework.com/ * @copyright Copyright (c) 2008 Yii Software LLC * @license http://www.yiiframework.com/license/ diff --git a/framework/db/Migration.php b/framework/db/Migration.php index 87fcdde69a..b03957ba7a 100644 --- a/framework/db/Migration.php +++ b/framework/db/Migration.php @@ -6,6 +6,7 @@ */ namespace yii\db; + use yii\di\Instance; /** diff --git a/framework/db/TableSchema.php b/framework/db/TableSchema.php index 48723a47db..7900561072 100644 --- a/framework/db/TableSchema.php +++ b/framework/db/TableSchema.php @@ -1,7 +1,7 @@ * @link http://www.yiiframework.com/ - * @copyright Copyright © 2008-2011 Yii Software LLC + * @copyright Copyright (c) 2008 Yii Software LLC * @license http://www.yiiframework.com/license/ */ diff --git a/framework/helpers/FileHelper.php b/framework/helpers/FileHelper.php index 63954a423c..9fcf164ac4 100644 --- a/framework/helpers/FileHelper.php +++ b/framework/helpers/FileHelper.php @@ -1,7 +1,5 @@ * @link http://www.yiiframework.com/ - * @copyright Copyright © 2008-2011 Yii Software LLC + * @copyright Copyright (c) 2008 Yii Software LLC * @license http://www.yiiframework.com/license/ */ diff --git a/framework/validators/ImageValidator.php b/framework/validators/ImageValidator.php index 89f087e1fa..3e1a3c9373 100644 --- a/framework/validators/ImageValidator.php +++ b/framework/validators/ImageValidator.php @@ -1,7 +1,5 @@