BasicFilename::getFormat()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 1
b 0
f 0
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
}