diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 7a81c5ba..4c7cac87 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -3,19 +3,26 @@ use PhpCsFixer\Config; use PhpCsFixer\Finder; +$baseline_file = __DIR__ . '/../../PluginsPhpCsFixer.php'; +if (!file_exists($baseline_file)) { + throw new RuntimeException( + sprintf( + 'Unable to find "%s". Running php-cs-fixer on a plugin requires a GLPI development checkout that ships PluginsPhpCsFixer.php.', + $baseline_file, + ), + ); +} + +$baseline = require $baseline_file; + $finder = Finder::create() ->in(__DIR__) - ->name('*.php') - ->ignoreVCSIgnored(true); - -$config = new Config(); + ->ignoreVCSIgnored(true) + ->name('*.php'); -$rules = [ - '@PER-CS2.0' => true, - 'trailing_comma_in_multiline' => ['elements' => ['arguments', 'array_destructuring', 'arrays']], // For PHP 7.4 compatibility -]; +/** @var Config $config */ +$config = $baseline($finder); return $config - ->setRules($rules) - ->setFinder($finder) - ->setUsingCache(false); + ->setCacheFile(__DIR__ . '/var/php-cs-fixer/.php-cs-fixer.cache') +; diff --git a/CHANGELOG.md b/CHANGELOG.md index 46dc0a19..ef2d8d68 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Add Transifex translations link to README +### Fixed + +- CI: use the GLPI shared php-cs-fixer configuration and apply its coding style + ## [2.16.0] - 2026-10-05 ### Fixed diff --git a/inc/backend.class.php b/inc/backend.class.php index 9e49c18f..61adb829 100644 --- a/inc/backend.class.php +++ b/inc/backend.class.php @@ -28,7 +28,6 @@ * ------------------------------------------------------------------------- */ - use function Safe\preg_match; /* @@ -57,7 +56,7 @@ abstract class PluginDatainjectionBackend * Get header of the file * * @param PluginDatainjectionData|null $injectionData - * @param boolean $header_present + * @param bool $header_present * * @return array with the data from the header **/ diff --git a/inc/backendcsv.class.php b/inc/backendcsv.class.php index 2ffd2cac..fce042a6 100644 --- a/inc/backendcsv.class.php +++ b/inc/backendcsv.class.php @@ -74,7 +74,7 @@ public function setDelimiter($delimiter) /** - * @param boolean $present (true by default) + * @param bool $present (true by default) **/ public function setHeaderPresent($present = true) { @@ -88,7 +88,7 @@ public function setHeaderPresent($present = true) * * @param mixed $fic * @param array $data - * @param integer $encoding (default 1) + * @param int $encoding (default 1) **/ public static function parseLine($fic, $data, $encoding = 1) { @@ -123,7 +123,7 @@ public function init($newfile, $encoding) /** * Read a CSV file and store data in an array * - * @param integer $numberOfLines inumber of lines to be read (-1 means all file) (default 1) + * @param int $numberOfLines inumber of lines to be read (-1 means all file) (default 1) **/ public function read($numberOfLines = 1) { diff --git a/inc/backendinterface.class.php b/inc/backendinterface.class.php index 5d36b974..efba52a7 100644 --- a/inc/backendinterface.class.php +++ b/inc/backendinterface.class.php @@ -36,7 +36,7 @@ interface PluginDatainjectionBackendInterface /** * Read from file * - * @param integer $numberOfLines (default 1) + * @param int $numberOfLines (default 1) **/ public function read($numberOfLines = 1); diff --git a/inc/clientinjection.class.php b/inc/clientinjection.class.php index 480cf6a6..c39fdd01 100644 --- a/inc/clientinjection.class.php +++ b/inc/clientinjection.class.php @@ -128,7 +128,7 @@ public static function showUploadFileForm($options = []) /** * @param PluginDatainjectionModel $model PluginDatainjectionModel object - * @param integer $entities_id + * @param int $entities_id **/ public static function showInjectionForm(PluginDatainjectionModel $model, $entities_id) { diff --git a/inc/commoninjectionlib.class.php b/inc/commoninjectionlib.class.php index 97d6ceb9..7cf5d53a 100644 --- a/inc/commoninjectionlib.class.php +++ b/inc/commoninjectionlib.class.php @@ -293,7 +293,7 @@ public function areTypeMandatoryFieldsOK($injectionClass) * * @param string $field_type the type of field * - * @return boolean true if it's a dropdown type, false if not + * @return bool true if it's a dropdown type, false if not **/ public static function isFieldADropdown($field_type) { @@ -599,7 +599,7 @@ private function getFieldValue( $itemtype, $searchOption, $field, - $value + $value, ) { $linkfield = $searchOption['storevaluein'] ?? $searchOption['linkfield']; @@ -969,7 +969,7 @@ private function unsetValue($itemtype, $field) * @param string $itemtype * @param string $field name * @param string|int $value of the field - * @param boolean $fromdb boolean + * @param bool $fromdb boolean **/ private function setValueForItemtype($itemtype, $field, $value, $fromdb = false) { @@ -1409,7 +1409,7 @@ private function check() * * @param mixed $val the value to check * - * @return boolean true if it's a float, false otherwise + * @return bool true if it's a float, false otherwise */ private function isFloat($val) { @@ -1422,7 +1422,7 @@ private function isFloat($val) * * @param mixed $val the value to check * - * @return boolean true if it's an integer, false otherwise + * @return bool true if it's an integer, false otherwise */ private function isInteger($val) { @@ -1437,7 +1437,7 @@ private function isInteger($val) * @param array $option the option associated with the field * @param string $field_name the field name * @param mixed $data the data to check - * @param boolean $mandatory is the field mandatory + * @param bool $mandatory is the field mandatory * * @return int the result of the check **/ @@ -1772,7 +1772,7 @@ public function processAddOrUpdate() /** * Flag the current line as partially injected and log the reason * - * @param integer $code log label describing the reason + * @param int $code log label describing the reason * @param string $itemtype itemtype that could not be written **/ private function addCheckWarning(int $code, string $itemtype): void @@ -1789,7 +1789,7 @@ private function addCheckWarning(int $code, string $itemtype): void * @param PluginDatainjectionInjectionInterface $injectionClass class which represents the object to inject * @param CommonDBTM $item the CommonDBTM object representing the itemtype to inject * @param array|string|false $values the values to inject - * @param boolean $add true to insert an object, false to update an existing object + * @param bool $add true to insert an object, false to update an existing object * * @return int|string the id of the object added or updated **/ @@ -2252,7 +2252,7 @@ private function addTemplateFields($itemtype) * Log event into the history * * @param object $item the item to log - * @param boolean $add true if it's an add, false if it's an update + * @param bool $add true if it's an add, false if it's an update * * @return void nothing **/ @@ -2354,7 +2354,7 @@ public static function getLogLabel($type) public static function addToSearchOptions( array $type_searchOptions, array $options, - PluginDatainjectionInjectionInterface $injectionClass + PluginDatainjectionInjectionInterface $injectionClass, ) { self::addTemplateSearchOptions($injectionClass, $type_searchOptions); diff --git a/inc/data.class.php b/inc/data.class.php index a95f013d..dbf0a21f 100644 --- a/inc/data.class.php +++ b/inc/data.class.php @@ -51,7 +51,7 @@ public function getData() /** - * @param integer $line_id + * @param int $line_id **/ public function getDataAtLine($line_id) { diff --git a/inc/devicecaseinjection.class.php b/inc/devicecaseinjection.class.php index 8814ad56..c1b836bd 100644 --- a/inc/devicecaseinjection.class.php +++ b/inc/devicecaseinjection.class.php @@ -82,7 +82,7 @@ public function getOptions($primary_type = '') /** * @param array $values - * @param boolean $add (true by default) + * @param bool $add (true by default) * @param array|null $rights array **/ public function processAfterInsertOrUpdate($values, $add = true, $rights = []) diff --git a/inc/devicecontrolinjection.class.php b/inc/devicecontrolinjection.class.php index 503d6bd5..83fbf07a 100644 --- a/inc/devicecontrolinjection.class.php +++ b/inc/devicecontrolinjection.class.php @@ -83,7 +83,7 @@ public function getOptions($primary_type = '') /** * @param array $values - * @param boolean $add (true by default) + * @param bool $add (true by default) * @param array|null $rights array **/ public function processAfterInsertOrUpdate($values, $add = true, $rights = []) diff --git a/inc/devicedriveinjection.class.php b/inc/devicedriveinjection.class.php index 668e7af0..d5d279a5 100644 --- a/inc/devicedriveinjection.class.php +++ b/inc/devicedriveinjection.class.php @@ -83,7 +83,7 @@ public function getOptions($primary_type = '') /** * @param array $values - * @param boolean $add (true by default) + * @param bool $add (true by default) * @param array|null $rights array */ public function processAfterInsertOrUpdate($values, $add = true, $rights = []) diff --git a/inc/deviceharddriveinjection.class.php b/inc/deviceharddriveinjection.class.php index 240b3df5..9b245e11 100644 --- a/inc/deviceharddriveinjection.class.php +++ b/inc/deviceharddriveinjection.class.php @@ -84,7 +84,7 @@ public function getOptions($primary_type = '') /** * @param array $values - * @param boolean $add (true by default) + * @param bool $add (true by default) * @param array|null $rights array */ public function processAfterInsertOrUpdate($values, $add = true, $rights = []) diff --git a/inc/devicememoryinjection.class.php b/inc/devicememoryinjection.class.php index d6ab5daa..5cdc8c6b 100644 --- a/inc/devicememoryinjection.class.php +++ b/inc/devicememoryinjection.class.php @@ -84,7 +84,7 @@ public function getOptions($primary_type = '') /** * @param array $values - * @param boolean $add (true by default) + * @param bool $add (true by default) * @param array|null $rights array **/ public function processAfterInsertOrUpdate($values, $add = true, $rights = []) diff --git a/inc/devicemotherboardinjection.class.php b/inc/devicemotherboardinjection.class.php index d508ffb0..cc640a72 100644 --- a/inc/devicemotherboardinjection.class.php +++ b/inc/devicemotherboardinjection.class.php @@ -84,7 +84,7 @@ public function getOptions($primary_type = '') /** * @param array $values - * @param boolean $add (true by default) + * @param bool $add (true by default) * @param array|null $rights array */ public function processAfterInsertOrUpdate($values, $add = true, $rights = []) diff --git a/inc/devicenetworkcardinjection.class.php b/inc/devicenetworkcardinjection.class.php index 5aa5c71a..f64471b9 100644 --- a/inc/devicenetworkcardinjection.class.php +++ b/inc/devicenetworkcardinjection.class.php @@ -82,7 +82,7 @@ public function getOptions($primary_type = '') /** * @param array $values - * @param boolean $add (true by default) + * @param bool $add (true by default) * @param array|null $rights array */ public function processAfterInsertOrUpdate($values, $add = true, $rights = []) diff --git a/inc/deviceprocessorinjection.class.php b/inc/deviceprocessorinjection.class.php index 9a65ac45..726280f9 100644 --- a/inc/deviceprocessorinjection.class.php +++ b/inc/deviceprocessorinjection.class.php @@ -84,7 +84,7 @@ public function getOptions($primary_type = '') /** * @param array $values - * @param boolean $add (true by default) + * @param bool $add (true by default) * @param array|null $rights array **/ public function processAfterInsertOrUpdate($values, $add = true, $rights = []) diff --git a/inc/dropdown.class.php b/inc/dropdown.class.php index 8358fa16..f0777cc5 100644 --- a/inc/dropdown.class.php +++ b/inc/dropdown.class.php @@ -103,8 +103,8 @@ public static function getFileEncodingValue() public static function portUnicityValues() { - return [__('Port number'), __('Name'), __('Mac address'), __('Port number') . "+" . __('Name'), __('Port number') . "+" . __('Mac address'), __('Port number') . "+" . __('Name') . "+" . - __('Mac address')]; + return [__('Port number'), __('Name'), __('Mac address'), __('Port number') . "+" . __('Name'), __('Port number') . "+" . __('Mac address'), __('Port number') . "+" . __('Name') . "+" + . __('Mac address')]; } diff --git a/inc/engine.class.php b/inc/engine.class.php index fbd8e4c8..020538e1 100644 --- a/inc/engine.class.php +++ b/inc/engine.class.php @@ -181,7 +181,7 @@ public function addValueToInject( $searchOptions, $mapping, $value, - $several = [] + $several = [], ): void { // Option will be found only for "main" type. diff --git a/inc/entityinjection.class.php b/inc/entityinjection.class.php index d295f4f0..040f07a6 100644 --- a/inc/entityinjection.class.php +++ b/inc/entityinjection.class.php @@ -114,7 +114,7 @@ public static function getRootEntityName() /** * @param array $input array - * @param boolean $add (true by default) + * @param bool $add (true by default) * @param array|null $rights array **/ public function customimport($input = [], $add = true, $rights = []) diff --git a/inc/info.class.php b/inc/info.class.php index 4527d57e..4e42a52d 100644 --- a/inc/info.class.php +++ b/inc/info.class.php @@ -30,8 +30,8 @@ use Glpi\Application\View\TemplateRenderer; -use function Safe\ob_start; use function Safe\ob_get_clean; +use function Safe\ob_start; class PluginDatainjectionInfo extends CommonDBTM { @@ -74,14 +74,14 @@ public function getInfosType() /** * @param PluginDatainjectionModel $model PluginDatainjectionModel object - * @param boolean $canedit (false by default) + * @param bool $canedit (false by default) **/ public static function showAddInfo(PluginDatainjectionModel $model, $canedit = false) { if ($canedit) { - echo "