Completed
Pull Request — master (#22)
by MoshiMoshi
06:45
created

SaveAreaBuilder::buildPrefix()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
/*
4
 * This file is part of the ConfigCacheBundle package.
5
 *
6
 * Copyright (c) 2015-2016 Yahoo Japan Corporation
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace YahooJapan\ConfigCacheBundle\ConfigCache;
13
14
use Symfony\Component\Filesystem\Filesystem;
15
16
/**
17
 * SaveAreaBuilder manages a temporary directory to save.
18
 */
19
class SaveAreaBuilder
20
{
21
    const TEMP_DIRECTORY_PREFIX = 'yahoo_japan_config_cache_';
22
23
    protected $env;
24
    protected $filesystem;
25
26
    /**
27
     * Constructor.
28
     *
29
     * @param string     $env
30
     * @param Filesystem $filesystem
31
     */
32 27
    public function __construct($env, Filesystem $filesystem)
33
    {
34 27
        $this->env        = $env;
35 27
        $this->filesystem = $filesystem;
36 27
    }
37
38
    /**
39
     * Builds a temporary directory and returns.
40
     *
41
     * @param string $directory
42
     *
43
     * @return string
44
     */
45 9
    public function build($directory)
46
    {
47 9
        $temporaryDirectory = $this->buildPrefix().$directory;
48 9
        $this->filesystem->mkdir($temporaryDirectory);
49
50 9
        return $temporaryDirectory;
51
    }
52
53
    /**
54
     * Builds a temporary directory prefix.
55
     *
56
     * @return string
57
     */
58 17
    public function buildPrefix()
59
    {
60 17
        return sys_get_temp_dir().DIRECTORY_SEPARATOR.self::TEMP_DIRECTORY_PREFIX.$this->env;
61
    }
62
}
63