ListWith   A
last analyzed

Coupling/Cohesion

Components 1
Dependencies 2

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 56
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getMethod() 0 4 1
A handle() 0 13 3
A getMetadataByName() 0 12 2
1
<?php
2
3
namespace League\Flysystem\Plugin;
4
5
class ListWith extends AbstractPlugin
6
{
7
    /**
8
     * Get the method name.
9
     *
10
     * @return string
11
     */
12 3
    public function getMethod()
13
    {
14 3
        return 'listWith';
15
    }
16
17
    /**
18
     * List contents with metadata.
19
     *
20
     * @param array  $keys
21
     * @param string $directory
22
     * @param bool   $recursive
23
     *
24
     * @return array listing with metadata
25
     */
26 6
    public function handle(array $keys = [], $directory = '', $recursive = false)
27
    {
28 6
        $contents = $this->filesystem->listContents($directory, $recursive);
29
30 6
        foreach ($contents as $index => $object) {
31 6
            if ($object['type'] === 'file') {
32 6
                $missingKeys = array_diff($keys, array_keys($object));
33 6
                $contents[$index] = array_reduce($missingKeys, [$this, 'getMetadataByName'], $object);
34 1
            }
35 1
        }
36
37 3
        return $contents;
38
    }
39
40
    /**
41
     * Get a meta-data value by key name.
42
     *
43
     * @param array $object
44
     * @param       $key
45
     *
46
     * @return array
47
     */
48 6
    protected function getMetadataByName(array $object, $key)
49
    {
50 6
        $method = 'get' . ucfirst($key);
51
52 6
        if ( ! method_exists($this->filesystem, $method)) {
53 3
            throw new \InvalidArgumentException('Could not get meta-data for key: ' . $key);
54
        }
55
56 3
        $object[$key] = $this->filesystem->{$method}($object['path']);
57
58 3
        return $object;
59
    }
60
}
61