Skip to content

Commit

Permalink
Merge pull request #2 from codenix-sv/dev
Browse files Browse the repository at this point in the history
Migrated to PHP 7
  • Loading branch information
codenix-sv authored Mar 18, 2020
2 parents 5b7ebe0 + 7ea606d commit 6c2649c
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 68 deletions.
10 changes: 6 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
language: php

php:
- '5.6'
- '7.0'
- '7.1'
- '7.2'
- '7.3'
- '7.4'

# faster builds on new travis setup not using sudo
sudo: false
Expand All @@ -20,12 +22,12 @@ install:
before_script:
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
- chmod +x ./cc-test-reporter
- if [ $(phpenv version-name) = "7.1" ]; then ./cc-test-reporter before-build; fi
- ./cc-test-reporter before-build

script:
- composer validate --strict
- vendor/bin/phpunit

after_script:
- if [ $(phpenv version-name) = "7.1" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT; fi
- if [ $(phpenv version-name) = "7.1" ]; then wget https://scrutinizer-ci.com/ocular.phar; php ocular.phar code-coverage:upload --format=php-clover ./build/logs/clover.xml; fi
- if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT; fi
- if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then wget https://scrutinizer-ci.com/ocular.phar; php ocular.phar code-coverage:upload --format=php-clover ./build/logs/clover.xml; fi
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Flatpickr is a lightweight and powerful datetime picker written in vanilla javas
![flatpickr-theme-dark](https://user-images.githubusercontent.com/17989224/33085189-a6d0688a-ceec-11e7-8a38-be258ff692b2.png)

## Latest release
The latest stable version of the extension is v1.0
The latest stable version of the extension is v2.0

## Installation

Expand All @@ -25,12 +25,12 @@ The preferred way to install this extension is through [composer](http://getcomp
Either run

```bash
$ composer require codenix-sv/yii2-flatpickr:~1.0
$ composer require codenix-sv/yii2-flatpickr:~2.0
```
or add

```json
"codenix-sv/yii2-flatpickr" : "~1.0"
"codenix-sv/yii2-flatpickr" : "~2.0"
```

to the require section of your application's `composer.json` file.
Expand All @@ -46,7 +46,7 @@ use codenixsv\flatpickr\Flatpickr;

?>
...
<?= $form->field($model, 'date')->widget(Flatpickr::className()) ?>
<?= $form->field($model, 'date')->widget(Flatpickr::class) ?>
```
### Example of use as a widget:
```php
Expand All @@ -61,7 +61,7 @@ use codenixsv\flatpickr\Flatpickr;

?>
...
<?= $form->field($model, 'email')->widget(Flatpickr::className(), [
<?= $form->field($model, 'email')->widget(Flatpickr::class, [
'theme' =>'dark',
'clientOptions' => [
'locale' => 'ru',
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
}
],
"require": {
"php": ">=7.0",
"yiisoft/yii2": "~2.0.0",
"npm-asset/flatpickr": "~4.0"
},
"require-dev": {
"phpunit/phpunit": "~5.0"
"phpunit/phpunit": "~6.0"
},
"autoload": {
"psr-4": {
Expand Down
31 changes: 9 additions & 22 deletions src/Flatpickr.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,18 @@ class Flatpickr extends InputWidget
*/
public $clientOptions = [];

/**
* @var array
*/
/** @var array */
public $defaultOptions = [
'allowInput' => true
];

/**
* @var string
*/
/** @var string */
private $_locale;

/**
* @var string
*/
/** @var string */
public $theme;

/**
* @var string
*/
/** @var string */
private $_id;

/**
Expand All @@ -64,17 +56,14 @@ public function init()

/**
* @inheritdoc
* @return string
*/
public function run()
public function run(): string
{
parent::run();

$this->registerClientScript();

$content = $this->renderContent();

return $content;
return $this->renderContent();
}

/**
Expand All @@ -96,15 +85,13 @@ private function registerClientScript()

/**
* Renders widget
* @return string
*/
private function renderContent()
private function renderContent(): string
{
$options = ArrayHelper::merge(['class' => 'form-control', 'data-input' => true], $this->options);
$content = $this->hasModel()

return $this->hasModel()
? Html::activeTextInput($this->model, $this->attribute, $options)
: Html::textInput($this->name, $this->value, $options);

return $content;
}
}
23 changes: 5 additions & 18 deletions src/assets/FlatpickrAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,23 @@
*/
class FlatpickrAsset extends AssetBundle
{
/**
* @inheritdoc
* @var string
*/
/** @var string */
public $sourcePath = '@npm/flatpickr/dist';

/**
* @inheritdoc
* @var array
*/
/** @var array */
public $js = [
'flatpickr.min.js',
];

/**
* @inheritdoc
* @var array
*/
/** @var array */
public $css = [
'flatpickr.min.css',
];

/**
* @var string
*/
/** @var string */
public $theme;

/**
* @var string
*/
/** @var string */
public $locale;

/**
Expand Down
1 change: 0 additions & 1 deletion tests/functional/FlatpickrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use tests\data\models\TestModel;
use codenixsv\flatpickr\Flatpickr;
use yii\widgets\ActiveForm;

/**
* Class FlatpickrTest
Expand Down
24 changes: 9 additions & 15 deletions tests/functional/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
namespace codenixsv\flatpickr\tests\functional;

use yii\web\View;
use \yii\web\Application;
use yii\web\Application;
use Yii;

/**
* Class TestCase
* @package codenixsv\flatpickr\tests\functional
*/
abstract class TestCase extends \PHPUnit_Framework_TestCase
abstract class TestCase extends \PHPUnit\Framework\TestCase
{
/**
* @inheritdoc
Expand Down Expand Up @@ -40,9 +41,8 @@ protected function mockApplication()
/**
* Returns vendor directory path
*
* @return string
*/
protected function getVendorPath()
protected function getVendorPath(): string
{
return dirname(dirname(__DIR__)) . '/vendor';
}
Expand All @@ -52,28 +52,24 @@ protected function getVendorPath()
*/
protected function destroyApplication()
{
\Yii::$app = null;
Yii::$app = null;
}

/**
* Creates view for testing
*
* @return View
*/
protected function getView()
protected function getView(): View
{
$view = new View();

return $view;
return new View();
}

/**
* Returns config for Application
* @return array
*/
protected function getApplicationConfig()
protected function getApplicationConfig(): array
{
$config = [
return [
'id' => 'testapp',
'basePath' => __DIR__,
'vendorPath' => $this->getVendorPath(),
Expand Down Expand Up @@ -101,7 +97,5 @@ protected function getApplicationConfig()
],
],
];

return $config;
}
}
8 changes: 6 additions & 2 deletions tests/functional/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
<?php
// ensure we get report on all possible php errors

error_reporting(-1);
define('YII_ENABLE_ERROR_HANDLER', false);
define('YII_DEBUG', true);

$_SERVER['SCRIPT_NAME'] = '/' . __DIR__;
$_SERVER['SCRIPT_FILENAME'] = __FILE__;

require_once(__DIR__ . '/../../vendor/autoload.php');
require_once(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php');

Yii::setAlias('@tests', __DIR__);
require_once(__DIR__ . '/TestCase.php');

require_once(__DIR__ . '/TestCase.php');

0 comments on commit 6c2649c

Please sign in to comment.