TemporaryScope   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 9
Bugs 0 Features 4
Metric Value
c 9
b 0
f 4
dl 0
loc 57
wmc 4
lcom 1
cbo 3
rs 10

4 Methods

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