FtpTransport   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 8
dl 0
loc 25
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A send() 0 11 2
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