GetWithMetadata   A
last analyzed

Coupling/Cohesion

Components 1
Dependencies 2

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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