Skip to content

Commit

Permalink
style: run composer run cs:fix
Browse files Browse the repository at this point in the history
  • Loading branch information
zak39 committed Dec 5, 2024
1 parent 6fe4de0 commit c5f429b
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 32 deletions.
10 changes: 4 additions & 6 deletions lib/Controller/FileCSVController.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,15 @@ 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'),
$this->translate->t('Your CSV file must use a comma (",") as separator'),
);
}

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'),
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion lib/Files/Csv/CsvReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion lib/Files/Csv/ImportUsers/HeaderExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
23 changes: 11 additions & 12 deletions lib/Files/Csv/StructureValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
11 changes: 5 additions & 6 deletions lib/Files/FileUploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class FileUploader implements FileInterface {
private $resource;

private string|false $lineEnding;
private string|false $lineEnding;

public function __construct(private string $path) {
}
Expand All @@ -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) {
Expand All @@ -27,16 +27,15 @@ 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);
}

public function getPath(): string {
return $this->path;
}

public function getSize(): false|int|float
{
public function getSize(): false|int|float {
return filesize($this->path);
}
}
11 changes: 5 additions & 6 deletions lib/Files/NextcloudFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class NextcloudFile implements FileInterface {
private $resource;

private string|false $lineEnding;
private string|false $lineEnding;

public function __construct(private Node $file) {
}
Expand All @@ -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");

Expand All @@ -30,16 +30,15 @@ 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);
}

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());
}
Expand Down

0 comments on commit c5f429b

Please sign in to comment.