FtpTransport::send()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 11
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Setono\SyliusStockMovementPlugin\Transport;
6
7
use League\Flysystem\Adapter\Ftp;
8
use League\Flysystem\FileNotFoundException;
9
use League\Flysystem\Filesystem;
10
use League\Flysystem\FilesystemInterface;
11
use RuntimeException;
12
use Safe\Exceptions\StringsException;
13
use function Safe\sprintf;
14
use Setono\SyliusStockMovementPlugin\Model\ReportConfigurationInterface;
15
use Setono\SyliusStockMovementPlugin\Model\ReportInterface;
16
17
final class FtpTransport implements TransportInterface
18
{
19
    /** @var FilesystemInterface */
20
    private $filesystem;
21
22
    public function __construct(FilesystemInterface $filesystem)
23
    {
24
        $this->filesystem = $filesystem;
25
    }
26
27
    /**
28
     * @throws FileNotFoundException
29
     * @throws StringsException
30
     */
31
    public function send(string $file, array $configuration, ReportInterface $report, ReportConfigurationInterface $reportConfiguration): void
32
    {
33
        $configuration['root'] = $configuration['path'] ?? null;
34
35
        $stream = $this->filesystem->readStream($file);
36
        if (false === $stream) {
37
            throw new RuntimeException(sprintf('The stream for the file %s could not be created', $file));
38
        }
39
40
        $filesystem = new Filesystem(new Ftp($configuration));
41
        $filesystem->putStream($file, $stream);
42
    }
43
}
44