Skip to content

Commit

Permalink
composer cs
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaBaoFa committed Sep 9, 2024
1 parent bb90f40 commit 6acbf25
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
4 changes: 4 additions & 0 deletions app/Command/TestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ public function configure()
*/
public function handle(): void
{
$arr = [1,2,3,4,5,6];
var_dump(end($arr));
return ;
//
$online_zip = file_get_contents('http://json.think-region.yupoxiong.com/region.json.zip?v=' . uniqid('region', true));
$zip_file = BASE_PATH . '/region.json.zip';
file_put_contents($zip_file, $online_zip);
Expand Down
42 changes: 22 additions & 20 deletions app/Service/DiskService.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ public function getSelectTree(): array
public function update(mixed $id, array $data): bool
{
$handleData = $this->handleData($data);
if (!$this->checkChildrenExists($id)) {
if (! $this->checkChildrenExists($id)) {
return $this->dao->update($id, $handleData);
}
$update[] = [
'id' => $id,
'data' => $handleData,
];
$descendants = $this->dao->getDescendants(parentId: (int)$id);
$descendants = $this->dao->getDescendants(parentId: (int) $id);
foreach ($descendants as $descendant) {
$handleDescendantLevelData = $this->handleDescendantLevels($descendant['level'], $handleData['level'], $id);
$update[] = [
Expand All @@ -76,7 +76,7 @@ public function realDelete(array $ids): bool
{
// 判断$items
foreach ($ids as $id) {
if (!$this->belongMe(['id' => $id])) {
if (! $this->belongMe(['id' => $id])) {
throw new BusinessException(ErrorCode::DISK_FILE_NOT_EXIST);
}
}
Expand All @@ -103,7 +103,7 @@ public function saveFolder(array $data): int
public function getDownloadTokens(array $hashes): array
{
foreach ($hashes as $hash) {
if (!$this->belongMe(['hash' => $hash])) {
if (! $this->belongMe(['hash' => $hash])) {
throw new BusinessException(ErrorCode::DISK_FILE_NOT_EXIST);
}
}
Expand All @@ -116,12 +116,12 @@ public function getFolderMeta(array $data, $column = ['id', 'name', 'level', 'pa
$folderId = 0;
if (Arr::get($data, 'id') > 0) {
$folderId = Arr::get($data, 'id');
(!$this->dao->isFolder((int)$folderId)) && throw new BusinessException(ErrorCode::DISK_FOLDER_NOT_EXIST);
(! $this->dao->isFolder((int) $folderId)) && throw new BusinessException(ErrorCode::DISK_FOLDER_NOT_EXIST);
}
if ($path = Arr::get($data, 'path')) {
$folderId = $this->getFolderIdByPath($path);
}
if (! $folderId){
if (! $folderId) {
throw new BusinessException(ErrorCode::DISK_FOLDER_NOT_EXIST);
}
$currentFolder = $this->find($folderId, $column);
Expand All @@ -131,7 +131,7 @@ public function getFolderMeta(array $data, $column = ['id', 'name', 'level', 'pa
$folders = explode(',', $currentFolder->level);
$ancestor = [];
foreach ($folders as $key => $folderId) {
if ((int)$folderId == 0) {
if ((int) $folderId == 0) {
Arr::set($ancestor, $folderId, '根目录');
continue;
}
Expand All @@ -149,7 +149,7 @@ public function getFolderMeta(array $data, $column = ['id', 'name', 'level', 'pa
public function listContents(int $folder_id = 0): array
{
if ($folder_id > 0) {
(!$this->dao->isFolder($folder_id)) && throw new BusinessException(ErrorCode::DISK_FOLDER_NOT_EXIST);
(! $this->dao->isFolder($folder_id)) && throw new BusinessException(ErrorCode::DISK_FOLDER_NOT_EXIST);
}
return $this->getPageList([
'parent_id' => $folder_id,
Expand All @@ -163,7 +163,7 @@ public function rename(int $item_id, string $newName): bool
*/
$item = $this->dao->find($item_id);
// 1. 检查文件是否存在
if (!$item) {
if (! $item) {
throw new BusinessException(ErrorCode::DISK_FILE_NOT_EXIST);
}
if ($item->name == $newName) {
Expand All @@ -172,7 +172,7 @@ public function rename(int $item_id, string $newName): bool
$item = $item->toArray();
// 2. 检查文件名是否已存在
Arr::set($item, 'name', $newName);
$this->checkNameExists((int)Arr::get($item, 'parent_id', 0), $item);
$this->checkNameExists((int) Arr::get($item, 'parent_id', 0), $item);
return $this->dao->update($item_id, $item);
}

Expand All @@ -190,9 +190,9 @@ public function checkNameExists(int $pid, array $data): array

public function getPid(array $data): int
{
$pid = (int)Arr::get($data, 'parent_id', 0);
$pid = (int) Arr::get($data, 'parent_id', 0);
if ($pid > 0) {
(!$this->dao->isFolder($pid)) && throw new BusinessException(ErrorCode::DISK_FOLDER_NOT_EXIST);
(! $this->dao->isFolder($pid)) && throw new BusinessException(ErrorCode::DISK_FOLDER_NOT_EXIST);
}
return $pid;
}
Expand All @@ -218,7 +218,7 @@ public function move(array $items, int $targetFolderId): bool
throw new BusinessException(ErrorCode::DISK_FOLDER_ILLEGAL_SELECTED);
}
Arr::set($diskFile, 'parent_id', $targetFolderId);
if (!$this->update(Arr::get($diskFile, $pk), $diskFile)) {
if (! $this->update(Arr::get($diskFile, $pk), $diskFile)) {
return false;
}
}
Expand All @@ -229,7 +229,7 @@ public function delete(array $ids): bool
{
// 判断$items
foreach ($ids as $id) {
if (!$this->belongMe(['id' => $id])) {
if (! $this->belongMe(['id' => $id])) {
throw new BusinessException(ErrorCode::DISK_FILE_NOT_EXIST);
}
}
Expand All @@ -241,7 +241,7 @@ public function recovery(array $ids): bool
{
// 判断$items
foreach ($ids as $id) {
if (!$this->belongMe(['id' => $id])) {
if (! $this->belongMe(['id' => $id])) {
throw new BusinessException(ErrorCode::DISK_FILE_NOT_EXIST);
}
}
Expand Down Expand Up @@ -294,7 +294,7 @@ public function search(array $query): array

public function getHash(int $folder_id): array
{
if (!$this->dao->isFolder($folder_id) && !$this->belongMe(['id' => $folder_id])) {
if (! $this->dao->isFolder($folder_id) && ! $this->belongMe(['id' => $folder_id])) {
throw new BusinessException(ErrorCode::DISK_FOLDER_NOT_EXIST);
}
$cols = ['id', 'name', 'hash'];
Expand All @@ -314,7 +314,7 @@ private function handleFileData(array $data): array
{
// 文件name、hash
$fs = di()->get(FileSystemService::class);
if (!$fs->dao->isUploaded(Arr::get($data, 'hash'))) {
if (! $fs->dao->isUploaded(Arr::get($data, 'hash'))) {
throw new BusinessException(ErrorCode::FILE_HAS_NOT_BEEN_UPLOADED);
}
$file = $fs->dao->getFileInfoByHash(Arr::get($data, 'hash'));
Expand Down Expand Up @@ -342,9 +342,9 @@ private function handleData(array $data): array
private function handleLevel(array $data): array
{
if (Arr::get($data, 'parent_id', 0) === 0) {
Arr::set($data, 'level', (string)Arr::get($data, 'parent_id', '0'));
Arr::set($data, 'level', (string) Arr::get($data, 'parent_id', '0'));
} else {
$parent = $this->find((int)Arr::get($data, 'parent_id'));
$parent = $this->find((int) Arr::get($data, 'parent_id'));
/**
* @var DiskFile $parent
*/
Expand Down Expand Up @@ -391,7 +391,9 @@ private function getFolderIdByPath(string $path): int
'/',
trim(
$path,
'/'));
'/'
)
);
$currentPid = 0;
foreach ($path as $key => $value) {
// 判断每个文件夹是否存在
Expand Down

0 comments on commit 6acbf25

Please sign in to comment.