From 1f7134634b8de22d6bac1ec2bc6f5d657f1ecb7b Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Tue, 16 Feb 2016 14:06:23 +0300 Subject: [PATCH] Use static:: instead of $this for static method calls --- framework/base/Application.php | 2 +- framework/captcha/Captcha.php | 7 +++---- framework/db/ActiveRecord.php | 10 +++++----- framework/db/BaseActiveRecord.php | 14 +++++++------- framework/log/Target.php | 2 +- 5 files changed, 17 insertions(+), 18 deletions(-) diff --git a/framework/base/Application.php b/framework/base/Application.php index b85b8a6007..91e9ffe41d 100644 --- a/framework/base/Application.php +++ b/framework/base/Application.php @@ -195,7 +195,7 @@ abstract class Application extends Module public function __construct($config = []) { Yii::$app = $this; - $this->setInstance($this); + static::setInstance($this); $this->state = self::STATE_BEGIN; diff --git a/framework/captcha/Captcha.php b/framework/captcha/Captcha.php index e85cb352d7..26cfecc859 100644 --- a/framework/captcha/Captcha.php +++ b/framework/captcha/Captcha.php @@ -91,7 +91,7 @@ class Captcha extends InputWidget { parent::init(); - $this->checkRequirements(); + static::checkRequirements(); if (!isset($this->imageOptions['id'])) { $this->imageOptions['id'] = $this->options['id'] . '-image'; @@ -165,9 +165,8 @@ class Captcha extends InputWidget public static function checkRequirements() { if (extension_loaded('imagick')) { - $imagick = new \Imagick(); - $imagickFormats = $imagick->queryFormats('PNG'); - if (in_array('PNG', $imagickFormats)) { + $imagickFormats = \Imagick::queryFormats('PNG'); + if (in_array('PNG', $imagickFormats, true)) { return 'imagick'; } } diff --git a/framework/db/ActiveRecord.php b/framework/db/ActiveRecord.php index a79e5bd286..e3270f5a98 100644 --- a/framework/db/ActiveRecord.php +++ b/framework/db/ActiveRecord.php @@ -114,7 +114,7 @@ class ActiveRecord extends BaseActiveRecord */ public function loadDefaultValues($skipIfSet = true) { - foreach ($this->getTableSchema()->columns as $column) { + foreach (static::getTableSchema()->columns as $column) { if ($column->defaultValue !== null && (!$skipIfSet || $this->{$column->name} === null)) { $this->{$column->name} = $column->defaultValue; } @@ -454,11 +454,11 @@ class ActiveRecord extends BaseActiveRecord return false; } $values = $this->getDirtyAttributes($attributes); - if (($primaryKeys = static::getDb()->schema->insert($this->tableName(), $values)) === false) { + if (($primaryKeys = static::getDb()->schema->insert(static::tableName(), $values)) === false) { return false; } foreach ($primaryKeys as $name => $value) { - $id = $this->getTableSchema()->columns[$name]->phpTypecast($value); + $id = static::getTableSchema()->columns[$name]->phpTypecast($value); $this->setAttribute($name, $id); $values[$name] = $id; } @@ -607,7 +607,7 @@ class ActiveRecord extends BaseActiveRecord if ($lock !== null) { $condition[$lock] = $this->$lock; } - $result = $this->deleteAll($condition); + $result = static::deleteAll($condition); if ($lock !== null && !$result) { throw new StaleObjectException('The object being deleted is outdated.'); } @@ -630,7 +630,7 @@ class ActiveRecord extends BaseActiveRecord return false; } - return $this->tableName() === $record->tableName() && $this->getPrimaryKey() === $record->getPrimaryKey(); + return static::tableName() === $record->tableName() && $this->getPrimaryKey() === $record->getPrimaryKey(); } /** diff --git a/framework/db/BaseActiveRecord.php b/framework/db/BaseActiveRecord.php index d06f9ef09c..11f239104f 100644 --- a/framework/db/BaseActiveRecord.php +++ b/framework/db/BaseActiveRecord.php @@ -688,7 +688,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface return 0; } - $rows = $this->updateAll($values, $this->getOldPrimaryKey(true)); + $rows = static::updateAll($values, $this->getOldPrimaryKey(true)); foreach ($values as $name => $value) { $this->_oldAttributes[$name] = $this->_attributes[$name]; @@ -721,7 +721,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface } // We do not check the return value of updateAll() because it's possible // that the UPDATE statement doesn't change anything and thus returns 0. - $rows = $this->updateAll($values, $condition); + $rows = static::updateAll($values, $condition); if ($lock !== null && !$rows) { throw new StaleObjectException('The object being updated is outdated.'); @@ -760,7 +760,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface */ public function updateCounters($counters) { - if ($this->updateAllCounters($counters, $this->getOldPrimaryKey(true)) > 0) { + if (static::updateAllCounters($counters, $this->getOldPrimaryKey(true)) > 0) { foreach ($counters as $name => $value) { if (!isset($this->_attributes[$name])) { $this->_attributes[$name] = $value; @@ -805,7 +805,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface if ($lock !== null) { $condition[$lock] = $this->$lock; } - $result = $this->deleteAll($condition); + $result = static::deleteAll($condition); if ($lock !== null && !$result) { throw new StaleObjectException('The object being deleted is outdated.'); } @@ -957,7 +957,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface public function refresh() { /* @var $record BaseActiveRecord */ - $record = $this->findOne($this->getPrimaryKey(true)); + $record = static::findOne($this->getPrimaryKey(true)); if ($record === null) { return false; } @@ -1212,7 +1212,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface } } else { $p1 = $model->isPrimaryKey(array_keys($relation->link)); - $p2 = $this->isPrimaryKey(array_values($relation->link)); + $p2 = static::isPrimaryKey(array_values($relation->link)); if ($p1 && $p2) { if ($this->getIsNewRecord() && $model->getIsNewRecord()) { throw new InvalidCallException('Unable to link models: at most one model can be newly created.'); @@ -1302,7 +1302,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface } } else { $p1 = $model->isPrimaryKey(array_keys($relation->link)); - $p2 = $this->isPrimaryKey(array_values($relation->link)); + $p2 = static::isPrimaryKey(array_values($relation->link)); if ($p2) { foreach ($relation->link as $a => $b) { $model->$a = null; diff --git a/framework/log/Target.php b/framework/log/Target.php index a74329efe2..9eda466e27 100644 --- a/framework/log/Target.php +++ b/framework/log/Target.php @@ -99,7 +99,7 @@ abstract class Target extends Component */ public function collect($messages, $final) { - $this->messages = array_merge($this->messages, $this->filterMessages($messages, $this->getLevels(), $this->categories, $this->except)); + $this->messages = array_merge($this->messages, static::filterMessages($messages, $this->getLevels(), $this->categories, $this->except)); $count = count($this->messages); if ($count > 0 && ($final || $this->exportInterval > 0 && $count >= $this->exportInterval)) { if (($context = $this->getContextMessage()) !== '') {