Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

Commit

Permalink
add phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
cconard96 committed Apr 13, 2024
1 parent ee6a863 commit 805ef67
Show file tree
Hide file tree
Showing 15 changed files with 68 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
vendor
composer.lock
tests/.phpunit.result.cache
.phpunit.result.cache
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
},
"require-dev": {
"glpi-project/tools": "^0.7.2",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "~9.6"
},
"config": {
Expand All @@ -17,6 +18,7 @@
}
},
"scripts": {
"test": "phpunit -c phpunit.xml"
"test": "phpunit -c phpunit.xml",
"phpstan": "phpstan analyse -c phpstan.neon"
}
}
2 changes: 1 addition & 1 deletion front/ruleimport.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
Html::displayNotFoundError();
}

$rulecollection = new PluginJamfRuleImportCollection($_SESSION['glpiactive_entity']);
$rulecollection = new PluginJamfRuleImportCollection();

include(GLPI_ROOT . "/front/rule.common.form.php");
2 changes: 1 addition & 1 deletion front/ruleimport.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
Html::displayNotFoundError();
}

$rulecollection = new PluginJamfRuleImportCollection($_SESSION['glpiactive_entity']);
$rulecollection = new PluginJamfRuleImportCollection();

include(GLPI_ROOT . "/front/rule.common.php");
10 changes: 5 additions & 5 deletions inc/config.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@ 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 '';
}

public function showForm($ID = -1, array $options = [])
{
global $CFG_GLPI;
if (!Session::haveRight('config', UPDATE)) {
return false;
}
Expand All @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions inc/connection.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion inc/devicesync.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
14 changes: 1 addition & 13 deletions inc/migration.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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);
}

Expand Down
3 changes: 2 additions & 1 deletion inc/profile.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public function showForm($profiles_id = 0, $openform = true, $closeform = true)
echo "<div class='spaced'>";
$profile = new Profile();
$profile->getFromDB($profiles_id);
if ($openform && ($canedit = Session::haveRightsOr(self::$rightname, [CREATE, UPDATE, PURGE]))) {
$canedit = Session::haveRightsOr(self::$rightname, [CREATE, UPDATE, PURGE]);
if ($openform && $canedit) {
echo "<form method='post' action='" . $profile::getFormURL() . "'>";
}

Expand Down
2 changes: 1 addition & 1 deletion inc/sync.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ abstract class PluginJamfSync
* @param CommonDBTM|null $item
* @param array $data
*/
public function __construct(CommonDBTM $item = null, array $data = [])
final public function __construct(CommonDBTM $item = null, array $data = [])
{
/** @global DBmysql */
global $DB;
Expand Down
3 changes: 2 additions & 1 deletion inc/user_jssaccount.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ public static function getTypeName($nb = 0)
public function prepareInputForUpdate($input)
{
global $DB;
if ($input['jssaccounts_id'] == 0) {
if ($input['jssaccounts_id'] === 0) {
$DB->delete(self::getTable(), ['id' => $this->fields['id']]);
return false;
}
return $input;
}

public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
Expand Down
14 changes: 14 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
parameters:
parallel:
maximumNumberOfProcesses: 2
level: 1
bootstrapFiles:
- ../../inc/includes.php
paths:
- ajax
- front
- inc
- setup.php
- hook.php
stubFiles:
- ../../stubs/glpi_constants.php
59 changes: 31 additions & 28 deletions setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,39 @@ function plugin_init_jamf()
global $PLUGIN_HOOKS;

$PLUGIN_HOOKS['csrf_compliant']['jamf'] = true;
$PLUGIN_HOOKS['add_javascript']['jamf'][] = 'js/jamf.js';
Plugin::registerClass('PluginJamfConfig', ['addtabon' => 'Config']);
$PLUGIN_HOOKS['post_item_form']['jamf'] = 'plugin_jamf_showJamfInfoForItem';
$PLUGIN_HOOKS['pre_item_update']['jamf']['Phone'] = ['PluginJamfMobileDevice', 'preUpdatePhone'];
$PLUGIN_HOOKS['undiscloseConfigValue']['jamf'] = [PluginJamfConfig::class, 'undiscloseConfigValue'];
Plugin::registerClass('PluginJamfRuleImportCollection', ['rulecollections_types' => true]);
Plugin::registerClass('PluginJamfProfile', ['addtabon' => ['Profile']]);
Plugin::registerClass('PluginJamfItem_ExtensionAttribute', ['addtabon' => [
'Computer',
'Phone'
]]);
Plugin::registerClass('PluginJamfItem_MDMCommand', ['addtabon' => [
'Computer',
'Phone'
]]);
Plugin::registerClass('PluginJamfUser_JSSAccount', ['addtabon' => ['User']]);
if (Session::haveRight('plugin_jamf_mobiledevice', READ)) {
$PLUGIN_HOOKS['menu_toadd']['jamf'] = ['tools' => 'PluginJamfMenu'];
}
$PLUGIN_HOOKS['post_init']['jamf'] = 'plugin_jamf_postinit';
$PLUGIN_HOOKS['item_purge']['jamf'] = [
'Computer' => ['PluginJamfAbstractDevice', 'plugin_jamf_purgeComputer'],
'Phone' => ['PluginJamfAbstractDevice', 'plugin_jamf_purgePhone'],
'Software' => ['PluginJamfSoftware', 'plugin_jamf_purgeSoftware']
];

// Dashboards
$PLUGIN_HOOKS['dashboard_cards']['jamf'] = 'plugin_jamf_dashboardCards';
if (Plugin::isPluginActive('jamf')) {
$PLUGIN_HOOKS['add_javascript']['jamf'][] = 'js/jamf.js';
Plugin::registerClass('PluginJamfConfig', ['addtabon' => 'Config']);
$PLUGIN_HOOKS['post_item_form']['jamf'] = 'plugin_jamf_showJamfInfoForItem';
$PLUGIN_HOOKS['pre_item_update']['jamf']['Phone'] = ['PluginJamfMobileDevice', 'preUpdatePhone'];
$PLUGIN_HOOKS['undiscloseConfigValue']['jamf'] = [PluginJamfConfig::class, 'undiscloseConfigValue'];
Plugin::registerClass('PluginJamfRuleImportCollection', ['rulecollections_types' => true]);
Plugin::registerClass('PluginJamfProfile', ['addtabon' => ['Profile']]);
Plugin::registerClass('PluginJamfItem_ExtensionAttribute', ['addtabon' => [
'Computer',
'Phone'
]]);
Plugin::registerClass('PluginJamfItem_MDMCommand', ['addtabon' => [
'Computer',
'Phone'
]]);
Plugin::registerClass('PluginJamfUser_JSSAccount', ['addtabon' => ['User']]);
if (Session::haveRight('plugin_jamf_mobiledevice', READ)) {
$PLUGIN_HOOKS['menu_toadd']['jamf'] = ['tools' => 'PluginJamfMenu'];
}
$PLUGIN_HOOKS['post_init']['jamf'] = 'plugin_jamf_postinit';
$PLUGIN_HOOKS['item_purge']['jamf'] = [
'Computer' => ['PluginJamfAbstractDevice', 'plugin_jamf_purgeComputer'],
'Phone' => ['PluginJamfAbstractDevice', 'plugin_jamf_purgePhone'],
'Software' => ['PluginJamfSoftware', 'plugin_jamf_purgeSoftware']
];

$PLUGIN_HOOKS['secured_configs']['Jamf'] = ['jsspassword'];
// Dashboards
$PLUGIN_HOOKS['dashboard_cards']['jamf'] = 'plugin_jamf_dashboardCards';

$PLUGIN_HOOKS['secured_configs']['Jamf'] = ['jsspassword'];
}
}

function plugin_version_jamf()
Expand Down
1 change: 0 additions & 1 deletion tests/units/PluginJamfComputerSync.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

namespace tests\units;

use DbTestCase;
use PluginJamfComputer;
use PluginJamfComputerTestSync;
use PluginJamfExtensionAttribute;
Expand Down
1 change: 0 additions & 1 deletion tests/units/PluginJamfMobileSync.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

namespace tests\units;

use DbTestCase;
use Phone;
use PluginJamfAbstractDevice;
use PluginJamfExtensionAttribute;
Expand Down

0 comments on commit 805ef67

Please sign in to comment.