Passed
Push — master ( b74a1f...762e12 )
by MoshiMoshi
03:10
created

SaveAreaBuilder   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 1
cbo 1
dl 0
loc 44
ccs 10
cts 10
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A build() 0 7 1
A buildPrefix() 0 4 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