Skip to content

Commit

Permalink
php-cs-fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
hiqsol committed Oct 26, 2015
1 parent 1a364dd commit 3d51603
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 49 deletions.
43 changes: 25 additions & 18 deletions src/ActiveQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ActiveQuery extends Query implements ActiveQueryInterface
* Constructor.
*
* @param array $modelClass the model class associated with this query
* @param array $config configurations to be applied to the newly created query object
* @param array $config configurations to be applied to the newly created query object
*/
public function __construct($modelClass, $config = [])
{
Expand Down Expand Up @@ -102,7 +102,7 @@ public function createCommand($db = null)
}
if ($this->index === null) {
$this->index = $modelClass::index();
$this->type = $modelClass::type();
$this->type = $modelClass::type();
}

$commandConfig = $db->getQueryBuilder()->build($this);
Expand All @@ -111,7 +111,7 @@ public function createCommand($db = null)
}

/**
* @inheritdoc
* {@inheritdoc}
*/
public function prepare()
{
Expand All @@ -127,7 +127,7 @@ public function prepare()

public function joinWith($with)
{
$this->joinWith[] = [(array)$with, true];
$this->joinWith[] = [(array) $with, true];

return $this;
}
Expand All @@ -139,7 +139,7 @@ private function buildJoinWith()
$this->join = [];

foreach ($this->joinWith as $config) {
list ($with, $eagerLoading) = $config;
list($with, $eagerLoading) = $config;

foreach ($with as $name => $callback) {
if (is_int($name)) {
Expand Down Expand Up @@ -176,6 +176,7 @@ private function buildJoinWith()
public function select($columns)
{
$this->select = $columns;

return $this;
}

Expand All @@ -186,6 +187,7 @@ public function addSelect($columns)
} else {
$this->select = array_merge($this->select, $columns);
}

return $this;
}

Expand Down Expand Up @@ -242,15 +244,15 @@ private function createModels($rows)
$class = $this->modelClass;
if ($this->indexBy === null) {
foreach ($rows as $row) {
$model = $class::instantiate($row);
$model = $class::instantiate($row);
$modelClass = get_class($model);
$modelClass::populateRecord($model, $row);
$this->populateJoinedRelations($model, $row);
$models[] = $model;
}
} else {
foreach ($rows as $row) {
$model = $class::instantiate($row);
$model = $class::instantiate($row);
$modelClass = get_class($model);
$modelClass::populateRecord($model, $row);
if (is_string($this->indexBy)) {
Expand All @@ -270,27 +272,32 @@ private function createModels($rows)
* Populates joined relations from [[join]] array.
*
* @param ActiveRecord $model
* @param array $row
* @param array $row
*/
public function populateJoinedRelations($model, array $row) {
public function populateJoinedRelations($model, array $row)
{
foreach ($row as $key => $value) {
if (empty($this->join) || !is_array($value) || $model->hasAttribute($key)) continue;
if (empty($this->join) || !is_array($value) || $model->hasAttribute($key)) {
continue;
}
foreach ($this->join as $name) {
if ($model->isRelationPopulated($name)) continue 2;
$records = [];
$relation = $model->getRelation($name);
if ($model->isRelationPopulated($name)) {
continue 2;
}
$records = [];
$relation = $model->getRelation($name);
$relationClass = $relation->modelClass;

if ($relation->multiple) {
foreach ($value as $item) {
$relationModel = $relationClass::instantiate($item);
$relationModel = $relationClass::instantiate($item);
$relationModelClass = get_class($relationModel);
$relationModelClass::populateRecord($relationModel, $item);
$relation->populateJoinedRelations($relationModel, $item);
$records[] = $relationModel;
}
} else {
$relationModel = $relationClass::instantiate($value);
$relationModel = $relationClass::instantiate($value);
$relationModelClass = get_class($relationModel);
$relationModelClass::populateRecord($relationModel, $value);
$relation->populateJoinedRelations($relationModel, $value);
Expand Down Expand Up @@ -378,10 +385,10 @@ public function search($db = null, $options = [])
public function column($field, $db = null)
{
if ($field === '_id') {
$command = $this->createCommand($db);
$command->queryParts['fields'] = [];
$command = $this->createCommand($db);
$command->queryParts['fields'] = [];
$command->queryParts['_source'] = false;
$result = $command->search();
$result = $command->search();
if (empty($result['hits']['hits'])) {
return [];
}
Expand Down
35 changes: 19 additions & 16 deletions src/ActiveRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function isScenarioDefault()
* Gets a record by its primary key.
*
* @param mixed $primaryKey the primaryKey value
* @param array $options options given in this parameter are passed to API.
* @param array $options options given in this parameter are passed to API.
*
* @return null|static The record instance or null if it was not found.
*/
Expand All @@ -75,7 +75,7 @@ public static function get($primaryKey = null, $options = [])
return;
}
$command = static::getDb()->createCommand();
$result = $command->get(static::type(), $primaryKey, $options);
$result = $command->get(static::type(), $primaryKey, $options);

if ($result) {
$model = static::instantiate($result);
Expand Down Expand Up @@ -207,16 +207,18 @@ public static function joinIndex()
* depends on the row data to be populated into the record.
* For example, by creating a record based on the value of a column,
* you may implement the so-called single-table inheritance mapping.
*
* @param array $row row data to be populated into the record.
* This array consists of the following keys:
* - `_source`: refers to the attributes of the record.
* - `_type`: the type this record is stored in.
* - `_index`: the index this record is stored in.
* This array consists of the following keys:
* - `_source`: refers to the attributes of the record.
* - `_type`: the type this record is stored in.
* - `_index`: the index this record is stored in.
*
* @return static the newly created active record
*/
public static function instantiate($row)
{
return new static;
return new static();
}

/**
Expand Down Expand Up @@ -251,11 +253,11 @@ public function insert($runValidation = true, $attributes = null, $options = [])
$values = $this->getDirtyAttributes($attributes);

$command = $this->getScenarioCommand('create');
$data = array_merge($values, $options, ['id' => $this->getOldPrimaryKey()]);
$data = array_merge($values, $options, ['id' => $this->getOldPrimaryKey()]);

$result = static::getDb()->createCommand()->perform($command, $data);

$pk = static::primaryKey()[0];
$pk = static::primaryKey()[0];
$this->$pk = $result['id'];
if ($pk !== 'id') {
$values[$pk] = $result['id'];
Expand All @@ -274,7 +276,7 @@ public function delete($options = [])
}

$command = $this->getScenarioCommand('delete');
$data = array_merge($options, ['id' => $this->getOldPrimaryKey()]);
$data = array_merge($options, ['id' => $this->getOldPrimaryKey()]);

$result = static::getDb()->createCommand()->perform($command, $data);

Expand Down Expand Up @@ -313,9 +315,9 @@ protected function updateInternal($attributes = null, $options = [])
}

$command = $this->getScenarioCommand('update');
$data = array_merge($values, $options, ['id' => $this->getOldPrimaryKey()]);
$data = array_merge($values, $options, ['id' => $this->getOldPrimaryKey()]);

$result = static::getDb()->createCommand()->perform($command, $data);
$result = static::getDb()->createCommand()->perform($command, $data);
$changedAttributes = [];
foreach ($values as $name => $value) {
$changedAttributes[$name] = $this->getOldAttribute($name);
Expand All @@ -332,7 +334,7 @@ protected function updateInternal($attributes = null, $options = [])
*
* @param $action
* @param array $options
* @param bool $bulk
* @param bool $bulk
*
* @return array
*/
Expand All @@ -348,7 +350,7 @@ public static function perform($action, $options = [], $bulk = false)
* Creates the command name for the specified scenario name.
*
* @param string $default
* @param bool $bulk
* @param bool $bulk
*
* @throws InvalidConfigException
* @throws NotSupportedException
Expand Down Expand Up @@ -429,7 +431,7 @@ public function getIsNewRecord()
*/
public function optimisticLock()
{
return null;
return;
}

/**
Expand All @@ -444,8 +446,9 @@ public function unlinkAll($name, $delete = false)

/**
* {@inheritdoc}
*
* @return ActiveQueryInterface|ActiveQuery the relational query object. If the relation does not exist
* and `$throwException` is false, null will be returned.
* and `$throwException` is false, null will be returned.
*/
public function getRelation($name, $throwException = true)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ protected function httpRequest($method, $url, $requestBody = null, $raw = false)
$body = '';
$options = [
CURLOPT_URL => $url,
CURLOPT_USERAGENT => 'Yii Framework ' . Yii::getVersion() . ' (HiArt)',
CURLOPT_USERAGENT => 'Yii Framework ' . Yii::getVersion() . ' (HiArt)',
//CURLOPT_ENCODING => 'UTF-8',
# CURLOPT_USERAGENT => 'curl/0.00 (php 5.x; U; en)',
CURLOPT_RETURNTRANSFER => false,
Expand Down
10 changes: 5 additions & 5 deletions src/DebugAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,19 @@ public function run($logId, $tag)
}
$message = $timings[$logId][1];
if (($pos = mb_strpos($message, '#')) !== false) {
$url = mb_substr($message, 0, $pos);
$url = mb_substr($message, 0, $pos);
$body = mb_substr($message, $pos + 1);
} else {
$url = $message;
$url = $message;
$body = null;
}
$method = mb_substr($url, 0, $pos = mb_strpos($url, ' '));
$url = mb_substr($url, $pos + 1);
$url = mb_substr($url, $pos + 1);

parse_str($body, $options);

/* @var $db Connection */
$db = \Yii::$app->get($this->db);
$db = \Yii::$app->get($this->db);
$time = microtime(true);
switch ($method) {
case 'GET':
Expand Down Expand Up @@ -91,7 +91,7 @@ public function run($logId, $tag)
Yii::$app->response->format = Response::FORMAT_JSON;

return [
'time' => sprintf('%.1f ms', $time * 1000),
'time' => sprintf('%.1f ms', $time * 1000),
'result' => $result,
];
}
Expand Down
4 changes: 2 additions & 2 deletions src/DebugPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ public function getDetail()
'class' => 'hiart-link',
'data' => ['id' => $i],
]) . '<br/>';
$url_encoded = Html::encode((isset($apiUrl)) ? str_replace(' ', ' ' . $apiUrl, $url) : $url);
$url_encoded = Html::encode((isset($apiUrl)) ? str_replace(' ', ' ' . $apiUrl, $url) : $url);
$body_encoded = Html::encode($body);
$rows[] = <<<HTML
$rows[] = <<<HTML
<tr>
<td style="width: 10%;">$duration</td>
<td style="width: 75%;"><div><b>$url_encoded</b><br/><p>$body_encoded</p>$traceString</div></td>
Expand Down
3 changes: 1 addition & 2 deletions src/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ class Query extends Component implements QueryInterface
public $select;
public $join;



/**
* {@inheritdoc}
*/
Expand All @@ -59,6 +57,7 @@ public function createCommand($db = null)
public function join($type)
{
$this->join[] = $type;

return $this;
}

Expand Down
16 changes: 11 additions & 5 deletions src/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ public function __construct($connection, $config = [])

/**
* @param ActiveQuery $query
* @return array
*
* @throws NotSupportedException
*
* @return array
*/
public function build($query)
{
Expand All @@ -57,7 +59,8 @@ public function build($query)
];
}

public function buildLimit ($limit, &$parts) {
public function buildLimit($limit, &$parts)
{
if (!empty($limit)) {
if ($limit == -1) {
$limit = 'ALL';
Expand All @@ -66,19 +69,22 @@ public function buildLimit ($limit, &$parts) {
}
}

public function buildPage ($offset, $limit, &$parts) {
public function buildPage($offset, $limit, &$parts)
{
if ($offset > 0) {
$parts['page'] = ceil($offset / $limit) + 1;
}
}

public function buildOrderBy ($orderBy, &$parts) {
public function buildOrderBy($orderBy, &$parts)
{
if (!empty($orderBy)) {
$parts['orderby'] = key($orderBy) . $this->_sort[reset($orderBy)];
}
}

public function buildSelect ($select, &$parts) {
public function buildSelect($select, &$parts)
{
if (!empty($select)) {
foreach ($select as $attribute) {
$parts['select'][$attribute] = $attribute;
Expand Down

0 comments on commit 3d51603

Please sign in to comment.