Skip to content

Commit

Permalink
php-cs-fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
hiqsol committed Aug 26, 2015
1 parent 427dc71 commit fb39db4
Show file tree
Hide file tree
Showing 13 changed files with 521 additions and 332 deletions.
43 changes: 43 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

$header = <<<EOF
Tools to use API as ActiveRecord for Yii2
@link https://github.com/hiqdev/yii2-hiart
@package yii2-hiart
@license BSD-3-Clause
@copyright Copyright (c) 2015, HiQDev (https://hiqdev.com/)
EOF;

Symfony\CS\Fixer\Contrib\HeaderCommentFixer::setHeader($header);

return Symfony\CS\Config\Config::create()
->level(Symfony\CS\FixerInterface::SYMFONY_LEVEL)
->fixers([
'-long_array_syntax', /// Arrays should use the long syntax.
'-php4_constructor', /// Convert PHP4-style constructors to __construct. Warning! This could change code behavior.
'-phpdoc_var_to_type', /// @var should always be written as @type.
'header_comment', /// Add, replace or remove header comment.
'align_double_arrow', /// Align double arrow symbols in consecutive lines.
'align_equals', /// Align equals symbols in consecutive lines.
'concat_with_spaces', /// Concatenation should be used with at least one whitespace around.
'ereg_to_preg', /// Replace deprecated ereg regular expression functions with preg. Warning! This could change code behavior.
'multiline_spaces_before_semicolon', /// Multi-line whitespace before closing semicolon are prohibited.
'newline_after_open_tag', /// Ensure there is no code on the same line as the PHP open tag.
'single_blank_line_before_namespace', /// There should be no blank lines before a namespace declaration.
'ordered_use', /// Ordering use statements.
'phpdoc_order', /// Annotations in phpdocs should be ordered so that @param come first, then @throws, then @return.
'pre_increment', /// Pre incrementation/decrementation should be used if possible.
'short_array_syntax', /// PHP arrays should use the PHP 5.4 short-syntax.
'strict', /// Comparison should be strict. Warning! This could change code behavior.
'strict_param', /// Functions should be used with $strict param. Warning! This could change code behavior.
])
->finder(
Symfony\CS\Finder\DefaultFinder::create()
->in(__DIR__)
->notPath('vendor')
->notPath('runtime')
->notPath('web/assets')
->notPath('tests/unit/UnitTester.php')
)
;
14 changes: 8 additions & 6 deletions src/ActiveDataProvider.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<?php
/**
* @link http://hiqdev.com/yii2-hiart
* @license http://hiqdev.com/yii2-hiart/license
* @copyright Copyright (c) 2015 HiQDev

/*
* Tools to use API as ActiveRecord for Yii2
*
* @link https://github.com/hiqdev/yii2-hiart
* @package yii2-hiart
* @license BSD-3-Clause
* @copyright Copyright (c) 2015, HiQDev (https://hiqdev.com/)
*/

namespace hiqdev\hiart;


class ActiveDataProvider extends \yii\data\ActiveDataProvider
{

}
64 changes: 38 additions & 26 deletions src/ActiveQuery.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<?php
/**
* @link http://hiqdev.com/yii2-hiart
* @copyright Copyright (c) 2015 HiQDev
* @license http://hiqdev.com/yii2-hiart/license

/*
* Tools to use API as ActiveRecord for Yii2
*
* @link https://github.com/hiqdev/yii2-hiart
* @package yii2-hiart
* @license BSD-3-Clause
* @copyright Copyright (c) 2015, HiQDev (https://hiqdev.com/)
*/

namespace hiqdev\hiart;

use common\components\Err;
use hipanel\base\Re;
use yii\db\ActiveQueryInterface;
use yii\db\ActiveQueryTrait;
Expand All @@ -24,14 +27,14 @@ class ActiveQuery extends Query implements ActiveQueryInterface
*/
const EVENT_INIT = 'init';


/**
* 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 = []) {
public function __construct($modelClass, $config = [])
{
$this->modelClass = $modelClass;
parent::__construct($config);
}
Expand All @@ -42,7 +45,8 @@ public function __construct ($modelClass, $config = []) {
* an [[EVENT_INIT]] event. If you override this method, make sure you call the parent implementation at the end
* to ensure triggering of the event.
*/
public function init () {
public function init()
{
parent::init();
$this->trigger(self::EVENT_INIT);
}
Expand All @@ -51,10 +55,12 @@ public function init () {
* Creates a DB command that can be used to execute this query.
*
* @param Connection $db the DB connection used to create the DB command.
* If null, the DB connection returned by [[modelClass]] will be used.
* If null, the DB connection returned by [[modelClass]] will be used.
*
* @return Command the created DB command instance.
*/
public function createCommand ($db = null) {
public function createCommand($db = null)
{
if ($this->primaryModel !== null) {
// lazy loading
if (is_array($this->via)) {
Expand Down Expand Up @@ -89,7 +95,6 @@ public function createCommand ($db = null) {
$this->type = $modelClass::type();
}


$commandConfig = $db->getQueryBuilder()->build($this);

return $db->createCommand($commandConfig);
Expand All @@ -99,10 +104,12 @@ public function createCommand ($db = null) {
* Executes query and returns all results as an array.
*
* @param Connection $db the DB connection used to create the DB command.
* If null, the DB connection returned by [[modelClass]] will be used.
* If null, the DB connection returned by [[modelClass]] will be used.
*
* @return array the query results. If the query results in nothing, an empty array will be returned.
*/
public function all ($db = null) {
public function all($db = null)
{
if ($this->asArray) {
// TODO implement with
return parent::all($db);
Expand Down Expand Up @@ -130,16 +137,18 @@ public function all ($db = null) {
* Executes query and returns a single row of result.
*
* @param Connection $db the DB connection used to create the DB command.
* If null, the DB connection returned by [[modelClass]] will be used.
* If null, the DB connection returned by [[modelClass]] will be used.
*
* @return ActiveRecord|array|null a single row of query result. Depending on the setting of [[asArray]],
* the query result may be either an array or an ActiveRecord object. Null will be returned
* if the query results in nothing.
* the query result may be either an array or an ActiveRecord object. Null will be returned
* if the query results in nothing.
*/
public function one ($db = null) {
// $result = $this->createCommand($db)->get();
public function one($db = null)
{
// $result = $this->createCommand($db)->get();

if (($result = parent::one($db)) === false) {
return null;
return;
}
if ($this->asArray) {
// TODO implement with()
Expand Down Expand Up @@ -174,9 +183,10 @@ public function one ($db = null) {
}

/**
* @inheritdoc
* {@inheritdoc}
*/
public function search ($db = null, $options = []) {
public function search($db = null, $options = [])
{
$result = $this->createCommand($db)->search($options);
// TODO implement with() for asArray
if (!empty($result) && !$this->asArray) {
Expand All @@ -194,10 +204,11 @@ public function search ($db = null, $options = []) {
}

/**
* @inheritdoc
* {@inheritdoc}
*/
public function column ($field, $db = null) {
if ($field == '_id') {
public function column($field, $db = null)
{
if ($field === '_id') {
$command = $this->createCommand($db);
$command->queryParts['fields'] = [];
$command->queryParts['_source'] = false;
Expand All @@ -216,7 +227,8 @@ public function column ($field, $db = null) {
return parent::column($field, $db);
}

public function getList ($as_array = true, $db = null, $options = []) {
public function getList($as_array = true, $db = null, $options = [])
{
$rawResult = $this->createCommand($db)->getList($options);
foreach ($rawResult as $k => $v) {
$result[] = ['gl_key' => $k, 'gl_value' => $v];
Expand Down
Loading

0 comments on commit fb39db4

Please sign in to comment.