From 4df21da7cdfd72477bc2d2ad8d15bba003130bc0 Mon Sep 17 00:00:00 2001 From: Igor Chepurnoy Date: Sat, 31 Dec 2016 18:13:23 +0200 Subject: [PATCH] add php-cs-fixer, travis.yml --- .gitattributes | 8 ++++++++ .gitignore | 35 +++++++++++++++++++++++++++++++++++ .php_cs | 25 +++++++++++++++++++++++++ .travis.yml | 22 ++++++++++++++++++++++ ChosenSelect.php | 41 ++++++++++++++--------------------------- ChosenSelectAsset.php | 18 ++++++++++-------- composer.json | 9 ++++++++- 7 files changed, 122 insertions(+), 36 deletions(-) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 .php_cs create mode 100644 .travis.yml diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..f7c5bd5 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,8 @@ + # Ignore all test and documentation for archive +/.gitattributes export-ignore +/.gitignore export-ignore +/.scrutinizer.yml export-ignore +/.travis.yml export-ignore +/phpunit.xml.dist export-ignore +/tests export-ignore +/docs export-ignore \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8e375d0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,35 @@ +# phpstorm project files +.idea + +# netbeans project files +nbproject + +# zend studio for eclipse project files +.buildpath +.project +.settings + +# windows thumbnail cache +Thumbs.db + +# composer vendor dir +/vendor + +/composer.lock + +# composer itself is not needed +composer.phar + +# Mac DS_Store Files +.DS_Store + +# phpunit itself is not needed +phpunit.phar +# local phpunit config +/phpunit.xml + +# local tests configuration +/tests/data/config.local.php + +# runtime cache +/tests/runtime \ No newline at end of file diff --git a/.php_cs b/.php_cs new file mode 100644 index 0000000..3867449 --- /dev/null +++ b/.php_cs @@ -0,0 +1,25 @@ +exclude('vendor') + ->in([__DIR__]); + +$config = PhpCsFixer\Config::create() + ->setUsingCache(false) + ->setRules([ + '@Symfony' => true, + 'phpdoc_align' => false, + 'phpdoc_summary' => false, + 'phpdoc_inline_tag' => false, + 'pre_increment' => false, + 'heredoc_to_nowdoc' => false, + 'cast_spaces' => false, + 'include' => false, + 'phpdoc_no_package' => false, + 'concat_space' => ['spacing' => 'one'], + 'ordered_imports' => true, + 'array_syntax' => ['syntax' => 'short'], + ]) + ->setFinder($finder); + +return $config; diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..a8dc1ef --- /dev/null +++ b/.travis.yml @@ -0,0 +1,22 @@ +language: php + +php: + - 5.6 + +# faster builds on new travis setup not using sudo +sudo: false + +# cache vendor dirs +cache: + directories: + - $HOME/.composer/cache + - vendor + +install: + - travis_retry composer self-update && composer --version + - travis_retry composer global require "fxp/composer-asset-plugin:~1.1.1" + - export PATH="$HOME/.composer/vendor/bin:$PATH" + - travis_retry composer install --prefer-dist --no-interaction + +script: + - vendor/friendsofphp/php-cs-fixer/php-cs-fixer fix --dry-run --diff diff --git a/ChosenSelect.php b/ChosenSelect.php index 0094bcb..de0bf7f 100644 --- a/ChosenSelect.php +++ b/ChosenSelect.php @@ -7,52 +7,46 @@ use yii\widgets\InputWidget; /** - * Chosen Select Widget based on Chosen jQuery plugin {@link http://harvesthq.github.io/chosen) - * @package yii2mod\chosen + * Yii2 wrapper for Chosen plugin {@link http://harvesthq.github.io/chosen) * - * @author Igor Chepurnoy + * @author Igor Chepurnoy + * + * @since 1.0 */ class ChosenSelect extends InputWidget { - /** - * @var array the HTML attributes for the input tag. In default it contains ['data-placeholder' => 'Please select...', 'multiple' => false] - * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. - */ - public $options = []; - /** * @var array select items */ public $items = []; /** - * @var array Plugin options. In default it contains ['width' => '100%'] + * @var array plugin options. By default it contains ['width' => '100%'] */ public $pluginOptions = []; /** - * Initializes the object. - * This method is invoked at the end of the constructor after the object is initialized with the - * given configuration. + * @inheritdoc */ public function init() { parent::init(); - if(empty($this->options['data-placeholder'])) { + if (empty($this->options['data-placeholder'])) { $this->options['data-placeholder'] = 'Please select...'; } - if(empty($this->options['multiple'])) { + + if (empty($this->options['multiple'])) { $this->options['multiple'] = false; } - if(empty($this->pluginOptions['width'])) { + + if (empty($this->pluginOptions['width'])) { $this->pluginOptions['width'] = '100%'; } } /** - * Render chosen select - * @return string|void + * @inheritdoc */ public function run() { @@ -71,24 +65,17 @@ protected function registerAssets() { $view = $this->getView(); ChosenSelectAsset::register($view); - $js = '$("#' . $this->getInputId() . '").chosen(' . $this->getPluginOptions() . ');'; + $js = '$("#' . $this->options['id'] . '").chosen(' . $this->getPluginOptions() . ');'; $view->registerJs($js, $view::POS_END); } /** * Return plugin options in json format + * * @return string */ public function getPluginOptions() { return Json::encode($this->pluginOptions); } - - /** - * Return input id - */ - public function getInputId() - { - return $this->options['id']; - } } diff --git a/ChosenSelectAsset.php b/ChosenSelectAsset.php index 2224653..ae3c7b3 100644 --- a/ChosenSelectAsset.php +++ b/ChosenSelectAsset.php @@ -5,18 +5,21 @@ use yii\web\AssetBundle; /** - * Class ChosenSelectAsset - * @package yii2mod\chosen + * ChosenSelectAsset bundle + * + * @author Igor Chepurnoy + * + * @since 1.0 */ class ChosenSelectAsset extends AssetBundle { /** - * @var string + * @var string the directory that contains the source asset files for this asset bundle */ public $sourcePath = '@bower/drmonty-chosen'; /** - * @var array + * @var array list of JavaScript files that this bundle contains */ public $js = [ 'js/chosen.jquery.js', @@ -24,17 +27,16 @@ class ChosenSelectAsset extends AssetBundle ]; /** - * @var array + * @var array list of CSS files that this bundle contains */ public $css = [ 'css/chosen.css', ]; /** - * Depends - * @var array + * @var array list of JavaScript files that this bundle contains */ public $depends = [ - 'yii\web\YiiAsset' + 'yii\web\YiiAsset', ]; } diff --git a/composer.json b/composer.json index e54cf25..a2b6586 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,11 @@ "name": "yii2mod/yii2-chosen-select", "description": "Chosen Select Widget based on Chosen jQuery plugin", "type": "yii2-extension", - "keywords": ["yii2", "module"], + "keywords": [ + "yii2", + "select", + "widget" + ], "license": "MIT", "authors": [ { @@ -14,6 +18,9 @@ "yiisoft/yii2": "*", "bower-asset/drmonty-chosen": "*" }, + "require-dev": { + "friendsofphp/php-cs-fixer": "~2.0" + }, "autoload": { "psr-4": { "yii2mod\\chosen\\": ""