1 | <?php |
||||
2 | declare(strict_types=1); |
||||
3 | |||||
4 | namespace tkanstantsin\fileupload\saver; |
||||
5 | |||||
6 | use League\Flysystem\FilesystemInterface; |
||||
7 | use tkanstantsin\fileupload\FileManager; |
||||
8 | use tkanstantsin\fileupload\formatter\Factory as FormatterFactory; |
||||
9 | use tkanstantsin\fileupload\model\IFile; |
||||
10 | |||||
11 | /** |
||||
12 | * Class FileDuplicator makes full copy of existed file (only content) |
||||
13 | */ |
||||
14 | class Replicator |
||||
15 | { |
||||
16 | /** |
||||
17 | * @var FileManager |
||||
18 | */ |
||||
19 | protected $fileManager; |
||||
20 | /** |
||||
21 | * @var IFile |
||||
22 | */ |
||||
23 | protected $originalFile; |
||||
24 | /** |
||||
25 | * @var FilesystemInterface |
||||
26 | */ |
||||
27 | protected $originalFS; |
||||
28 | /** |
||||
29 | * @var IFile |
||||
30 | */ |
||||
31 | protected $replicaFile; |
||||
32 | /** |
||||
33 | * @var FilesystemInterface |
||||
34 | */ |
||||
35 | protected $replicaFS; |
||||
36 | |||||
37 | /** |
||||
38 | * FileSaver constructor. |
||||
39 | * @param FileManager $fileManager |
||||
40 | * @param IFile $originalFile |
||||
41 | * @param FilesystemInterface $originalFS |
||||
42 | * @param IFile $replicaFile |
||||
43 | * @param FilesystemInterface $replicaFS |
||||
44 | */ |
||||
45 | public function __construct(FileManager $fileManager, |
||||
46 | IFile $originalFile, |
||||
47 | FilesystemInterface $originalFS, |
||||
48 | IFile $replicaFile, |
||||
49 | FilesystemInterface $replicaFS) |
||||
50 | { |
||||
51 | $this->fileManager = $fileManager; |
||||
52 | $this->originalFile = $originalFile; |
||||
53 | $this->originalFS = $originalFS; |
||||
54 | $this->replicaFile = $replicaFile; |
||||
55 | $this->replicaFS = $replicaFS; |
||||
56 | } |
||||
57 | |||||
58 | /** |
||||
59 | * @return bool |
||||
60 | * @throws \InvalidArgumentException |
||||
61 | * @throws \RuntimeException |
||||
62 | * @throws \League\Flysystem\FileNotFoundException |
||||
63 | * @throws \tkanstantsin\fileupload\config\InvalidConfigException |
||||
64 | */ |
||||
65 | public function run(): bool |
||||
66 | { |
||||
67 | $originalFileFormatter = $this->fileManager->buildFormatter( |
||||
68 | $this->replicaFile, |
||||
69 | FormatterFactory::FILE_ORIGINAL |
||||
70 | ); |
||||
71 | |||||
72 | $replicaAlias = $this->fileManager->getAliasConfig($this->replicaFile->getModelAlias()); |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
73 | $newPath = $replicaAlias->getFilePath($this->replicaFile); |
||||
74 | $saver = new Saver($this->replicaFile, $this->originalFS, $newPath); |
||||
0 ignored issues
–
show
It seems like
$newPath can also be of type null ; however, parameter $path of tkanstantsin\fileupload\saver\Saver::__construct() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
75 | |||||
76 | return $saver->save($originalFileFormatter); |
||||
77 | } |
||||
78 | } |
||||
79 |