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..8deeddd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,14 +5,6 @@ php: - 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 +13,7 @@ sudo: false cache: directories: - $HOME/.composer/cache + - vendor install: - travis_retry composer self-update && composer --version @@ -29,4 +22,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/actions/CronLogAction.php b/actions/CronLogAction.php index d914842..5397094 100644 --- a/actions/CronLogAction.php +++ b/actions/CronLogAction.php @@ -7,12 +7,13 @@ /** * Class CronLogAction + * * @package yii2mod\cron\actions */ class CronLogAction extends Action { /** - * @var string name of the view, which should be rendered. + * @var string name of the view, which should be rendered */ public $view = '@vendor/yii2mod/yii2-cron-log/views/index'; @@ -31,7 +32,7 @@ public function run() return $this->controller->render($this->view, [ 'searchModel' => $searchModel, - 'dataProvider' => $dataProvider + 'dataProvider' => $dataProvider, ]); } -} \ No newline at end of file +} diff --git a/behaviors/CronLoggerBehavior.php b/behaviors/CronLoggerBehavior.php index 416474c..97631ed 100755 --- a/behaviors/CronLoggerBehavior.php +++ b/behaviors/CronLoggerBehavior.php @@ -40,7 +40,7 @@ class CronLoggerBehavior extends Behavior protected $schedule; /** - * @var array list of action names, which should be logged. + * @var array list of action names, which should be logged */ public $actions = []; @@ -52,7 +52,7 @@ class CronLoggerBehavior extends Behavior /** * Declares event handlers for the [[owner]]'s events. * - * @return array events (array keys) and the corresponding event handler methods (array values). + * @return array events (array keys) and the corresponding event handler methods (array values) */ public function events() { @@ -64,6 +64,7 @@ public function events() /** * Before action + * * @param $event \yii\base\ActionEvent */ public function beforeAction($event) @@ -79,6 +80,7 @@ public function beforeAction($event) /** * After action + * * @param $event \yii\base\ActionEvent */ public function afterAction($event) @@ -124,4 +126,4 @@ private function getActionParams() return $result; } -} \ No newline at end of file +} diff --git a/behaviors/MutexConsoleCommandBehavior.php b/behaviors/MutexConsoleCommandBehavior.php index b395f3f..7691ad1 100644 --- a/behaviors/MutexConsoleCommandBehavior.php +++ b/behaviors/MutexConsoleCommandBehavior.php @@ -27,17 +27,18 @@ * ``` * * Class MutexConsoleCommandBehavior + * * @package yii2mod\cron\behaviors */ class MutexConsoleCommandBehavior extends Behavior { /** - * @var string name of the mutex application component. + * @var string name of the mutex application component */ public $mutex = 'mutex'; /** - * @var array list of action names, which mutex should be applied to. + * @var array list of action names, which mutex should be applied to */ public $mutexActions = []; @@ -53,7 +54,7 @@ public function events() } /** - * @return Mutex mutex application component instance. + * @return Mutex mutex application component instance */ public function getMutex() { @@ -63,9 +64,9 @@ public function getMutex() /** * Composes the mutex name. * - * @param string $action command action name. + * @param string $action command action name * - * @return string mutex name. + * @return string mutex name */ protected function composeMutexName($action) { @@ -75,9 +76,9 @@ protected function composeMutexName($action) /** * Checks if specified action is among mutex actions. * - * @param string $action action name. + * @param string $action action name * - * @return boolean whether action should be under mutex. + * @return bool whether action should be under mutex */ public function checkIsMutexAction($action) { @@ -86,6 +87,7 @@ public function checkIsMutexAction($action) /** * @param $event + * * @return bool */ public function beforeAction($event) @@ -95,6 +97,7 @@ public function beforeAction($event) if (!$this->getMutex()->acquire($mutexName)) { echo "Execution terminated: command is already running.\n"; $event->isValid = false; + return false; } } @@ -110,4 +113,4 @@ public function afterAction($event) $this->getMutex()->release($mutexName); } } -} \ No newline at end of file +} diff --git a/components/ErrorHandler.php b/components/ErrorHandler.php index d3071b2..c597c48 100644 --- a/components/ErrorHandler.php +++ b/components/ErrorHandler.php @@ -8,6 +8,7 @@ /** * Class ErrorHandler + * * @package yii2mod\cron\components */ class ErrorHandler extends \yii\console\ErrorHandler @@ -36,4 +37,4 @@ public function logException($exception) } \Yii::error((string)$exception, $category); } -} \ No newline at end of file +} diff --git a/composer.json b/composer.json index 968f2b8..2de2bd8 100644 --- a/composer.json +++ b/composer.json @@ -2,25 +2,32 @@ "name": "yii2mod/yii2-cron-log", "description": "Component for logging cron jobs", "type": "yii2-extension", - "keywords": ["yii2 cron log", "cron log", "logging cron jobs"], + "keywords": [ + "yii2 cron log", + "cron log", + "logging cron jobs" + ], "license": "MIT", "authors": [ - { - "name": "Dmitry Semenov", - "email": "disemx@gmail.com" - }, - { - "name": "Igor Chepurnoy", - "email": "igorzfort@gmail.com" - } + { + "name": "Dmitry Semenov", + "email": "disemx@gmail.com" + }, + { + "name": "Igor Chepurnoy", + "email": "igorzfort@gmail.com" + } ], "require": { - "yiisoft/yii2": ">=2.0.8", - "yii2mod/yii2-enum": ">=1.1" + "yiisoft/yii2": ">=2.0.8", + "yii2mod/yii2-enum": ">=1.4" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "~1.7" }, "autoload": { - "psr-4": { - "yii2mod\\cron\\": "" - } + "psr-4": { + "yii2mod\\cron\\": "" + } } } diff --git a/messages/en/yii2mod-cron-log.php b/messages/en/yii2mod-cron-log.php index e0f5132..465aec8 100644 --- a/messages/en/yii2mod-cron-log.php +++ b/messages/en/yii2mod-cron-log.php @@ -27,5 +27,5 @@ 'Status' => 'Status', 'Success' => 'Success', 'Error' => 'Error', - 'Run' => 'Run' + 'Run' => 'Run', ]; diff --git a/messages/ru/yii2mod-cron-log.php b/messages/ru/yii2mod-cron-log.php index 14b0b38..3021baf 100644 --- a/messages/ru/yii2mod-cron-log.php +++ b/messages/ru/yii2mod-cron-log.php @@ -27,5 +27,5 @@ 'Status' => 'Статус', 'Success' => 'Успешное завершение', 'Error' => 'Ошибка', - 'Run' => 'Выполняется' + 'Run' => 'Выполняется', ]; diff --git a/models/CronScheduleModel.php b/models/CronScheduleModel.php index 8b91cd3..1b58eef 100644 --- a/models/CronScheduleModel.php +++ b/models/CronScheduleModel.php @@ -60,6 +60,7 @@ public function attributeLabels() * @param string $jobCode * @param int $status * @param null $messages + * * @return bool */ public function startCronSchedule($jobCode, $status = CronScheduleStatus::RUN, $messages = null) @@ -78,7 +79,7 @@ public function startCronSchedule($jobCode, $status = CronScheduleStatus::RUN, $ * @param string $status * @param null $messages * - * @return boolean + * @return bool */ public function endCronSchedule($status, $messages = null) { @@ -92,4 +93,4 @@ public function endCronSchedule($status, $messages = null) return false; } -} \ No newline at end of file +} diff --git a/models/enumerables/CronScheduleStatus.php b/models/enumerables/CronScheduleStatus.php index 43ef8c7..059ad42 100644 --- a/models/enumerables/CronScheduleStatus.php +++ b/models/enumerables/CronScheduleStatus.php @@ -6,6 +6,7 @@ /** * Class CronScheduleStatus + * * @package yii2mod\cron\models\enumerables */ class CronScheduleStatus extends BaseEnum @@ -25,6 +26,6 @@ class CronScheduleStatus extends BaseEnum public static $list = [ self::SUCCESS => 'Success', self::ERROR => 'Error', - self::RUN => 'Run' + self::RUN => 'Run', ]; -} \ No newline at end of file +} diff --git a/models/search/CronScheduleSearch.php b/models/search/CronScheduleSearch.php index 7beeb8c..ca1dac5 100644 --- a/models/search/CronScheduleSearch.php +++ b/models/search/CronScheduleSearch.php @@ -7,12 +7,13 @@ /** * Class CronScheduleSearch + * * @package yii2mod\cron\models\search */ class CronScheduleSearch extends CronScheduleModel { /** - * @var int the default page size. + * @var int the default page size */ public $pageSize = 25; @@ -41,8 +42,8 @@ public function search($params) 'query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]], '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/CronLoggerBehaviorTest.php b/tests/CronLoggerBehaviorTest.php index 1dfa816..01bf999 100644 --- a/tests/CronLoggerBehaviorTest.php +++ b/tests/CronLoggerBehaviorTest.php @@ -8,6 +8,7 @@ /** * Class CronLoggerBehaviorTest + * * @package yii2mod\cron\tests */ class CronLoggerBehaviorTest extends TestCase @@ -20,4 +21,4 @@ public function testCronLog() $this->assertNotEmpty($cronScheduleModel, 'Cron log is empty!'); $this->assertEquals(Controller::EXIT_CODE_NORMAL, $cronScheduleModel->status, 'Invalid cron status!'); } -} \ No newline at end of file +} diff --git a/tests/TestCase.php b/tests/TestCase.php index fb95463..e5e8133 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,8 +2,8 @@ namespace yii2mod\cron\tests; -use yii\helpers\ArrayHelper; use Yii; +use yii\helpers\ArrayHelper; /** * This is the base class for all yii framework unit tests. @@ -27,6 +27,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 */ @@ -37,7 +38,7 @@ protected function mockApplication($config = [], $appClass = '\yii\console\Appli 'basePath' => __DIR__, 'vendorPath' => $this->getVendorPath(), 'controllerMap' => [ - 'hello' => 'yii2mod\cron\tests\data\HelloController' + 'hello' => 'yii2mod\cron\tests\data\HelloController', ], 'components' => [ 'db' => [ @@ -48,7 +49,7 @@ protected function mockApplication($config = [], $appClass = '\yii\console\Appli 'class' => 'yii2mod\cron\components\ErrorHandler', ], 'mutex' => [ - 'class' => 'yii\mutex\FileMutex' + 'class' => 'yii\mutex\FileMutex', ], ], ], $config)); @@ -88,4 +89,4 @@ protected function setupTestDbData() 'dateFinished' => 'timestamp 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/tests/data/HelloController.php b/tests/data/HelloController.php index 0500566..faeb7d6 100644 --- a/tests/data/HelloController.php +++ b/tests/data/HelloController.php @@ -6,6 +6,7 @@ /** * Class HelloController + * * @package yii2mod\cron\tests\data */ class HelloController extends Controller @@ -18,17 +19,18 @@ public function behaviors() return [ 'cronLogger' => [ 'class' => 'yii2mod\cron\behaviors\CronLoggerBehavior', - 'actions' => ['index'] - ] + 'actions' => ['index'], + ], ]; } /** * This command echoes what you have entered as the message. - * @param string $message the message to be echoed. + * + * @param string $message the message to be echoed */ public function actionIndex($message = 'hello world') { echo $message . "\n"; } -} \ No newline at end of file +} diff --git a/views/index.php b/views/index.php index 51fcf4b..486cf6a 100644 --- a/views/index.php +++ b/views/index.php @@ -1,7 +1,7 @@ \ No newline at end of file