Completed
Push — master ( 0b8f98...686b93 )
by Arnold
08:12 queued 08:12
created

BasicFilename   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 50%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
dl 0
loc 46
ccs 4
cts 8
cp 0.5
rs 10
c 1
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 3 2
A __toString() 0 3 1
A getFormat() 0 3 1
A __construct() 0 3 1
1
<?php
2
/**
3
 * This file is part of the Cache package.
4
 *
5
 * Copyright (c) Daniel González
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @author Daniel González <[email protected]>
11
 * @author Arnold Daniels <[email protected]>
12
 */
13
14
declare(strict_types=1);
15
16
namespace Desarrolla2\Cache\File;
17
18
/**
19
 * Create a path for a key
20
 */
21
class BasicFilename
22
{
23
    /**
24
     * @var string
25
     */
26
    protected $format;
27
28
    /**
29
     * BasicFilename constructor.
30
     *
31
     * @param string $format
32
     */
33 591
    public function __construct(string $format)
34
    {
35 591
        $this->format = $format;
36
    }
37
38
    /**
39
     * Get the format
40
     *
41
     * @return string
42
     */
43
    public function getFormat(): string
44
    {
45
        return $this->format;
46
    }
47
48
    /**
49
     * Create the path for a key
50
     *
51
     * @param string $key
52
     * @return string
53
     */
54 591
    public function __invoke(string $key): string
55
    {
56 591
        return sprintf($this->format, $key ?: '*');
57
    }
58
59
    /**
60
     * Cast to string
61
     *
62
     * @return string
63
     */
64
    public function __toString(): string
65
    {
66
        return $this->getFormat();
67
    }
68
}