From c5f429bfbf5985c722dddd3ad2b71d85822627a9 Mon Sep 17 00:00:00 2001 From: zak39 Date: Thu, 5 Dec 2024 16:04:42 +0100 Subject: [PATCH] style: run composer run cs:fix --- lib/Controller/FileCSVController.php | 10 ++++---- lib/Files/Csv/CsvReader.php | 2 +- lib/Files/Csv/ImportUsers/HeaderExtractor.php | 2 +- lib/Files/Csv/StructureValidator.php | 23 +++++++++---------- lib/Files/FileUploader.php | 11 ++++----- lib/Files/NextcloudFile.php | 11 ++++----- 6 files changed, 27 insertions(+), 32 deletions(-) diff --git a/lib/Controller/FileCSVController.php b/lib/Controller/FileCSVController.php index 086c4a391..7b0e0164b 100644 --- a/lib/Controller/FileCSVController.php +++ b/lib/Controller/FileCSVController.php @@ -90,8 +90,7 @@ public function __construct( * @param array $space represents a workspace in array * @return array */ - private function importProcess(FileInterface $file, array $space): array - { + private function importProcess(FileInterface $file, array $space): array { if (!SeparatorDetector::isComma($file) || !SeparatorDetector::isCommaForAllFile($file)) { throw new InvalidSeparatorCsvException( $this->translate->t('Invalid separator for CSV file'), @@ -99,8 +98,7 @@ private function importProcess(FileInterface $file, array $space): array ); } - if (!StructureValidator::checkCommaAllLines($file)) - { + if (!StructureValidator::checkCommaAllLines($file)) { throw new InvalidSeparatorCsvException( $this->translate->t('Invalid separator for CSV file'), $this->translate->t('Your CSV file must use a comma (",") as separator'), @@ -241,9 +239,9 @@ function ($name) { /** * @NoAdminRequired * @SpaceAdminRequired - * + * * @param int $spaceId is the spaceId from workspace - * + * * Returns formatted list of existing users of the instance. */ public function import(?int $spaceId = null): JSONResponse { diff --git a/lib/Files/Csv/CsvReader.php b/lib/Files/Csv/CsvReader.php index 198ac5834..00099b6e5 100644 --- a/lib/Files/Csv/CsvReader.php +++ b/lib/Files/Csv/CsvReader.php @@ -13,7 +13,7 @@ class CsvReader { public function __construct(private BasicStreamInterface $file) { $handle = $file->open(); $headers = fgetcsv($handle, 1000, Separator::COMMA); - $this->headers = array_map(function($header) { + $this->headers = array_map(function ($header) { return preg_replace('/[\x00-\x1F\x7F\x{200B}-\x{200D}\x{FEFF}]/u', '', trim($header)); }, $headers); $file->close(); diff --git a/lib/Files/Csv/ImportUsers/HeaderExtractor.php b/lib/Files/Csv/ImportUsers/HeaderExtractor.php index 45952ede2..ae9191418 100644 --- a/lib/Files/Csv/ImportUsers/HeaderExtractor.php +++ b/lib/Files/Csv/ImportUsers/HeaderExtractor.php @@ -7,7 +7,7 @@ class HeaderExtractor implements CsvHeaderExtractorInterface { public static function getIndex(array $haystack, array $needles): int|bool { $index = null; - $needles = array_map(function($needle) { + $needles = array_map(function ($needle) { return preg_replace('/[\x00-\x1F\x7F\x{200B}-\x{200D}\x{FEFF}]/u', '', trim($needle)); }, $needles); foreach($haystack as $key => $value) { diff --git a/lib/Files/Csv/StructureValidator.php b/lib/Files/Csv/StructureValidator.php index 8ba207bc0..fc3200b24 100644 --- a/lib/Files/Csv/StructureValidator.php +++ b/lib/Files/Csv/StructureValidator.php @@ -5,18 +5,17 @@ use OCA\Workspace\Files\Csv\ImportUsers\Header; use OCA\Workspace\Files\FileInterface; -class StructureValidator -{ - - public static function checkCommaAllLines(FileInterface $file): bool { +class StructureValidator { + + public static function checkCommaAllLines(FileInterface $file): bool { $handle = $file->open(); - $nbFieldsRequired = count(Header::FIELDS_REQUIRED); - while(($data = fgetcsv($handle, 1000, Separator::COMMA)) !== false) { - if (count($data) < $nbFieldsRequired) { - return false; - } - } + $nbFieldsRequired = count(Header::FIELDS_REQUIRED); + while(($data = fgetcsv($handle, 1000, Separator::COMMA)) !== false) { + if (count($data) < $nbFieldsRequired) { + return false; + } + } - return true; - } + return true; + } } diff --git a/lib/Files/FileUploader.php b/lib/Files/FileUploader.php index 7a774da18..9a10e85db 100644 --- a/lib/Files/FileUploader.php +++ b/lib/Files/FileUploader.php @@ -5,7 +5,7 @@ class FileUploader implements FileInterface { private $resource; - private string|false $lineEnding; + private string|false $lineEnding; public function __construct(private string $path) { } @@ -15,8 +15,8 @@ public function __construct(private string $path) { * @throws \Exception */ public function open(?string $path = null) { - $this->lineEnding = ini_get("auto_detect_line_endings"); - ini_set("auto_detect_line_endings", true); + $this->lineEnding = ini_get("auto_detect_line_endings"); + ini_set("auto_detect_line_endings", true); $this->resource = fopen($this->path, "r"); if (!$this->resource) { @@ -27,7 +27,7 @@ public function open(?string $path = null) { } public function close(): bool { - ini_set("auto_detect_line_endings", $this->lineEnding); + ini_set("auto_detect_line_endings", $this->lineEnding); return fclose($this->resource); } @@ -35,8 +35,7 @@ public function getPath(): string { return $this->path; } - public function getSize(): false|int|float - { + public function getSize(): false|int|float { return filesize($this->path); } } diff --git a/lib/Files/NextcloudFile.php b/lib/Files/NextcloudFile.php index 2f4f90e06..38ccaf352 100644 --- a/lib/Files/NextcloudFile.php +++ b/lib/Files/NextcloudFile.php @@ -7,7 +7,7 @@ class NextcloudFile implements FileInterface { private $resource; - private string|false $lineEnding; + private string|false $lineEnding; public function __construct(private Node $file) { } @@ -17,8 +17,8 @@ public function __construct(private Node $file) { * @throws \Exception */ public function open(?string $path = null) { - $this->lineEnding = ini_get("auto_detect_line_endings"); - ini_set("auto_detect_line_endings", true); + $this->lineEnding = ini_get("auto_detect_line_endings"); + ini_set("auto_detect_line_endings", true); $store = $this->file->getStorage(); $this->resource = $store->fopen($this->file->getInternalPath(), "r"); @@ -30,7 +30,7 @@ public function open(?string $path = null) { } public function close(): bool { - ini_set("auto_detect_line_endings", $this->lineEnding); + ini_set("auto_detect_line_endings", $this->lineEnding); return fclose($this->resource); } @@ -38,8 +38,7 @@ public function getPath(): string { return $this->file->getInternalPath(); } - public function getSize(): false|int|float - { + public function getSize(): false|int|float { $store = $this->file->getStorage(); return $store->filesize($this->file->getInternalPath()); }