Skip to content

Commit

Permalink
Apply fixes from StyleCI (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
lichunqiang authored May 10, 2017
1 parent 4f18b06 commit 9d0dc53
Show file tree
Hide file tree
Showing 208 changed files with 799 additions and 755 deletions.
16 changes: 8 additions & 8 deletions api/components/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,33 @@ protected function renderException($exception)
} else {
$response = new Response();
}

//force return json format exception
$response->format = Response::FORMAT_JSON;
// if ($exception instanceof SystemException) {

// $response->send();
// }
$response->data = $this->convertExceptionToArray($exception);

if ($exception instanceof HttpException) {
$response->setStatusCode($exception->statusCode);
} else {
$response->setStatusCode(500);
}

$response->send();
}

/**
* @inheritdoc
* {@inheritdoc}
*/
protected function convertExceptionToArray($exception)
{
if (!YII_DEBUG && !$exception instanceof UserException && !$exception instanceof HttpException) {
$exception = new HttpException(500, 'There was an error at the server.');
}

$array = [
// 'name' => $exception->getName() ?: 'Exception',
'errmsg' => $exception->getMessage(),
Expand All @@ -77,7 +77,7 @@ protected function convertExceptionToArray($exception)
$array['data']['previous'] = $this->convertExceptionToArray($prev);
}
}

return $array;
}
}
2 changes: 1 addition & 1 deletion api/components/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class Setup implements BootstrapInterface
{
/**
* @inheritdoc
* {@inheritdoc}
*/
public function bootstrap($app)
{
Expand Down
6 changes: 2 additions & 4 deletions api/components/behaviors/FormatResponseBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace api\components\behaviors;

use Yii;
use yii\base\Behavior;
use yii\web\Response;

Expand All @@ -20,9 +19,9 @@ public function events()
Response::EVENT_BEFORE_SEND => 'formatResponse',
];
}

/**
* @param \yii\base\Event $event
* @param \yii\base\Event $event
*/
public function formatResponse($event)
{
Expand All @@ -32,7 +31,6 @@ public function formatResponse($event)
$headers->set('Access-Control-Allow-Origin', '*');
//format response
if ('html' !== $response->format) {

if (!isset($response->data['errcode'])) {
if ($response->data !== null) {
$response->data = [
Expand Down
2 changes: 1 addition & 1 deletion api/config/i18n.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
'/messages',
'/runtime',
'.md',
'/config'
'/config',
],

// 'php' output format is for saving messages to php files.
Expand Down
1 change: 0 additions & 1 deletion api/config/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,3 @@
require(__DIR__ . '/params.php')
),
];

11 changes: 7 additions & 4 deletions api/controllers/SiteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ class SiteController extends Controller
{
use MethodInjectionTrait;
/**
* @inheritdoc
* {@inheritdoc}
*/
public $enableCsrfValidation = false;

/**
* @inheritdoc
* {@inheritdoc}
*/
public function actions()
{
Expand All @@ -38,16 +38,18 @@ public function actions()
}

/**
* @inheritdoc
* {@inheritdoc}
*/
public function beforeAction($action)
{
if (parent::beforeAction($action)) {
if ('api' == $action->id) {
if ('api' === $action->id) {
app()->response->detachBehavior('beforeSend');
}

return true;
}

return false;
}

Expand All @@ -60,6 +62,7 @@ public function actionCreate()
{
app()->response->format = \yii\web\Response::FORMAT_JSON;
$resutl = app()->request->bodyParams;

return ['tr' => $resutl, 'xx' => app()->request->post(), 'get' => app()->request->get()];
}

Expand Down
1 change: 1 addition & 0 deletions api/controllers/TestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public function actionIndex()
public function actionCreate()
{
$result = app()->request->bodyParams;

return [
'body' => $result,
'post' => app()->request->post(),
Expand Down
16 changes: 6 additions & 10 deletions api/modules/v1/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,27 @@

use Yii;

/**
*
* @package api\modules\v1
*/
final class Module extends \yii\base\Module
{
public $controllerNamespace = 'api\modules\v1\controllers';

public function init()
{
parent::init();

//Yii::$app->getUser()->identityClass = 'api\modules\v1\models\User';

//finder model classes
//$this->initFinderModelClass();
}

/**
* Init finder model class
* Init finder model class.
*/
protected function initFinderModelClass()
{
$container = Yii::$container;

//$container->set(TweetFinder::class, ['modelClass' => 'api\modules\v1\models\Tweet']);
}
}
19 changes: 13 additions & 6 deletions api/modules/v1/controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@
* ),
* @SWG\Response(response = 200, description = "success")
* )
*
*/
class AuthController extends Controller
{
Expand All @@ -108,6 +107,7 @@ public function behaviors()
{
$behaviors = parent::behaviors();
unset($behaviors['authenticator']);

return $behaviors;
}

Expand All @@ -122,6 +122,7 @@ public function actions()
'phoneCheckCallback' => function ($tel) {
if (User::checkPhoneIsRegisted($tel)) {
$this->sendFaildValidation(t('app', '{phone} had been registed.', ['phone' => $tel]));

return false;
}
},
Expand All @@ -131,6 +132,7 @@ public function actions()
'phoneCheckCallback' => function ($tel) {
if (!User::checkPhoneIsRegisted($tel)) {
$this->sendFaildValidation(t('app', '{phone} has not registed.', ['phone' => $tel]));

return false;
}
},
Expand All @@ -149,6 +151,7 @@ public function actions()
}
$user->generatePasswordResetToken();
$user->update();

return $user->password_reset_token;
},
],
Expand Down Expand Up @@ -180,6 +183,7 @@ public function actions()
* ),
* @SWG\Response(response = 200, description = "Login Success")
* )
*
* @param LoginForm $form
*
* @return $this|array
Expand Down Expand Up @@ -254,14 +258,17 @@ public function actionLogin(LoginForm $form)
* ),
* @SWG\Response(response = 200, description = "success")
* )
*
* @param RegisterForm $form
*
* @return $this|array|User|\common\models\UserProfile
*
* @throws \common\exceptions\SystemException
*/
public function actionRegister(RegisterForm $form)
{
$form->load(app()->request->post());

return $form->register();
}

Expand Down Expand Up @@ -293,9 +300,6 @@ public function actionRegister(RegisterForm $form)
* ),
* @SWG\Response(response = 200, description = "success")
* )
*
*
* @return null
*/
public function actionResetPassword()
{
Expand Down Expand Up @@ -326,7 +330,7 @@ public function actionResetPassword()
}

/**
* 用户鉴权接口
* 用户鉴权接口.
*
* @SWG\Post(
* path = "/auth/query",
Expand All @@ -345,7 +349,9 @@ public function actionResetPassword()
* ),
* @SWG\Response(response = 200, description = "success")
* )
*
* @return mixed
*
* @throws UnauthorizedHttpException
*/
public function actionQuery()
Expand All @@ -360,11 +366,12 @@ public function actionQuery()

//更新在线状态
$user->setOnline();

return;
}

/**
* 验证手机号是否注册
* 验证手机号是否注册.
*
* @SWG\Post(
* path = "/auth/phone",
Expand Down
Loading

0 comments on commit 9d0dc53

Please sign in to comment.