Commit c1445871 by Thiago Talma

Correction of many errors code inspection.

Adjustments code according to the standards. Adding missing PHPDoc comment.
parent 664d2aa0
......@@ -15,6 +15,8 @@ namespace yii\base;
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*
* @property array $data
*/
trait ArrayAccessTrait
{
......
......@@ -176,7 +176,7 @@ abstract class ErrorHandler extends Component
* Renders the exception.
* @param \Exception $exception the exception to be rendered.
*/
protected abstract function renderException($exception);
abstract protected function renderException($exception);
/**
* Logs the given exception
......
......@@ -184,9 +184,7 @@ class Formatter extends Component
return $this->nullDisplay;
}
return str_replace('<p></p>', '',
'<p>' . preg_replace('/[\r\n]{2,}/', "</p>\n<p>", Html::encode($value)) . '</p>'
);
return str_replace('<p></p>', '', '<p>' . preg_replace('/[\r\n]{2,}/', "</p>\n<p>", Html::encode($value)) . '</p>');
}
/**
......
......@@ -181,6 +181,7 @@ class Theme extends Component
* Converts a relative file path into an absolute one using [[basePath]].
* @param string $path the relative file path to be converted.
* @return string the absolute file path
* @throws InvalidConfigException if [[baseUrl]] is not set
*/
public function getPath($path)
{
......
......@@ -107,15 +107,26 @@ class MemCache extends Cache
$timeout = (int) ($server->timeout / 1000) + (($server->timeout % 1000 > 0) ? 1 : 0);
if ($paramCount === 9) {
$cache->addServer(
$server->host, $server->port, $server->persistent,
$server->weight, $timeout, $server->retryInterval,
$server->status, $server->failureCallback, $server->timeout
$server->host,
$server->port,
$server->persistent,
$server->weight,
$timeout,
$server->retryInterval,
$server->status,
$server->failureCallback,
$server->timeout
);
} else {
$cache->addServer(
$server->host, $server->port, $server->persistent,
$server->weight, $timeout, $server->retryInterval,
$server->status, $server->failureCallback
$server->host,
$server->port,
$server->persistent,
$server->weight,
$timeout,
$server->retryInterval,
$server->status,
$server->failureCallback
);
}
}
......
......@@ -252,10 +252,12 @@ class CaptchaAction extends Action
{
$image = imagecreatetruecolor($this->width, $this->height);
$backColor = imagecolorallocate($image,
$backColor = imagecolorallocate(
$image,
(int) ($this->backColor % 0x1000000 / 0x10000),
(int) ($this->backColor % 0x10000 / 0x100),
$this->backColor % 0x100);
$this->backColor % 0x100
);
imagefilledrectangle($image, 0, 0, $this->width, $this->height, $backColor);
imagecolordeallocate($image, $backColor);
......@@ -263,10 +265,12 @@ class CaptchaAction extends Action
imagecolortransparent($image, $backColor);
}
$foreColor = imagecolorallocate($image,
$foreColor = imagecolorallocate(
$image,
(int) ($this->foreColor % 0x1000000 / 0x10000),
(int) ($this->foreColor % 0x10000 / 0x100),
$this->foreColor % 0x100);
$this->foreColor % 0x100
);
$length = strlen($code);
$box = imagettfbbox(30, 0, $this->fontFile, $code);
......
......@@ -89,8 +89,9 @@ class FixtureController extends Controller
}
if (!$foundFixtures) {
throw new Exception("No files were found by name: \"" . implode(', ', $fixtures) . "\".\n"
. "Check that files with these name exists, under fixtures path: \n\"" . $this->getFixturePath() . "\"."
throw new Exception(
"No files were found by name: \"" . implode(', ', $fixtures) . "\".\n" .
"Check that files with these name exists, under fixtures path: \n\"" . $this->getFixturePath() . "\"."
);
}
......@@ -131,8 +132,9 @@ class FixtureController extends Controller
}
if (!$foundFixtures) {
throw new Exception("No files were found by name: \"" . implode(', ', $fixtures) . "\".\n"
. "Check that fixtures with these name exists, under fixtures path: \n\"" . $this->getFixturePath() . "\"."
throw new Exception(
"No files were found by name: \"" . implode(', ', $fixtures) . "\".\n" .
"Check that fixtures with these name exists, under fixtures path: \n\"" . $this->getFixturePath() . "\"."
);
}
......
......@@ -253,7 +253,10 @@ class MessageController extends Controller
foreach ($translator as $currentTranslator) {
$n = preg_match_all(
'/\b' . $currentTranslator . '\s*\(\s*(\'.*?(?<!\\\\)\'|".*?(?<!\\\\)")\s*,\s*(\'.*?(?<!\\\\)\'|".*?(?<!\\\\)")\s*[,\)]/s',
$subject, $matches, PREG_SET_ORDER);
$subject,
$matches,
PREG_SET_ORDER
);
for ($i = 0; $i < $n; ++$i) {
if (($pos = strpos($matches[$i][1], '.')) !== false) {
$category = substr($matches[$i][1], $pos + 1, -1);
......
......@@ -95,7 +95,8 @@ class MigrateController extends Controller
*/
public function options($actionId)
{
return array_merge(parent::options($actionId),
return array_merge(
parent::options($actionId),
['migrationPath', 'migrationTable', 'db'], // global for all actions
($actionId == 'create') ? ['templateFile'] : [] // action create
);
......
......@@ -159,6 +159,7 @@ trait ActiveQueryTrait
{
$primaryModel = new $this->modelClass;
$relations = $this->normalizeRelations($primaryModel, $with);
/** @var ActiveQuery $relation */
foreach ($relations as $name => $relation) {
if ($relation->asArray === null) {
// inherit asArray from primary query
......
......@@ -16,6 +16,10 @@ use yii\base\InvalidParamException;
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Carsten Brandt <mail@cebe.cc>
* @since 2.0
*
* @method ActiveRelationTrait one()
* @method ActiveRelationTrait[] all()
* @property ActiveRecord $modelClass
*/
trait ActiveRelationTrait
{
......@@ -248,12 +252,20 @@ trait ActiveRelationTrait
}
}
/**
* @param ActiveRecordInterface[] $primaryModels primary models
* @param ActiveRecordInterface[] $models models
* @param string $primaryName the primary relation name
* @param string $name the relation name
* @return null
*/
private function populateInverseRelation(&$primaryModels, $models, $primaryName, $name)
{
if (empty($models) || empty($primaryModels)) {
return;
}
$model = reset($models);
/** @var ActiveQueryInterface|ActiveQuery $relation */
$relation = $model instanceof ActiveRecordInterface ? $model->getRelation($name) : (new $this->modelClass)->getRelation($name);
if ($relation->multiple) {
......
......@@ -145,6 +145,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
* @param string|array $condition the conditions that will be put in the WHERE part of the UPDATE SQL.
* Please refer to [[Query::where()]] on how to specify this parameter.
* @return integer the number of rows updated
* @throws NotSupportedException if not overrided
*/
public static function updateAll($attributes, $condition = '')
{
......@@ -164,6 +165,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
* @param string|array $condition the conditions that will be put in the WHERE part of the UPDATE SQL.
* Please refer to [[Query::where()]] on how to specify this parameter.
* @return integer the number of rows updated
* @throws NotSupportedException if not overrided
*/
public static function updateAllCounters($counters, $condition = '')
{
......@@ -184,6 +186,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
* Please refer to [[Query::where()]] on how to specify this parameter.
* @param array $params the parameters (name => value) to be bound to the query.
* @return integer the number of rows deleted
* @throws NotSupportedException if not overrided
*/
public static function deleteAll($condition = '', $params = [])
{
......@@ -908,6 +911,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
*/
public function refresh()
{
/** @var ActiveQuery $record */
$record = $this->findOne($this->getPrimaryKey(true));
if ($record === null) {
return false;
......
......@@ -528,14 +528,17 @@ class Connection extends Component
*/
public function quoteSql($sql)
{
return preg_replace_callback('/(\\{\\{(%?[\w\-\. ]+%?)\\}\\}|\\[\\[([\w\-\. ]+)\\]\\])/',
return preg_replace_callback(
'/(\\{\\{(%?[\w\-\. ]+%?)\\}\\}|\\[\\[([\w\-\. ]+)\\]\\])/',
function ($matches) {
if (isset($matches[3])) {
return $this->quoteColumnName($matches[3]);
} else {
return str_replace('%', $this->tablePrefix, $this->quoteTableName($matches[2]));
}
}, $sql);
},
$sql
);
}
/**
......
......@@ -263,7 +263,7 @@ class Container extends Component
*/
public function setSingleton($class, $definition = [], array $params = [])
{
$this->_definitions[$class] = $this->normalizeDefinition($class, $definition);;
$this->_definitions[$class] = $this->normalizeDefinition($class, $definition);
$this->_params[$class] = $params;
$this->_singletons[$class] = null;
return $this;
......
......@@ -142,8 +142,7 @@ class DataColumn extends Column
if (is_string($this->filter)) {
return $this->filter;
} elseif ($this->filter !== false && $this->grid->filterModel instanceof Model &&
$this->attribute !== null && $this->grid->filterModel->isAttributeActive($this->attribute))
{
$this->attribute !== null && $this->grid->filterModel->isAttributeActive($this->attribute)) {
if (is_array($this->filter)) {
$options = array_merge(['prompt' => ''], $this->filterInputOptions);
return Html::activeDropDownList($this->grid->filterModel, $this->attribute, $this->filter, $options);
......
......@@ -341,6 +341,7 @@ class BaseConsole
function ($ansi) use (&$tags) {
$styleA = [];
foreach (explode(';', $ansi) as $controlCode) {
$style = [];
switch ($controlCode) {
case self::FG_BLACK:
$style = ['color' => '#000000'];
......
......@@ -500,10 +500,14 @@ class BaseInflector
return $number . 'th';
}
switch ($number % 10) {
case 1: return $number . 'st';
case 2: return $number . 'nd';
case 3: return $number . 'rd';
default: return $number . 'th';
case 1:
return $number . 'st';
case 2:
return $number . 'nd';
case 3:
return $number . 'rd';
default:
return $number . 'th';
}
}
}
......@@ -344,7 +344,8 @@ class MessageFormatter extends Component
return $arg;
}
throw new NotSupportedException("Message format 'number' is only supported for integer values. You have to install PHP intl extension to use this feature.");
case 'none': return $arg;
case 'none':
return $arg;
case 'select':
/* http://icu-project.org/apiref/icu4c/classicu_1_1SelectFormat.html
selectStyle = (selector '{' message '}')+
......
......@@ -29,7 +29,7 @@ class SyslogTarget extends Target
/**
* @var array syslog levels
*/
private $syslogLevels = [
private $_syslogLevels = [
Logger::LEVEL_TRACE => LOG_DEBUG,
Logger::LEVEL_PROFILE_BEGIN => LOG_DEBUG,
Logger::LEVEL_PROFILE_END => LOG_DEBUG,
......@@ -45,7 +45,7 @@ class SyslogTarget extends Target
{
openlog($this->identity, LOG_ODELAY | LOG_PID, $this->facility);
foreach ($this->messages as $message) {
syslog($this->syslogLevels[$message[1]], $this->formatMessage($message));
syslog($this->_syslogLevels[$message[1]], $this->formatMessage($message));
}
closelog();
}
......
......@@ -161,15 +161,24 @@ class CompareValidator extends Validator
protected function compareValues($operator, $value, $compareValue)
{
switch ($operator) {
case '==': return $value == $compareValue;
case '===': return $value === $compareValue;
case '!=': return $value != $compareValue;
case '!==': return $value !== $compareValue;
case '>': return $value > $compareValue;
case '>=': return $value >= $compareValue;
case '<': return $value < $compareValue;
case '<=': return $value <= $compareValue;
default: return false;
case '==':
return $value == $compareValue;
case '===':
return $value === $compareValue;
case '!=':
return $value != $compareValue;
case '!==':
return $value !== $compareValue;
case '>':
return $value > $compareValue;
case '>=':
return $value >= $compareValue;
case '<':
return $value < $compareValue;
case '<=':
return $value <= $compareValue;
default:
return false;
}
}
......
<?php
/**
* @var \Exception $exception
* @var \yii\base\Exception $exception
* @var \yii\web\ErrorHandler $handler
*/
if ($exception instanceof \yii\web\HttpException) {
......@@ -22,8 +22,11 @@ if ($exception instanceof \yii\base\UserException) {
} else {
$message = 'An internal server error occurred.';
}
if (method_exists($this, 'beginPage')) {
$this->beginPage();
}
?>
<?php if (method_exists($this, 'beginPage')) $this->beginPage(); ?>
<!DOCTYPE html>
<html>
<head>
......@@ -80,7 +83,14 @@ if ($exception instanceof \yii\base\UserException) {
<div class="version">
<?= date('Y-m-d H:i:s', time()) ?>
</div>
<?php if (method_exists($this, 'endBody')) $this->endBody(); // to allow injecting code into body (mostly by Yii Debug Toolbar) ?>
<?php
if (method_exists($this, 'endBody')) {
$this->endBody(); // to allow injecting code into body (mostly by Yii Debug Toolbar)
}
?>
</body>
</html>
<?php if (method_exists($this, 'endPage')) $this->endPage(); ?>
<?php
if (method_exists($this, 'endPage')) {
$this->endPage();
}
\ No newline at end of file
......@@ -70,7 +70,7 @@ class ViewAction extends Action
$viewName = $this->resolveViewName();
$controllerLayout = null;
if($this->layout !== null) {
if ($this->layout !== null) {
$controllerLayout = $this->controller->layout;
$this->controller->layout = $this->layout;
}
......
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