StreamedWritingTrait   A
last analyzed

Coupling/Cohesion

Components 0
Dependencies 1

Complexity

Total Complexity 3

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 0
cbo 1
dl 0
loc 53
ccs 9
cts 9
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A stream() 0 8 1
A writeStream() 0 4 1
A updateStream() 0 4 1
write() 0 1 ?
update() 0 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 6
    protected function stream($path, $resource, Config $config, $fallback)
21
    {
22 6
        Util::rewindStream($resource);
23 6
        $contents = stream_get_contents($resource);
24 6
        $fallbackCall = [$this, $fallback];
25
26 6
        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 3
    public function writeStream($path, $resource, Config $config)
39
    {
40 3
        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 3
    public function updateStream($path, $resource, Config $config)
53
    {
54 3
        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