Skip to content

Commit

Permalink
add php-cs-fixer, travis.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Chepurnoy committed Dec 31, 2016
1 parent 1009328 commit 4df21da
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 36 deletions.
8 changes: 8 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
25 changes: 25 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

$finder = PhpCsFixer\Finder::create()
->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;
22 changes: 22 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
41 changes: 14 additions & 27 deletions ChosenSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
*
* @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()
{
Expand All @@ -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'];
}
}
18 changes: 10 additions & 8 deletions ChosenSelectAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,38 @@
use yii\web\AssetBundle;

/**
* Class ChosenSelectAsset
* @package yii2mod\chosen
* ChosenSelectAsset bundle
*
* @author Igor Chepurnoy <[email protected]>
*
* @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',
'js/chosen.proto.js',
];

/**
* @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',
];
}
9 changes: 8 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand All @@ -14,6 +18,9 @@
"yiisoft/yii2": "*",
"bower-asset/drmonty-chosen": "*"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "~2.0"
},
"autoload": {
"psr-4": {
"yii2mod\\chosen\\": ""
Expand Down

0 comments on commit 4df21da

Please sign in to comment.