Skip to content

Commit

Permalink
#4 Add code quality tools and github worklow
Browse files Browse the repository at this point in the history
Add php stan ( WIP )
  • Loading branch information
nenes25 committed Oct 29, 2021
1 parent 28b4eab commit d75430f
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 2 deletions.
39 changes: 39 additions & 0 deletions classes/CronJobsForms.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class CronJobsForms
{
protected static $module = false;

/**
* @param Module $module
* @return bool
*/
public static function init($module)
{
if (self::$module == false) {
Expand All @@ -34,6 +38,11 @@ public static function init($module)
return self::$module;
}

/**
* @param string $title
* @param false $update
* @return array[]
*/
public static function getJobForm($title = 'New cron task', $update = false)
{
$form = [
Expand Down Expand Up @@ -150,6 +159,9 @@ public static function getJobForm($title = 'New cron task', $update = false)
return $form;
}

/**
* @return array[]
*/
public static function getForm()
{
$form = [
Expand Down Expand Up @@ -182,6 +194,9 @@ public static function getForm()
return [$form];
}

/**
* @return array[]
*/
public static function getFormValues()
{
$token = Configuration::get('CRONJOBS_EXECUTION_TOKEN', null, 0, 0);
Expand Down Expand Up @@ -211,6 +226,9 @@ public static function getFormValues()
];
}

/**
* @return array[]
*/
public static function getTasksList()
{
return [
Expand All @@ -226,6 +244,9 @@ public static function getTasksList()
];
}

/**
* @return array[]
*/
public static function getNewJobFormValues()
{
return [
Expand All @@ -238,6 +259,9 @@ public static function getNewJobFormValues()
];
}

/**
* @return array[]
*/
public static function getUpdateJobFormValues()
{
$id_shop = (int) Context::getContext()->shop->id;
Expand Down Expand Up @@ -267,6 +291,9 @@ public static function getUpdateJobFormValues()
];
}

/**
* @return array|bool
*/
public static function getTasksListValues()
{
$id_shop = (int) Context::getContext()->shop->id;
Expand Down Expand Up @@ -326,6 +353,9 @@ public static function getTasksListValues()
return $crons;
}

/**
* @return array[]
*/
protected static function getHoursFormOptions()
{
$data = [['id' => '-1', 'name' => self::$module->l('Every hour', 'CronJobsForms')]];
Expand All @@ -337,6 +367,9 @@ protected static function getHoursFormOptions()
return $data;
}

/**
* @return array[]
*/
protected static function getDaysFormOptions()
{
$data = [['id' => '-1', 'name' => self::$module->l('Every day of the month', 'CronJobsForms')]];
Expand All @@ -348,6 +381,9 @@ protected static function getDaysFormOptions()
return $data;
}

/**
* @return array[]
*/
protected static function getMonthsFormOptions()
{
$data = [['id' => '-1', 'name' => self::$module->l('Every month', 'CronJobsForms')]];
Expand All @@ -359,6 +395,9 @@ protected static function getMonthsFormOptions()
return $data;
}

/**
* @return array[]
*/
protected static function getDaysofWeekFormOptions()
{
$data = [['id' => '-1', 'name' => self::$module->l('Every day of the week', 'CronJobsForms')]];
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
},
"type": "prestashop-module",
"require-dev": {
"prestashop/php-dev-tools": "^4.1"
"prestashop/php-dev-tools": "^4.1",
"phpstan/phpstan": "^0.12.99"
},
"scripts": {
"cs-fixer": [
"@php ./vendor/bin/php-cs-fixer fix"
],
"header-stamp": [
"@php ./vendor/bin/header-stamp --exclude=\"vendor,translations\" --extensions=php --license=vendor/prestashop/header-stamp/assets/afl.txt"
"@php ./vendor/bin/header-stamp --exclude=\"vendor,translations\" --extensions=php --license=assets/afl.txt"
]
}
}
18 changes: 18 additions & 0 deletions controllers/admin/AdminCronJobsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public function __construct()
exit;
}

/**
* @return bool|ObjectModel|void
* @throws PrestaShopDatabaseException
* @throws PrestaShopException
*/
public function postProcess()
{
$this->module->sendCallback();
Expand All @@ -44,6 +49,11 @@ public function postProcess()
ob_end_clean();
}

/**
* @return void
* @throws PrestaShopDatabaseException
* @throws PrestaShopException
*/
protected function runModulesCrons()
{
$query = 'SELECT * FROM ' . _DB_PREFIX_ . bqSQL($this->module->name) . ' WHERE `active` = 1 AND `id_module` IS NOT NULL';
Expand Down Expand Up @@ -72,6 +82,10 @@ protected function runModulesCrons()
}
}

/**
* @return void
* @throws PrestaShopDatabaseException
*/
protected function runTasksCrons()
{
$query = 'SELECT * FROM ' . _DB_PREFIX_ . bqSQL($this->module->name) . ' WHERE `active` = 1 AND `id_module` IS NULL';
Expand All @@ -93,6 +107,10 @@ protected function runTasksCrons()
}
}

/**
* @param array $cron
* @return bool
*/
protected function shouldBeExecuted($cron)
{
$hour = ($cron['hour'] == -1) ? date('H') : $cron['hour'];
Expand Down
1 change: 1 addition & 0 deletions cronjobs.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ public function getContent()
$this->context->smarty->assign('form_infos', $this->_warnings);
$this->context->smarty->assign('form_successes', $this->_successes);

$back_url='';
if ((Tools::isSubmit('submitNewCronJob') || Tools::isSubmit('newcronjobs') || Tools::isSubmit('updatecronjobs')) &&
((isset($submit_cron) == false) || ($submit_cron === false))) {
$back_url = $this->context->link->getAdminLink('AdminModules', false)
Expand Down
10 changes: 10 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
includes:
- %currentWorkingDirectory%/vendor/prestashop/php-dev-tools/phpstan/ps-module-extension.neon

parameters:
paths:
- ./
excludes_analyse:
- vendor/
reportUnmatchedIgnoredErrors: false
level: 6
4 changes: 4 additions & 0 deletions upgrade/upgrade-1.0.6.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
exit;
}

/**
* @param Module $module
* @return Module
*/
function upgrade_module_1_0_6($module)
{
$table_name = _DB_PREFIX_ . bqSQL($module->name);
Expand Down

0 comments on commit d75430f

Please sign in to comment.