From 7ea606de417df7a588741b500ef5240c2fcbbdc4 Mon Sep 17 00:00:00 2001 From: Codenix Date: Wed, 18 Mar 2020 18:49:49 +0200 Subject: [PATCH] Migrated to PHP 7 --- .travis.yml | 10 ++++++---- README.md | 10 +++++----- composer.json | 3 ++- src/Flatpickr.php | 31 +++++++++--------------------- src/assets/FlatpickrAsset.php | 23 +++++----------------- tests/functional/FlatpickrTest.php | 1 - tests/functional/TestCase.php | 24 +++++++++-------------- tests/functional/bootstrap.php | 8 ++++++-- 8 files changed, 42 insertions(+), 68 deletions(-) diff --git a/.travis.yml b/.travis.yml index c20f01b..3664a08 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 @@ -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 \ No newline at end of file + - 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 \ No newline at end of file diff --git a/README.md b/README.md index f5c6cec..540ef46 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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. @@ -46,7 +46,7 @@ use codenixsv\flatpickr\Flatpickr; ?> ... -field($model, 'date')->widget(Flatpickr::className()) ?> +field($model, 'date')->widget(Flatpickr::class) ?> ``` ### Example of use as a widget: ```php @@ -61,7 +61,7 @@ use codenixsv\flatpickr\Flatpickr; ?> ... -field($model, 'email')->widget(Flatpickr::className(), [ +field($model, 'email')->widget(Flatpickr::class, [ 'theme' =>'dark', 'clientOptions' => [ 'locale' => 'ru', diff --git a/composer.json b/composer.json index c940fff..b0536ea 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/src/Flatpickr.php b/src/Flatpickr.php index e305400..3bd6380 100644 --- a/src/Flatpickr.php +++ b/src/Flatpickr.php @@ -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; /** @@ -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(); } /** @@ -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; } } diff --git a/src/assets/FlatpickrAsset.php b/src/assets/FlatpickrAsset.php index fe35169..aaaf43c 100644 --- a/src/assets/FlatpickrAsset.php +++ b/src/assets/FlatpickrAsset.php @@ -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; /** diff --git a/tests/functional/FlatpickrTest.php b/tests/functional/FlatpickrTest.php index 0516a2d..911c75c 100644 --- a/tests/functional/FlatpickrTest.php +++ b/tests/functional/FlatpickrTest.php @@ -4,7 +4,6 @@ use tests\data\models\TestModel; use codenixsv\flatpickr\Flatpickr; -use yii\widgets\ActiveForm; /** * Class FlatpickrTest diff --git a/tests/functional/TestCase.php b/tests/functional/TestCase.php index 410a26d..a5d2133 100644 --- a/tests/functional/TestCase.php +++ b/tests/functional/TestCase.php @@ -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 @@ -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'; } @@ -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(), @@ -101,7 +97,5 @@ protected function getApplicationConfig() ], ], ]; - - return $config; } } diff --git a/tests/functional/bootstrap.php b/tests/functional/bootstrap.php index f43475d..855048a 100644 --- a/tests/functional/bootstrap.php +++ b/tests/functional/bootstrap.php @@ -1,11 +1,15 @@