UploadToStorage::sendToStorage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 2
1
<?php
2
3
/**
4
 * This file is part of InFw\FileManager package.
5
 */
6
7
namespace InFw\FileManager;
8
9
use InFw\File\FileInterface;
10
use InFw\File\FileFactoryInterface;
11
12
/**
13
 * Class UploadToStorage.
14
 */
15
class UploadToStorage implements UploadInterface
16
{
17
    /**
18
     * File storage.
19
     *
20
     * @var StorageInterface
21
     */
22
    private $storage;
23
24
    /**
25
     * File factory.
26
     *
27
     * @var FileFactoryInterface
28
     */
29
    private $factory;
30
31
    /**
32
     * UploadToStorage constructor.
33
     *
34
     * @param StorageInterface     $storage
35
     * @param FileFactoryInterface $factory
36
     */
37
    public function __construct(StorageInterface $storage, FileFactoryInterface $factory)
38
    {
39
        $this->storage = $storage;
40
        $this->factory = $factory;
41
    }
42
43
    /**
44
     * Send a file to storage.
45
     *
46
     * @param string $path
47
     * @param string $name
48
     *
49
     * @return FileInterface
50
     */
51
    public function sendToStorage($path, $name)
52
    {
53
        $file = $this->factory->make($name, $path);
54
55
        $this->storage->save($file);
56
57
        return $file;
58
    }
59
}
60