Skip to content

Commit

Permalink
fix code style, require php version >= 5.5
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-chepurnoi committed Nov 22, 2016
1 parent 0ab0f7b commit d14d653
Show file tree
Hide file tree
Showing 22 changed files with 129 additions and 81 deletions.
23 changes: 23 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

$finder = Symfony\CS\Finder::create()
->exclude('vendor')
->in([__DIR__]);

$config = Symfony\CS\Config::create()
->fixers([
'-phpdoc_params',
'-phpdoc_short_description',
'-phpdoc_inline_tag',
'-pre_increment',
'-heredoc_to_nowdoc',
'-spaces_cast',
'-include',
'-phpdoc_no_package',
'concat_with_spaces',
'ordered_use',
'short_array_syntax',
])
->finder($finder);

return $config;
13 changes: 3 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
language: php

php:
- 5.4
- 5.5
- 5.6
- 7.0
- hhvm

# run build against hhvm but allow them to fail
# http://docs.travis-ci.com/user/build-configuration/#Rows-That-are-Allowed-To-Fail
matrix:
fast_finish: true
allow_failures:
- php: hhvm

# faster builds on new travis setup not using sudo
sudo: false
Expand All @@ -21,6 +12,7 @@ sudo: false
cache:
directories:
- $HOME/.composer/cache
- vendor

install:
- travis_retry composer self-update && composer --version
Expand All @@ -29,4 +21,5 @@ install:
- travis_retry composer install --prefer-dist --no-interaction

script:
- phpunit --verbose $PHPUNIT_FLAGS
- vendor/friendsofphp/php-cs-fixer/php-cs-fixer fix --dry-run --diff
- phpunit --verbose $PHPUNIT_FLAGS
12 changes: 8 additions & 4 deletions actions/PageAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

/**
* Class PageAction
*
* @package yii2mod\cms\actions
*/
class PageAction extends Action
Expand Down Expand Up @@ -39,21 +40,22 @@ class PageAction extends Action
*/
public function init()
{
parent::init();

if (empty($this->pageId)) {
$this->pageId = Yii::$app->request->get('pageId');
}

if (!empty($this->layout)) {
$this->controller->layout = $this->layout;
}

parent::init();
}

/**
* Run action
*
* @throws \yii\web\NotFoundHttpException
*
* @return string
*/
public function run()
Expand All @@ -70,6 +72,7 @@ public function run()
* Parse base template params, like {homeUrl}
*
* @param $pageContent
*
* @return string
*/
protected function parseBaseTemplateParams($pageContent)
Expand All @@ -94,14 +97,15 @@ protected function getBaseTemplateParams()
{
return ArrayHelper::merge($this->baseTemplateParams, [
'homeUrl' => Yii::$app->urlManager->baseUrl,
'siteName' => Yii::$app->name
'siteName' => Yii::$app->name,
]);
}

/**
* Find CmsModel
*
* @return null|CmsModel
*
* @throws NotFoundHttpException
*/
protected function findModel()
Expand All @@ -112,4 +116,4 @@ protected function findModel()

throw new NotFoundHttpException(Yii::t('yii2mod.cms', 'The requested page does not exist.'));
}
}
}
8 changes: 5 additions & 3 deletions components/PageUrlRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@

/**
* Class PageUrlRule
*
* @package yii2mod\cms\components
*/
class PageUrlRule extends UrlRule
{
/**
* @var string the pattern used to parse and create the path info part of a URL.
* @var string the pattern used to parse and create the path info part of a URL
*/
public $pattern = '<\w+>';

Expand All @@ -32,15 +33,16 @@ class PageUrlRule extends UrlRule
public function parseRequest($manager, $request)
{
$pathInfo = $request->getPathInfo();
$url = preg_replace("#/$#", "", $pathInfo);
$url = preg_replace('#/$#', '', $pathInfo);
$page = (new CmsModel())->findPage($url);

if (!empty($page)) {
$params['pageAlias'] = $url;
$params['pageId'] = $page->id;

return [$this->route, $params];
}

return parent::parseRequest($manager, $request);
}
}
}
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@
}
],
"require": {
"php": ">=5.5",
"yiisoft/yii2": "*",
"yii2mod/yii2-enum": "*",
"asofter/yii2-imperavi-redactor": "*",
"yii2mod/yii2-editable": "*",
"yii2mod/yii2-toggle-column": "*",
"yii2mod/yii2-comments": "*"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "~1.7"
},
"autoload": {
"psr-4": {
"yii2mod\\cms\\": ""
Expand Down
40 changes: 22 additions & 18 deletions controllers/CmsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
namespace yii2mod\cms\controllers;

use Yii;
use yii2mod\cms\models\CmsModel;
use yii\filters\VerbFilter;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii2mod\cms\models\CmsModel;
use yii2mod\editable\EditableAction;
use yii2mod\toggle\actions\ToggleAction;

/**
* Class CmsController
*
* @package yii2mod\cms\controllers
*/
class CmsController extends Controller
Expand Down Expand Up @@ -48,14 +49,14 @@ public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'class' => VerbFilter::class,
'actions' => [
'index' => ['get'],
'create' => ['get', 'post'],
'update' => ['get', 'post'],
'delete' => ['post']
'delete' => ['post'],
],
]
],
];
}

Expand All @@ -66,14 +67,14 @@ public function actions()
{
return [
'edit-page' => [
'class' => EditableAction::className(),
'modelClass' => CmsModel::className(),
'forceCreate' => false
'class' => EditableAction::class,
'modelClass' => CmsModel::class,
'forceCreate' => false,
],
'toggle' => [
'class' => ToggleAction::className(),
'modelClass' => CmsModel::className(),
]
'class' => ToggleAction::class,
'modelClass' => CmsModel::class,
],
];
}

Expand All @@ -89,7 +90,7 @@ public function actionIndex()

return $this->render($this->indexView, [
'dataProvider' => $dataProvider,
'searchModel' => $searchModel
'searchModel' => $searchModel,
]);
}

Expand All @@ -106,11 +107,12 @@ public function actionCreate()

if ($model->load(Yii::$app->request->post()) && $model->save()) {
Yii::$app->session->setFlash('success', Yii::t('yii2mod.cms', 'Page has been created.'));

return $this->redirect(['index']);
}

return $this->render($this->createView, [
'model' => $model
'model' => $model,
]);
}

Expand All @@ -119,7 +121,7 @@ public function actionCreate()
*
* If update is successful, the browser will be redirected to the 'index' page.
*
* @param integer $id
* @param int $id
*
* @return mixed
*/
Expand All @@ -129,11 +131,12 @@ public function actionUpdate($id)

if ($model->load(Yii::$app->request->post()) && $model->save()) {
Yii::$app->session->setFlash('success', Yii::t('yii2mod.cms', 'Page has been updated.'));

return $this->redirect(['index']);
}

return $this->render($this->updateView, [
'model' => $model
'model' => $model,
]);
}

Expand All @@ -142,22 +145,23 @@ public function actionUpdate($id)
*
* If deletion is successful, the browser will be redirected to the 'index' page.
*
* @param integer $id
* @param int $id
*
* @return mixed
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
Yii::$app->session->setFlash('success', Yii::t('yii2mod.cms', 'Page has been deleted.'));

return $this->redirect(['index']);
}

/**
* Finds the CmsModel model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
*
* @param integer $id
* @param int $id
*
* @return CmsModel the loaded model
*
Expand All @@ -173,4 +177,4 @@ protected function findModel($id)
throw new NotFoundHttpException(Yii::t('yii2mod.cms', 'The requested page does not exist.'));
}
}
}
}
2 changes: 1 addition & 1 deletion messages/en/yii2mod.cms.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@
'Page has been created.' => 'Page has been created.',
'Page has been updated.' => 'Page has been updated.',
'Page has been deleted.' => 'Page has been deleted.',
'The requested page does not exist.' => 'The requested page does not exist.'
'The requested page does not exist.' => 'The requested page does not exist.',
];
2 changes: 1 addition & 1 deletion messages/ru/yii2mod.cms.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@
'Page has been created.' => 'Страница была сохранён.',
'Page has been updated.' => 'Страница был обновлена.',
'Page has been deleted.' => 'Страница был удалена.',
'The requested page does not exist.' => 'Ошибка 404 - страница не найдена!'
'The requested page does not exist.' => 'Ошибка 404 - страница не найдена!',
];
5 changes: 2 additions & 3 deletions migrations/m150212_182851_init_cms.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ public function up()
'metaDescription' => $this->text(),
'metaKeywords' => $this->text(),
'createdAt' => $this->integer()->notNull(),
'updatedAt' => $this->integer()->notNull()
'updatedAt' => $this->integer()->notNull(),
], $tableOptions);

}

public function down()
{
$this->dropTable('{{%Cms}}');
}
}
}
2 changes: 1 addition & 1 deletion migrations/m161109_105445_rename_cms_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ public function down()
$this->renameTable('{{%cms}}', '{{%Cms}}');
}
}
}
}
Loading

0 comments on commit d14d653

Please sign in to comment.