Test Failed
Push — master ( 9f82b3...3c8bc2 )
by Alexey
07:31
created

Metadata   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 88.24%

Importance

Changes 0
Metric Value
dl 0
loc 66
c 0
b 0
f 0
ccs 15
cts 17
cp 0.8824
rs 10
wmc 8
lcom 1
cbo 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A mimetype() 0 4 1
A size() 0 4 1
A timestamp() 0 12 3
A type() 0 4 1
A path() 0 4 1
1
<?php declare(strict_types = 1);
2
3
namespace Venta\Filesystem;
4
5
use DateTime;
6
use DateTimeInterface;
7
use Venta\Contracts\Filesystem\Metadata as MetadataContract;
8
9
/**
10
 * Class Metadata
11
 *
12
 * @package Venta\Filesystem
13
 */
14
class Metadata implements MetadataContract
15
{
16
    /**
17
     * @var array
18
     */
19
    private $data = [];
20
21
    /**
22
     * Metadata constructor.
23
     *
24
     * @param array $data
25
     */
26 3
    public function __construct(array $data)
27
    {
28 3
        $this->data = $data;
29 3
    }
30
31
    /**
32
     * @inheritDoc
33
     */
34 1
    public function mimetype(): string
35
    {
36 1
        return $this->data['mimetype'] ?? '';
37
    }
38
39
    /**
40
     * @inheritDoc
41
     */
42 1
    public function size(): int
43
    {
44 1
        return $this->data['size'] ?? 0;
45
    }
46
47
    /**
48
     * @inheritDoc
49
     */
50 1
    public function timestamp(): DateTimeInterface
51
    {
52 1
        if (!isset($this->data['timestamp'])) {
53
            return null;
54
        }
55
56 1
        if ($this->data['timestamp'] instanceof DateTimeInterface) {
57 1
            return $this->data['timestamp'];
58
        }
59
60
        return (new DateTime())->setTimestamp($this->data['timestamp']);
61
    }
62
63
    /**
64
     * @inheritDoc
65
     */
66 1
    public function type(): string
67
    {
68 1
        return $this->data['type'] ?? '';
69
    }
70
71
    /**
72
     * @inheritDoc
73
     */
74 1
    public function path(): string
75
    {
76 1
        return $this->data['path'] ?? '';
77
    }
78
79
}