Skip to content

Commit 24f0ac1

Browse files
authored
Add php-cs-fixer (#16)
* Add php-cs-fixer * Apply suggestions from code review * Update inc/api.class.php
1 parent 6da31da commit 24f0ac1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1592
-1367
lines changed

.php-cs-fixer.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
use PhpCsFixer\Config;
4+
use PhpCsFixer\Finder;
5+
6+
$finder = Finder::create()
7+
->in(__DIR__)
8+
->name('*.php')
9+
->ignoreVCSIgnored(true);
10+
11+
$config = new Config();
12+
13+
$rules = [
14+
'@PER-CS2.0' => true,
15+
'trailing_comma_in_multiline' => ['elements' => ['arguments', 'array_destructuring', 'arrays']], // For PHP 7.4 compatibility
16+
];
17+
18+
return $config
19+
->setRules($rules)
20+
->setFinder($finder)
21+
->setUsingCache(false);

RoboFile.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
2-
require_once 'vendor/autoload.php';
32

4-
class RoboFile extends Glpi\Tools\RoboFile
5-
{
3+
require_once 'vendor/autoload.php';
64

7-
}
5+
class RoboFile extends Glpi\Tools\RoboFile {}

ajax/cron.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* -------------------------------------------------------------------------
45
* JAMF plugin for GLPI

ajax/getMDMCommandForm.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* -------------------------------------------------------------------------
45
* JAMF plugin for GLPI
@@ -43,7 +44,7 @@
4344
}
4445

4546
if (isset($_GET['itemtype'], $_GET['items_id'])) {
46-
$device = new ('PluginJamf'.$_GET['itemtype'])();
47+
$device = new ('PluginJamf' . $_GET['itemtype'])();
4748
if (!$device->getFromDB($_GET['items_id'])) {
4849
throw new RuntimeException('Invalid itemtype/items_id!');
4950
}

ajax/import.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* -------------------------------------------------------------------------
45
* JAMF plugin for GLPI
@@ -56,10 +57,10 @@
5657
// Get data for each item to import
5758
$toimport = $DB->request([
5859
'SELECT' => ['type', 'jamf_type', 'jamf_items_id'],
59-
'FROM' => PluginJamfImport::getTable(),
60-
'WHERE' => [
61-
'id' => $_REQUEST['import_ids']
62-
]
60+
'FROM' => PluginJamfImport::getTable(),
61+
'WHERE' => [
62+
'id' => $_REQUEST['import_ids'],
63+
],
6364
]);
6465
// Trigger extension attribute definition sync
6566
PluginJamfMobileSync::syncExtensionAttributeDefinitions();
@@ -75,7 +76,7 @@
7576
} else {
7677
throw new RuntimeException('Required argument missing!');
7778
}
78-
} else if ($_REQUEST['action'] == 'clear') {
79+
} elseif ($_REQUEST['action'] == 'clear') {
7980
if (PluginJamfMobileDevice::canCreate() || PluginJamfComputer::canCreate()) {
8081
PluginJamfImport::clearPendingImports();
8182
}

ajax/merge.php

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* -------------------------------------------------------------------------
45
* JAMF plugin for GLPI
@@ -55,13 +56,13 @@
5556
PluginJamfComputerSync::syncExtensionAttributeDefinitions();
5657
// An array of item IDs is required
5758
if (isset($_REQUEST['item_ids']) && is_array($_REQUEST['item_ids'])) {
58-
$failures = 0;
59+
$failures = 0;
5960
$successes = 0;
6061
foreach ($_REQUEST['item_ids'] as $glpi_id => $data) {
6162
if (!isset($data['jamf_id'], $data['itemtype'])) {
6263
continue;
6364
}
64-
$jamf_id = $data['jamf_id'];
65+
$jamf_id = $data['jamf_id'];
6566
$itemtype = $data['itemtype'];
6667

6768
if (($itemtype !== 'Computer') && ($itemtype !== 'Phone')) {
@@ -93,15 +94,15 @@
9394

9495
//WTF is this, Jamf?
9596
$os_details = $jamf_item['ios'] ?? $jamf_item['tvos'] ?? '';
96-
$ruleinput = [
97-
'name' => $jamf_item['name'] ?? $jamf_item['general']['name'],
98-
'itemtype' => $itemtype,
97+
$ruleinput = [
98+
'name' => $jamf_item['name'] ?? $jamf_item['general']['name'],
99+
'itemtype' => $itemtype,
99100
'last_inventory' => $jamf_item['lastInventoryUpdateTimestamp'] ?? $jamf_item['general']['lastContactTime'],
100-
'managed' => $jamf_item['managed'] ?? $os_details['managed'],
101-
'supervised' => $jamf_item['supervised'] ?? $os_details['supervised'],
101+
'managed' => $jamf_item['managed'] ?? $os_details['managed'],
102+
'supervised' => $jamf_item['supervised'] ?? $os_details['supervised'],
102103
];
103104
$ruleinput = $rules->processAllRules($ruleinput, $ruleinput, ['recursive' => true]);
104-
$import = isset($ruleinput['_import']) ? $ruleinput['_import'] : 'NS';
105+
$import = isset($ruleinput['_import']) ? $ruleinput['_import'] : 'NS';
105106

106107
if (isset($ruleinput['_import']) && !$ruleinput['_import']) {
107108
// Dropped by rules
@@ -112,17 +113,17 @@
112113
try {
113114
// Partial import
114115
$r = $DB->insert('glpi_plugin_jamf_devices', [
115-
'itemtype' => $itemtype,
116-
'items_id' => $glpi_id,
117-
'udid' => $jamf_item['udid'],
118-
'jamf_type' => $data['jamf_type'],
116+
'itemtype' => $itemtype,
117+
'items_id' => $glpi_id,
118+
'udid' => $jamf_item['udid'],
119+
'jamf_type' => $data['jamf_type'],
119120
'jamf_items_id' => $data['jamf_id'],
120121
]);
121122
if ($r === false) {
122123
throw new \RuntimeException('Failed to import the device data!');
123124
}
124125
// Link
125-
$plugin_item = new $plugin_itemtype();
126+
$plugin_item = new $plugin_itemtype();
126127
$plugin_items_id = $plugin_item->add([
127128
'glpi_plugin_jamf_devices_id' => $DB->insertId(),
128129
]);
@@ -133,14 +134,14 @@
133134
// Update merged device and then delete the pending import
134135
if ($sync_result) {
135136
$DB->update('glpi_plugin_jamf_devices', [
136-
'import_date' => $_SESSION['glpi_currenttime']
137+
'import_date' => $_SESSION['glpi_currenttime'],
137138
], [
138139
'itemtype' => $itemtype,
139-
'items_id' => $glpi_id
140+
'items_id' => $glpi_id,
140141
]);
141142
$DB->delete(PluginJamfImport::getTable(), [
142-
'jamf_type' => $data['jamf_type'],
143-
'jamf_items_id' => $jamf_id
143+
'jamf_type' => $data['jamf_type'],
144+
'jamf_items_id' => $jamf_id,
144145
]);
145146
$DB->commit();
146147
$successes++;

ajax/sendMDMCommand.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* -------------------------------------------------------------------------
45
* JAMF plugin for GLPI
@@ -68,13 +69,13 @@
6869
foreach ($_POST['items_id'] as $items_id) {
6970
/** @var PluginJamfMobileDevice $item */
7071
$item = new PluginJamfMobileDevice();
71-
$item->getFromDB((int)$items_id);
72+
$item->getFromDB((int) $items_id);
7273
$items[] = $item;
7374
}
7475
}
7576

7677
foreach ($items as $k => $item) {
77-
$commands = PluginJamfItem_MDMCommand::getApplicableCommands($item);
78+
$commands = PluginJamfItem_MDMCommand::getApplicableCommands($item);
7879
$command_names = array_keys($commands);
7980

8081
if (!in_array($_POST['command'], $command_names, true)) {
@@ -88,16 +89,16 @@
8889
}
8990

9091
// The API endpoint for sending MDM commands only accepts XML, so we need to build the XML payload
91-
$payload = new SimpleXMLElement("<mobile_device_command/>");
92+
$payload = new SimpleXMLElement('<mobile_device_command/>');
9293
$general = $payload->addChild('general');
9394
$general->addChild('command', $_POST['command']);
9495
$fields = array_flip($fields);
9596
array_walk_recursive($fields, [$general, 'addChild']);
9697
$mobile_devices = $payload->addChild('mobile_devices');
9798
foreach ($items as $item) {
9899
$device_data = $item->getJamfDeviceData();
99-
$jamf_id = $device_data['jamf_items_id'];
100-
$m = $mobile_devices->addChild('mobile_device');
100+
$jamf_id = $device_data['jamf_items_id'];
101+
$m = $mobile_devices->addChild('mobile_device');
101102
$m->addChild('id', $jamf_id);
102103
}
103104
echo PluginJamfAPI::sendMDMCommand($payload->asXML(), true);

ajax/sync.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* -------------------------------------------------------------------------
45
* JAMF plugin for GLPI

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"php": "~7.4.0|~8.0.0|~8.1.0|~8.2.0"
44
},
55
"require-dev": {
6+
"friendsofphp/php-cs-fixer": "^3.68",
67
"glpi-project/tools": "^0.7.2",
78
"phpstan/phpstan": "^1.10",
89
"phpunit/phpunit": "~9.6"

front/extfield.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* -------------------------------------------------------------------------
45
* JAMF plugin for GLPI

0 commit comments

Comments
 (0)