GetWithMetadata   A
last analyzed

Coupling/Cohesion

Components 1
Dependencies 2

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 43
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getMethod() 0 4 1
A handle() 0 20 4
1
<?php
2
3
namespace League\Flysystem\Plugin;
4
5
use InvalidArgumentException;
6
7
class GetWithMetadata extends AbstractPlugin
8
{
9
    /**
10
     * Get the method name.
11
     *
12
     * @return string
13
     */
14 3
    public function getMethod()
15
    {
16 3
        return 'getWithMetadata';
17
    }
18
19
    /**
20
     * Get metadata for an object with required metadata.
21
     *
22
     * @param string $path     path to file
23
     * @param array  $metadata metadata keys
24
     *
25
     * @throws InvalidArgumentException
26
     *
27
     * @return array|false metadata
28
     */
29 9
    public function handle($path, array $metadata)
30
    {
31 9
        $object = $this->filesystem->getMetadata($path);
32
33 9
        if ( ! $object) {
34 3
            return false;
35
        }
36
37 6
        $keys = array_diff($metadata, array_keys($object));
38
39 6
        foreach ($keys as $key) {
40 6
            if ( ! method_exists($this->filesystem, $method = 'get' . ucfirst($key))) {
41 3
                throw new InvalidArgumentException('Could not fetch metadata: ' . $key);
42
            }
43
44 3
            $object[$key] = $this->filesystem->{$method}($path);
45 3
        }
46
47 3
        return $object;
48
    }
49
}
50