TemporaryScope::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 5
rs 9.4286
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
/**
4
 * This file is part of peridot-temporary-plugin.
5
 *
6
 * (c) Noritaka Horio <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace holyshared\peridot\temporary;
13
14
use Peridot\Core\Scope;
15
16
/**
17
 * TemporaryScope
18
 *
19
 * @package holyshared\peridot\temporary
20
 */
21
final class TemporaryScope extends Scope
22
{
23
24
    /**
25
     * @var \holyshared\peridot\temporary\TemporaryFactory
26
     */
27
    private $factory;
28
29
    /**
30
     * @var \holyshared\peridot\temporary\TemporaryContainer
31
     */
32
    private $container;
33
34
35
    public function __construct()
36
    {
37
        $this->factory = new TemporaryFactory();
38
        $this->container = new TemporaryContainer();
39
    }
40
41
    /**
42
     * Remove all temporary file and directory
43
     */
44
    public function cleanUpTemporary()
45
    {
46
        $this->container->destroy();
47
    }
48
49
    /**
50
     * Create a new temporary directory
51
     *
52
     * @param int $mode permission
53
     * @return \holyshared\peridot\temporary\TemporaryDirectory
54
     */
55
    public function makeDirectory($mode = FileSystemPermission::NORMAL)
56
    {
57
        $directory = $this->factory->makeDirectory($mode);
58
        $this->container->add($directory);
59
60
        return $directory;
61
    }
62
63
    /**
64
     * Create a new temporary file
65
     *
66
     * @param int $mode permission
67
     * @return \holyshared\peridot\temporary\TemporaryFile
68
     */
69
    public function makeFile($mode = FileSystemPermission::NORMAL)
70
    {
71
        $file = $this->factory->makeFile($mode);
72
        $this->container->add($file);
73
74
        return $file;
75
    }
76
77
}
78