diff --git a/.php_cs b/.php_cs new file mode 100644 index 0000000..b810a08 --- /dev/null +++ b/.php_cs @@ -0,0 +1,23 @@ +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; diff --git a/.travis.yml b/.travis.yml index 66e5895..8f9bace 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 @@ -21,6 +12,7 @@ sudo: false cache: directories: - $HOME/.composer/cache + - vendor install: - travis_retry composer self-update && composer --version @@ -29,4 +21,5 @@ install: - travis_retry composer install --prefer-dist --no-interaction script: - - phpunit --verbose $PHPUNIT_FLAGS \ No newline at end of file + - vendor/friendsofphp/php-cs-fixer/php-cs-fixer fix --dry-run --diff + - phpunit --verbose $PHPUNIT_FLAGS diff --git a/Module.php b/Module.php index d553225..ce532d5 100755 --- a/Module.php +++ b/Module.php @@ -4,12 +4,13 @@ /** * Class Module + * * @package yii2mod\settings */ class Module extends \yii\base\Module { /** - * @var string the namespace that controller classes are in. + * @var string the namespace that controller classes are in */ public $controllerNamespace = 'yii2mod\settings\controllers'; -} \ No newline at end of file +} diff --git a/components/Settings.php b/components/Settings.php index 8752d91..b8fe955 100755 --- a/components/Settings.php +++ b/components/Settings.php @@ -3,14 +3,15 @@ namespace yii2mod\settings\components; use Yii; -use yii\helpers\ArrayHelper; use yii\base\Component; use yii\caching\Cache; use yii\di\Instance; +use yii\helpers\ArrayHelper; use yii2mod\settings\models\enumerables\SettingType; /** * Class Settings + * * @package yii2mod\settings\components */ class Settings extends Component @@ -27,8 +28,7 @@ class Settings extends Component * - a configuration array * - a [[yii\caching\Cache]] object * - * When this is not set, it means caching is not enabled. - * + * When this is not set, it means caching is not enabled */ public $cache = 'cache'; @@ -60,7 +60,7 @@ public function init() parent::init(); if ($this->cache !== null) { - $this->cache = Instance::ensure($this->cache, Cache::className()); + $this->cache = Instance::ensure($this->cache, Cache::class); } $this->model = Yii::createObject($this->modelClass); @@ -72,6 +72,7 @@ public function init() * @param string $section * @param string $key * @param null $default + * * @return mixed */ public function get($section, $key, $default = null) @@ -96,6 +97,7 @@ public function get($section, $key, $default = null) * @param string $key * @param string $value * @param null $type + * * @return bool */ public function set($section, $key, $value, $type = null) @@ -114,6 +116,7 @@ public function set($section, $key, $value, $type = null) * * @param string $section * @param string $key + * * @return bool */ public function has($section, $key) @@ -128,6 +131,7 @@ public function has($section, $key) * * @param string $section * @param string $key + * * @return bool */ public function remove($section, $key) @@ -156,6 +160,7 @@ public function removeAll() * * @param string $key * @param string $section + * * @return bool */ public function activate($section, $key) @@ -168,6 +173,7 @@ public function activate($section, $key) * * @param string $key * @param string $section + * * @return bool */ public function deactivate($section, $key) @@ -225,4 +231,4 @@ protected function convertSettingType($type) settype($this->setting, $type); } } -} \ No newline at end of file +} diff --git a/composer.json b/composer.json index 05a2b4d..0be0633 100644 --- a/composer.json +++ b/composer.json @@ -1,23 +1,32 @@ { - "name": "yii2mod/yii2-settings", - "description": "Yii2 Settings Module", - "type": "yii2-extension", - "keywords": ["yii2", "settings", "config", "storage"], - "license": "MIT", - "authors": [ - { - "name": "Igor Chepurnoy", - "email": "igorzfort@gmail.com" + "name": "yii2mod/yii2-settings", + "description": "Yii2 Settings Module", + "type": "yii2-extension", + "keywords": [ + "yii2", + "settings", + "config", + "storage" + ], + "license": "MIT", + "authors": [ + { + "name": "Igor Chepurnoy", + "email": "igorzfort@gmail.com" + } + ], + "require": { + "php": ">=5.5", + "yiisoft/yii2": ">=2.0.8", + "yii2mod/yii2-editable": "*", + "yii2mod/yii2-enum": "*" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "~1.7" + }, + "autoload": { + "psr-4": { + "yii2mod\\settings\\": "" + } } - ], - "require": { - "yiisoft/yii2": ">=2.0.8", - "yii2mod/yii2-editable": "*", - "yii2mod/yii2-enum": "*" - }, - "autoload": { - "psr-4": { - "yii2mod\\settings\\": "" - } - } } diff --git a/controllers/DefaultController.php b/controllers/DefaultController.php index 6999771..0a8fbbc 100644 --- a/controllers/DefaultController.php +++ b/controllers/DefaultController.php @@ -3,14 +3,15 @@ namespace yii2mod\settings\controllers; use Yii; -use yii2mod\editable\EditableAction; -use yii2mod\settings\models\SettingModel; +use yii\filters\VerbFilter; use yii\web\Controller; use yii\web\NotFoundHttpException; -use yii\filters\VerbFilter; +use yii2mod\editable\EditableAction; +use yii2mod\settings\models\SettingModel; /** * Class SettingController + * * @package yii2mod\settings\controllers */ class DefaultController extends Controller @@ -49,14 +50,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'], + ], + ], ]; } @@ -69,10 +70,10 @@ public function actions() { return [ 'edit-setting' => [ - 'class' => EditableAction::className(), - 'modelClass' => SettingModel::className(), - 'forceCreate' => false - ] + 'class' => EditableAction::class, + 'modelClass' => SettingModel::class, + 'forceCreate' => false, + ], ]; } @@ -105,6 +106,7 @@ public function actionCreate() if ($model->load(Yii::$app->request->post()) && $model->save()) { Yii::$app->session->setFlash('success', Yii::t('yii2mod.settings', 'Setting has been created.')); + return $this->redirect(['index']); } else { return $this->render($this->createView, [ @@ -118,7 +120,8 @@ public function actionCreate() * * If update is successful, the browser will be redirected to the 'view' page. * - * @param integer $id + * @param int $id + * * @return mixed */ public function actionUpdate($id) @@ -127,6 +130,7 @@ public function actionUpdate($id) if ($model->load(Yii::$app->request->post()) && $model->save()) { Yii::$app->session->setFlash('success', Yii::t('yii2mod.settings', 'Setting has been updated.')); + return $this->redirect(['index']); } else { return $this->render($this->updateView, [ @@ -140,13 +144,15 @@ 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.settings', 'Setting has been deleted.')); + return $this->redirect(['index']); } @@ -155,7 +161,8 @@ public function actionDelete($id) * * If the model is not found, a 404 HTTP exception will be thrown. * - * @param integer $id + * @param int $id + * * @return SettingModel the loaded model * * @throws NotFoundHttpException if the model cannot be found @@ -170,4 +177,4 @@ protected function findModel($id) throw new NotFoundHttpException(Yii::t('yii2mod.settings', 'The requested page does not exist.')); } } -} \ No newline at end of file +} diff --git a/messages/en/yii2mod.settings.php b/messages/en/yii2mod.settings.php index acdb5c4..80545b7 100644 --- a/messages/en/yii2mod.settings.php +++ b/messages/en/yii2mod.settings.php @@ -47,5 +47,5 @@ 'Setting has been created.' => 'Setting has been created.', 'Setting has been updated.' => 'Setting has been updated.', 'Setting has been deleted.' => 'Setting 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.', ]; diff --git a/messages/ru/yii2mod.settings.php b/messages/ru/yii2mod.settings.php index d01389c..d14b863 100644 --- a/messages/ru/yii2mod.settings.php +++ b/messages/ru/yii2mod.settings.php @@ -47,5 +47,5 @@ 'Setting has been created.' => 'Настройка была сохранена.', 'Setting has been updated.' => 'Настройка была обновлена.', 'Setting has been deleted.' => 'Настройка была удалена.', - 'The requested page does not exist.' => 'Ошибка 404 - страница не найдена!' + 'The requested page does not exist.' => 'Ошибка 404 - страница не найдена!', ]; diff --git a/messages/uk/yii2mod.settings.php b/messages/uk/yii2mod.settings.php index 03bcbdc..840cbdc 100644 --- a/messages/uk/yii2mod.settings.php +++ b/messages/uk/yii2mod.settings.php @@ -47,5 +47,5 @@ 'Setting has been created.' => 'Налаштування було створено.', 'Setting has been updated.' => 'Налаштування було оновлено.', 'Setting has been deleted.' => 'Налаштування було видалено.', - 'The requested page does not exist.' => 'Помилка 404 - сторінка не знайдена!' + 'The requested page does not exist.' => 'Помилка 404 - сторінка не знайдена!', ]; diff --git a/migrations/m150227_114524_init.php b/migrations/m150227_114524_init.php index 8c739f0..7528ae8 100644 --- a/migrations/m150227_114524_init.php +++ b/migrations/m150227_114524_init.php @@ -26,7 +26,7 @@ public function up() 'value' => $this->text()->notNull(), 'status' => $this->smallInteger()->notNull()->defaultValue(1), 'createdAt' => $this->integer()->notNull(), - 'updatedAt' => $this->integer()->notNull() + 'updatedAt' => $this->integer()->notNull(), ], $tableOptions); } diff --git a/migrations/m161109_104201_rename_setting_table.php b/migrations/m161109_104201_rename_setting_table.php index 3384ea6..dcf4c76 100644 --- a/migrations/m161109_104201_rename_setting_table.php +++ b/migrations/m161109_104201_rename_setting_table.php @@ -17,4 +17,4 @@ public function down() $this->renameTable('{{%setting}}', '{{%Setting}}'); } } -} \ No newline at end of file +} diff --git a/models/SettingModel.php b/models/SettingModel.php index 79b1d3c..fd977ab 100644 --- a/models/SettingModel.php +++ b/models/SettingModel.php @@ -2,25 +2,24 @@ namespace yii2mod\settings\models; +use Yii; use yii\behaviors\TimestampBehavior; use yii\db\ActiveRecord; use yii\helpers\ArrayHelper; -use Yii; use yii2mod\settings\models\enumerables\SettingStatus; use yii2mod\settings\models\enumerables\SettingType; /** * This is the model class for table "Settings". * - * @property integer $id + * @property int $id * @property string $type * @property string $section * @property string $key * @property string $value - * @property boolean $status + * @property bool $status * @property string $createdAt * @property string $updatedAt - * */ class SettingModel extends ActiveRecord { @@ -73,10 +72,10 @@ public function behaviors() { return [ 'timestamp' => [ - 'class' => TimestampBehavior::className(), + 'class' => TimestampBehavior::class, 'createdAtAttribute' => 'createdAt', - 'updatedAtAttribute' => 'updatedAt' - ] + 'updatedAtAttribute' => 'updatedAt', + ], ]; } @@ -142,6 +141,7 @@ public function getSettings() * @param $key * @param $value * @param null $type + * * @return bool */ public function setSetting($section, $key, $value, $type = null) @@ -149,7 +149,7 @@ public function setSetting($section, $key, $value, $type = null) $model = static::findOne(['section' => $section, 'key' => $key]); if (empty($model)) { - $model = new static; + $model = new static(); } $model->section = $section; @@ -170,6 +170,7 @@ public function setSetting($section, $key, $value, $type = null) * * @param $section * @param $key + * * @return bool|int|null * * @throws \Exception @@ -200,6 +201,7 @@ public function removeAllSettings() * * @param $section * @param $key + * * @return bool */ public function activateSetting($section, $key) @@ -208,6 +210,7 @@ public function activateSetting($section, $key) if ($model && $model->status === SettingStatus::INACTIVE) { $model->status = SettingStatus::ACTIVE; + return $model->save(true, ['status']); } @@ -219,6 +222,7 @@ public function activateSetting($section, $key) * * @param $section * @param $key + * * @return bool */ public function deactivateSetting($section, $key) @@ -227,9 +231,10 @@ public function deactivateSetting($section, $key) if ($model && $model->status === SettingStatus::ACTIVE) { $model->status = SettingStatus::INACTIVE; + return $model->save(true, ['status']); } return false; } -} \ No newline at end of file +} diff --git a/models/SettingQuery.php b/models/SettingQuery.php index 146367b..50f64b2 100644 --- a/models/SettingQuery.php +++ b/models/SettingQuery.php @@ -7,12 +7,14 @@ /** * Class SettingQuery + * * @package yii2mod\settings\models */ class SettingQuery extends ActiveQuery { /** * Scope for settings with active status + * * @return $this */ public function active() @@ -22,10 +24,11 @@ public function active() /** * Scope for settings with inactive status + * * @return $this */ public function inactive() { return $this->andWhere(['status' => SettingStatus::INACTIVE]); } -} \ No newline at end of file +} diff --git a/models/enumerables/SettingStatus.php b/models/enumerables/SettingStatus.php index 507721d..5bbec57 100644 --- a/models/enumerables/SettingStatus.php +++ b/models/enumerables/SettingStatus.php @@ -6,6 +6,7 @@ /** * Class SettingStatus + * * @package yii2mod\settings\models\enumerables */ class SettingStatus extends BaseEnum @@ -23,6 +24,6 @@ class SettingStatus extends BaseEnum */ public static $list = [ self::ACTIVE => 'Active', - self::INACTIVE => 'Inactive' + self::INACTIVE => 'Inactive', ]; -} \ No newline at end of file +} diff --git a/models/enumerables/SettingType.php b/models/enumerables/SettingType.php index 2e89fd0..2ab639c 100644 --- a/models/enumerables/SettingType.php +++ b/models/enumerables/SettingType.php @@ -6,6 +6,7 @@ /** * Class SettingStatus + * * @package yii2mod\settings\models\enumerables */ class SettingType extends BaseEnum @@ -31,4 +32,4 @@ class SettingType extends BaseEnum self::FLOAT_TYPE => 'Float', self::NULL_TYPE => 'Null', ]; -} \ No newline at end of file +} diff --git a/models/search/SettingSearch.php b/models/search/SettingSearch.php index 266b64c..0a683f6 100644 --- a/models/search/SettingSearch.php +++ b/models/search/SettingSearch.php @@ -7,12 +7,13 @@ /** * Class SettingSearch + * * @package yii2mod\settings\models\search */ class SettingSearch extends SettingModel { /** - * @var int the default page size. + * @var int the default page size */ public $pageSize = 10; @@ -40,8 +41,8 @@ public function search($params) $dataProvider = new ActiveDataProvider([ 'query' => $query, 'pagination' => [ - 'pageSize' => $this->pageSize - ] + 'pageSize' => $this->pageSize, + ], ]); if (!($this->load($params) && $this->validate())) { @@ -56,4 +57,4 @@ public function search($params) return $dataProvider; } -} \ No newline at end of file +} diff --git a/tests/SettingsTest.php b/tests/SettingsTest.php index 7920c7e..59ea02d 100644 --- a/tests/SettingsTest.php +++ b/tests/SettingsTest.php @@ -7,6 +7,7 @@ /** * Class SettingsTest + * * @package yii2mod\settings\tests */ class SettingsTest extends TestCase @@ -89,4 +90,4 @@ public function testCheckNullSettingType() Yii::$app->settings->set('system', 'language', null, SettingType::NULL_TYPE); $this->assertInternalType('null', Yii::$app->settings->get('system', 'language'), 'Returned setting is not an null!'); } -} \ No newline at end of file +} diff --git a/tests/TestCase.php b/tests/TestCase.php index 2310969..f62cffa 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,8 +2,8 @@ namespace yii2mod\settings\tests; -use yii\helpers\ArrayHelper; use Yii; +use yii\helpers\ArrayHelper; /** * This is the base class for all yii framework unit tests. @@ -26,6 +26,7 @@ protected function tearDown() /** * Populates Yii::$app with a new application * The application will be destroyed on tearDown() automatically. + * * @param array $config The application configuration, if needed * @param string $appClass name of the application class to create */ @@ -44,15 +45,15 @@ protected function mockApplication($config = [], $appClass = '\yii\console\Appli 'class' => 'yii2mod\settings\components\Settings', ], 'cache' => [ - 'class' => 'yii\caching\ArrayCache' + 'class' => 'yii\caching\ArrayCache', ], 'i18n' => [ 'translations' => [ 'yii2mod.settings' => [ 'class' => 'yii\i18n\PhpMessageSource', 'basePath' => '@yii2mod/settings/messages', - ] - ] + ], + ], ], ], ], $config)); @@ -94,4 +95,4 @@ protected function setupTestDbData() 'updatedAt' => 'integer not null', ])->execute(); } -} \ No newline at end of file +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php index effa70f..10cfa10 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -10,4 +10,4 @@ $_SERVER['SCRIPT_FILENAME'] = __FILE__; require_once(__DIR__ . '/../vendor/autoload.php'); -require_once(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php'); \ No newline at end of file +require_once(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php'); diff --git a/views/default/create.php b/views/default/create.php index 21022e5..b1622f8 100644 --- a/views/default/create.php +++ b/views/default/create.php @@ -14,7 +14,7 @@

title) ?>

render('_form', [ - 'model' => $model + 'model' => $model, ]); ?> diff --git a/views/default/index.php b/views/default/index.php index cdc57ee..14e445a 100644 --- a/views/default/index.php +++ b/views/default/index.php @@ -1,8 +1,8 @@ 'type', 'filter' => SettingType::listData(), - 'filterInputOptions' => ['prompt' => Yii::t('yii2mod.settings', 'Select Type'), 'class' => 'form-control'] + 'filterInputOptions' => ['prompt' => Yii::t('yii2mod.settings', 'Select Type'), 'class' => 'form-control'], ], [ 'attribute' => 'section', 'filter' => ArrayHelper::map(SettingModel::find()->select('section')->distinct()->all(), 'section', 'section'), - 'filterInputOptions' => ['prompt' => Yii::t('yii2mod.settings', 'Select Section'), 'class' => 'form-control'] + 'filterInputOptions' => ['prompt' => Yii::t('yii2mod.settings', 'Select Section'), 'class' => 'form-control'], ], 'key', 'value:ntext', [ - 'class' => EditableColumn::className(), + 'class' => EditableColumn::class, 'attribute' => 'status', 'url' => ['edit-setting'], 'value' => function ($model) { diff --git a/views/default/update.php b/views/default/update.php index 03906f2..64acb29 100644 --- a/views/default/update.php +++ b/views/default/update.php @@ -14,7 +14,7 @@

title) ?>

render('_form', [ - 'model' => $model + 'model' => $model, ]); ?>