mirror of
				https://github.com/yiisoft/yii2.git
				synced 2025-11-01 03:26:36 +08:00 
			
		
		
		
	Upgrade to PSR12 coding standard (#20121)
This commit is contained in:
		| @ -1,4 +1,5 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * @link https://www.yiiframework.com/ | ||||
|  * @copyright Copyright (c) 2008 Yii Software LLC | ||||
|  | ||||
| @ -1,4 +1,5 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * @link https://www.yiiframework.com/ | ||||
|  * @copyright Copyright (c) 2008 Yii Software LLC | ||||
|  | ||||
| @ -1,4 +1,5 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * @link https://www.yiiframework.com/ | ||||
|  * @copyright Copyright (c) 2008 Yii Software LLC | ||||
|  | ||||
| @ -1,4 +1,5 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * @link https://www.yiiframework.com/ | ||||
|  * @copyright Copyright (c) 2008 Yii Software LLC | ||||
|  | ||||
| @ -1,4 +1,5 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * @link https://www.yiiframework.com/ | ||||
|  * @copyright Copyright (c) 2008 Yii Software LLC | ||||
| @ -113,13 +114,13 @@ class HelpController extends Controller | ||||
|         } | ||||
|  | ||||
|         foreach ($controller->getActionArgsHelp($action) as $argument => $help) { | ||||
|             $description = preg_replace("~\R~", '', addcslashes($help['comment'], ':')) ?: $argument; | ||||
|             $description = preg_replace('~\R~', '', addcslashes($help['comment'], ':')) ?: $argument; | ||||
|             $this->stdout($argument . ':' . $description . "\n"); | ||||
|         } | ||||
|  | ||||
|         $this->stdout("\n"); | ||||
|         foreach ($controller->getActionOptionsHelp($action) as $argument => $help) { | ||||
|             $description = preg_replace("~\R~", '', addcslashes($help['comment'], ':')); | ||||
|             $description = preg_replace('~\R~', '', addcslashes($help['comment'], ':')); | ||||
|             $this->stdout('--' . $argument . ($description ? ':' . $description : '') . "\n"); | ||||
|         } | ||||
|     } | ||||
| @ -440,11 +441,12 @@ class HelpController extends Controller | ||||
|         if (!empty($args)) { | ||||
|             foreach ($args as $name => $arg) { | ||||
|                 $this->stdout($this->formatOptionHelp( | ||||
|                         '- ' . $this->ansiFormat($name, Console::FG_CYAN), | ||||
|                         $arg['required'], | ||||
|                         $arg['type'], | ||||
|                         $arg['default'], | ||||
|                         $arg['comment']) . "\n\n"); | ||||
|                     '- ' . $this->ansiFormat($name, Console::FG_CYAN), | ||||
|                     $arg['required'], | ||||
|                     $arg['type'], | ||||
|                     $arg['default'], | ||||
|                     $arg['comment'] | ||||
|                 ) . "\n\n"); | ||||
|             } | ||||
|         } | ||||
|  | ||||
| @ -452,12 +454,16 @@ class HelpController extends Controller | ||||
|             $this->stdout("\nOPTIONS\n\n", Console::BOLD); | ||||
|             foreach ($options as $name => $option) { | ||||
|                 $this->stdout($this->formatOptionHelp( | ||||
|                         $this->ansiFormat('--' . $name . $this->formatOptionAliases($controller, $name), | ||||
|                             Console::FG_RED, empty($option['required']) ? Console::FG_RED : Console::BOLD), | ||||
|                         !empty($option['required']), | ||||
|                         $option['type'], | ||||
|                         $option['default'], | ||||
|                         $option['comment']) . "\n\n"); | ||||
|                     $this->ansiFormat( | ||||
|                         '--' . $name . $this->formatOptionAliases($controller, $name), | ||||
|                         Console::FG_RED, | ||||
|                         empty($option['required']) ? Console::FG_RED : Console::BOLD | ||||
|                     ), | ||||
|                     !empty($option['required']), | ||||
|                     $option['type'], | ||||
|                     $option['default'], | ||||
|                     $option['comment'] | ||||
|                 ) . "\n\n"); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @ -1,4 +1,5 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * @link https://www.yiiframework.com/ | ||||
|  * @copyright Copyright (c) 2008 Yii Software LLC | ||||
| @ -353,7 +354,7 @@ EOD; | ||||
|         foreach ($rows as $row) { | ||||
|             $currentMessages[$row['category']][$row['id']] = $row['message']; | ||||
|         } | ||||
|          | ||||
|  | ||||
|         $new = []; | ||||
|         $obsolete = []; | ||||
|  | ||||
| @ -368,7 +369,7 @@ EOD; | ||||
|                 $new[$category] = $msgs; | ||||
|             } | ||||
|         } | ||||
|          | ||||
|  | ||||
|         // obsolete categories | ||||
|         foreach (array_diff(array_keys($currentMessages), array_keys($messages)) as $category) { | ||||
|             $obsolete += $currentMessages[$category]; | ||||
| @ -381,8 +382,8 @@ EOD; | ||||
|                     unset($obsolete[$pk]); | ||||
|                 } | ||||
|             } | ||||
|         }         | ||||
|          | ||||
|         } | ||||
|  | ||||
|         $this->stdout('Inserting new messages...'); | ||||
|         $insertCount = 0; | ||||
|  | ||||
| @ -392,9 +393,9 @@ EOD; | ||||
|                 $db->schema->insert($sourceMessageTable, ['category' => $category, 'message' => $msg]); | ||||
|             } | ||||
|         } | ||||
|          | ||||
|  | ||||
|         $this->stdout($insertCount ? "{$insertCount} saved.\n" : "Nothing to save.\n"); | ||||
|          | ||||
|  | ||||
|         $this->stdout($removeUnused ? 'Deleting obsoleted messages...' : 'Updating obsoleted messages...'); | ||||
|  | ||||
|         if (empty($obsolete)) { | ||||
| @ -408,13 +409,13 @@ EOD; | ||||
|                    ->execute(); | ||||
|                 $this->stdout("{$affected} deleted.\n"); | ||||
|             } elseif ($markUnused) { | ||||
|                 $marked=0; | ||||
|                 $marked = 0; | ||||
|                 $rows = (new Query()) | ||||
|                     ->select(['id', 'message']) | ||||
|                     ->from($sourceMessageTable) | ||||
|                     ->where(['in', 'id', array_keys($obsolete)]) | ||||
|                     ->all($db); | ||||
|      | ||||
|  | ||||
|                 foreach ($rows as $row) { | ||||
|                     $marked++; | ||||
|                     $db->createCommand()->update( | ||||
| @ -428,64 +429,64 @@ EOD; | ||||
|                 $this->stdout("kept untouched.\n"); | ||||
|             } | ||||
|         } | ||||
|          | ||||
|  | ||||
|         // get fresh message id list | ||||
|         $freshMessagesIds = []; | ||||
|         $rows = (new Query())->select(['id'])->from($sourceMessageTable)->all($db); | ||||
|         foreach ($rows as $row) { | ||||
|             $freshMessagesIds[] = $row['id']; | ||||
|         } | ||||
|              | ||||
|         $this->stdout("Generating missing rows..."); | ||||
|  | ||||
|         $this->stdout('Generating missing rows...'); | ||||
|         $generatedMissingRows = []; | ||||
|          | ||||
|  | ||||
|         foreach ($languages as $language) { | ||||
|           $count = 0; | ||||
|            | ||||
|           // get list of ids of translations for this language | ||||
|           $msgRowsIds = []; | ||||
|           $msgRows = (new Query())->select(['id'])->from($messageTable)->where([ | ||||
|               'language'=>$language, | ||||
|           ])->all($db); | ||||
|           foreach ($msgRows as $row) { | ||||
|               $msgRowsIds[] = $row['id']; | ||||
|           } | ||||
|            | ||||
|           // insert missing | ||||
|           foreach ($freshMessagesIds as $id) { | ||||
|             if (!in_array($id, $msgRowsIds)) { | ||||
|               $db->createCommand() | ||||
|                  ->insert($messageTable, ['id' => $id, 'language' => $language]) | ||||
|                  ->execute(); | ||||
|               $count++; | ||||
|             $count = 0; | ||||
|  | ||||
|             // get list of ids of translations for this language | ||||
|             $msgRowsIds = []; | ||||
|             $msgRows = (new Query())->select(['id'])->from($messageTable)->where([ | ||||
|                 'language' => $language, | ||||
|             ])->all($db); | ||||
|             foreach ($msgRows as $row) { | ||||
|                 $msgRowsIds[] = $row['id']; | ||||
|             } | ||||
|  | ||||
|             // insert missing | ||||
|             foreach ($freshMessagesIds as $id) { | ||||
|                 if (!in_array($id, $msgRowsIds)) { | ||||
|                     $db->createCommand() | ||||
|                        ->insert($messageTable, ['id' => $id, 'language' => $language]) | ||||
|                        ->execute(); | ||||
|                     $count++; | ||||
|                 } | ||||
|             } | ||||
|             if ($count) { | ||||
|                 $generatedMissingRows[] = "{$count} for {$language}"; | ||||
|             } | ||||
|           } | ||||
|           if ($count) { | ||||
|             $generatedMissingRows[] = "{$count} for {$language}"; | ||||
|           } | ||||
|         } | ||||
|          | ||||
|         $this->stdout($generatedMissingRows ? implode(", ", $generatedMissingRows).".\n" : "Nothing to do.\n"); | ||||
|          | ||||
|         $this->stdout("Dropping unused languages..."); | ||||
|         $droppedLanguages=[]; | ||||
|          | ||||
|  | ||||
|         $this->stdout($generatedMissingRows ? implode(', ', $generatedMissingRows) . ".\n" : "Nothing to do.\n"); | ||||
|  | ||||
|         $this->stdout('Dropping unused languages...'); | ||||
|         $droppedLanguages = []; | ||||
|  | ||||
|         $currentLanguages = []; | ||||
|         $rows = (new Query())->select(['language'])->from($messageTable)->groupBy('language')->all($db); | ||||
|         foreach ($rows as $row) { | ||||
|             $currentLanguages[] = $row['language']; | ||||
|         } | ||||
|          | ||||
|  | ||||
|         foreach ($currentLanguages as $currentLanguage) { | ||||
|           if (!in_array($currentLanguage, $languages)) { | ||||
|             $deleted=$db->createCommand()->delete($messageTable, "language=:language", [ | ||||
|                 'language'=>$currentLanguage, | ||||
|             ])->execute(); | ||||
|             $droppedLanguages[] = "removed {$deleted} rows for $currentLanguage"; | ||||
|           } | ||||
|             if (!in_array($currentLanguage, $languages)) { | ||||
|                 $deleted = $db->createCommand()->delete($messageTable, 'language=:language', [ | ||||
|                     'language' => $currentLanguage, | ||||
|                 ])->execute(); | ||||
|                 $droppedLanguages[] = "removed {$deleted} rows for $currentLanguage"; | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         $this->stdout($droppedLanguages ? implode(", ", $droppedLanguages).".\n" : "Nothing to do.\n"); | ||||
|  | ||||
|         $this->stdout($droppedLanguages ? implode(', ', $droppedLanguages) . ".\n" : "Nothing to do.\n"); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|  | ||||
| @ -1,4 +1,5 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * @link https://www.yiiframework.com/ | ||||
|  * @copyright Copyright (c) 2008 Yii Software LLC | ||||
| @ -411,11 +412,7 @@ class MigrateController extends BaseMigrateController | ||||
|  | ||||
|         $templateFile = $this->templateFile; | ||||
|         $table = null; | ||||
|         if (preg_match( | ||||
|             '/^create_?junction_?(?:table)?_?(?:for)?(.+)_?and(.+)_?tables?$/i', | ||||
|             $name, | ||||
|             $matches | ||||
|         )) { | ||||
|         if (preg_match('/^create_?junction_?(?:table)?_?(?:for)?(.+)_?and(.+)_?tables?$/i', $name, $matches)) { | ||||
|             $templateFile = $this->generatorTemplateFiles['create_junction']; | ||||
|             $firstTable = $this->normalizeTableName($matches[1]); | ||||
|             $secondTable = $this->normalizeTableName($matches[2]); | ||||
|  | ||||
| @ -1,4 +1,5 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * @link https://www.yiiframework.com/ | ||||
|  * @copyright Copyright (c) 2008 Yii Software LLC | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Razvan Grigore
					Razvan Grigore