diff --git a/.gitignore b/.gitignore index f0dcfe4..50b321e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ vendor composer.lock -tests/.phpunit.result.cache +.phpunit.result.cache diff --git a/composer.json b/composer.json index 3b6170a..77113af 100644 --- a/composer.json +++ b/composer.json @@ -4,6 +4,7 @@ }, "require-dev": { "glpi-project/tools": "^0.7.2", + "phpstan/phpstan": "^1.10", "phpunit/phpunit": "~9.6" }, "config": { @@ -17,6 +18,7 @@ } }, "scripts": { - "test": "phpunit -c phpunit.xml" + "test": "phpunit -c phpunit.xml", + "phpstan": "phpstan analyse -c phpstan.neon" } } diff --git a/front/ruleimport.form.php b/front/ruleimport.form.php index dac21a0..41fea6f 100644 --- a/front/ruleimport.form.php +++ b/front/ruleimport.form.php @@ -28,6 +28,6 @@ Html::displayNotFoundError(); } -$rulecollection = new PluginJamfRuleImportCollection($_SESSION['glpiactive_entity']); +$rulecollection = new PluginJamfRuleImportCollection(); include(GLPI_ROOT . "/front/rule.common.form.php"); diff --git a/front/ruleimport.php b/front/ruleimport.php index 594636e..937ddd9 100644 --- a/front/ruleimport.php +++ b/front/ruleimport.php @@ -28,6 +28,6 @@ Html::displayNotFoundError(); } -$rulecollection = new PluginJamfRuleImportCollection($_SESSION['glpiactive_entity']); +$rulecollection = new PluginJamfRuleImportCollection(); include(GLPI_ROOT . "/front/rule.common.php"); diff --git a/inc/config.class.php b/inc/config.class.php index 0130489..526ff17 100644 --- a/inc/config.class.php +++ b/inc/config.class.php @@ -33,7 +33,7 @@ class PluginJamfConfig extends CommonDBTM public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { - if (!$withtemplate && $item->getType() === 'Config') { + if (!$withtemplate && $item::class === Config::class) { return _x('plugin_info', 'Jamf plugin', 'jamf'); } return ''; @@ -41,7 +41,6 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) public function showForm($ID = -1, array $options = []) { - global $CFG_GLPI; if (!Session::haveRight('config', UPDATE)) { return false; } @@ -51,14 +50,15 @@ public function showForm($ID = -1, array $options = []) 'config' => $config, 'url' => Toolbox::getItemTypeFormURL('Config'), ]); + return true; } public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { - if ($item->getType() === 'Config') { - $config = new self(); - $config->showForm(); + if ($item::class === Config::class) { + return (new self())->showForm(); } + return false; } public static function undiscloseConfigValue($fields) diff --git a/inc/connection.class.php b/inc/connection.class.php index f73cf9c..5b3e030 100644 --- a/inc/connection.class.php +++ b/inc/connection.class.php @@ -198,6 +198,11 @@ private function fetchBearerToken() */ public function getClient() { + /** + * @var array $CFG_GLPI + */ + global $CFG_GLPI; + if (!isset($this->client)) { if ($this->bearer_token === null) { $this->fetchBearerToken(); diff --git a/inc/devicesync.class.php b/inc/devicesync.class.php index f1fecaf..d1144ae 100644 --- a/inc/devicesync.class.php +++ b/inc/devicesync.class.php @@ -178,7 +178,7 @@ public static function syncAll(): int $volume = 0; $config = PluginJamfConfig::getConfig(); - $valid_sync_interval = isset($config['sync_interval']) && !empty($config['sync_interval']) && ((int) $config['sync_interval'] >= 1); + $valid_sync_interval = isset($config['sync_interval']) && !empty($config['sync_interval']) && ((int)$config['sync_interval'] >= 1); if (!$valid_sync_interval) { $config['sync_interval'] = 8 * 60; } diff --git a/inc/migration.class.php b/inc/migration.class.php index 471c72a..4210ce9 100644 --- a/inc/migration.class.php +++ b/inc/migration.class.php @@ -59,7 +59,7 @@ public function __construct($version) public function applyMigrations() { $rc = new ReflectionClass($this); - $otherMigrationFunctions = array_map(static function ($rm) use ($rc) { + $otherMigrationFunctions = array_map(static function ($rm) { return $rm->getShortName(); }, array_filter($rc->getMethods(), static function ($m) { return preg_match('/(?<=^apply_)(.*)(?=_migration$)/', $m->getShortName()); @@ -473,18 +473,6 @@ public function apply_2_1_0_migration() ]); } - $old_jsspassword = Config::getConfigurationValues('plugin:Jamf', ['jsspassword'])['jsspassword'] ?? ''; - if (!empty($old_jsspassword)) { - $glpi_key = new GLPIKey(); - $this->db->update(Config::getTable(), [ - 'value' => $glpi_key->encrypt(Toolbox::decrypt($old_jsspassword)) - ], [ - 'context' => 'plugin:Jamf', - 'name' => 'jsspassword' - ]); - } - unset($old_jsspassword); - $this->glpiMigration->addRight(PluginJamfComputer::$rightname, ALLSTANDARDRIGHT); } diff --git a/inc/profile.class.php b/inc/profile.class.php index 70f4549..86b4de9 100644 --- a/inc/profile.class.php +++ b/inc/profile.class.php @@ -70,7 +70,8 @@ public function showForm($profiles_id = 0, $openform = true, $closeform = true) echo "