StreamedWritingTrait::write()
last analyzed

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 1
ccs 0
cts 0
cp 0
nc 1
1
<?php
2
3
namespace League\Flysystem\Adapter\Polyfill;
4
5
use League\Flysystem\Config;
6
use League\Flysystem\Util;
7
8
trait StreamedWritingTrait
9
{
10
    /**
11
     * Stream fallback delegator.
12
     *
13
     * @param string   $path
14
     * @param resource $resource
15
     * @param Config   $config
16
     * @param string   $fallback
17
     *
18
     * @return mixed fallback result
19
     */
20 View Code Duplication
    protected function stream($path, $resource, Config $config, $fallback)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21
    {
22
        Util::rewindStream($resource);
23
        $contents = stream_get_contents($resource);
24
        $fallbackCall = [$this, $fallback];
25
26
        return call_user_func($fallbackCall, $path, $contents, $config);
27
    }
28
29
    /**
30
     * Write using a stream.
31
     *
32
     * @param string   $path
33
     * @param resource $resource
34
     * @param Config   $config
35
     *
36
     * @return mixed false or file metadata
37
     */
38
    public function writeStream($path, $resource, Config $config)
39
    {
40
        return $this->stream($path, $resource, $config, 'write');
41
    }
42
43
    /**
44
     * Update a file using a stream.
45
     *
46
     * @param string   $path
47
     * @param resource $resource
48
     * @param Config   $config   Config object or visibility setting
49
     *
50
     * @return mixed false of file metadata
51
     */
52
    public function updateStream($path, $resource, Config $config)
53
    {
54
        return $this->stream($path, $resource, $config, 'update');
55
    }
56
57
    // Required abstract methods
58
    abstract public function write($pash, $contents, Config $config);
59
    abstract public function update($pash, $contents, Config $config);
60
}
61