mirror of
https://github.com/brufdev/many-notes.git
synced 2026-04-28 21:40:21 -05:00
Refactor with Larastan
This commit is contained in:
@@ -15,7 +15,9 @@ final class ProcessImportedFile
|
||||
{
|
||||
public function handle(Vault $vault, VaultNode $parent, string $fileName, string $filePath): void
|
||||
{
|
||||
['filename' => $name, 'extension' => $extension] = pathinfo($fileName);
|
||||
$pathInfo = pathinfo($fileName);
|
||||
$name = $pathInfo['filename'];
|
||||
$extension = $pathInfo['extension'] ?? '';
|
||||
|
||||
if (! in_array($extension, VaultFile::extensions())) {
|
||||
abort(400);
|
||||
@@ -35,6 +37,7 @@ final class ProcessImportedFile
|
||||
->where('extension', 'md')
|
||||
->exists();
|
||||
if ($nodeExists) {
|
||||
/** @var list<string> $nodes */
|
||||
$nodes = array_column(
|
||||
$vault->nodes()
|
||||
->select('name')
|
||||
@@ -47,7 +50,7 @@ final class ProcessImportedFile
|
||||
'name',
|
||||
);
|
||||
natcasesort($nodes);
|
||||
$name .= count($nodes) && preg_match('/-(\d+)$/', (string) end($nodes), $matches) === 1 ?
|
||||
$name .= count($nodes) && preg_match('/-(\d+)$/', end($nodes), $matches) === 1 ?
|
||||
'-'.((int) $matches[1] + 1) :
|
||||
'-1';
|
||||
}
|
||||
@@ -61,7 +64,9 @@ final class ProcessImportedFile
|
||||
]);
|
||||
|
||||
$relativePath = new GetPathFromVaultNode()->handle($node);
|
||||
['dirname' => $savePath, 'basename' => $saveName] = pathinfo($relativePath);
|
||||
$pathInfo = pathinfo($relativePath);
|
||||
$savePath = $pathInfo['dirname'] ?? '';
|
||||
$saveName = $pathInfo['basename'];
|
||||
Storage::putFileAs($savePath, new File($filePath), $saveName);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user