Path   A
last analyzed

Complexity

Total Complexity 24

Size/Duplication

Total Lines 152
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 93.75%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 24
c 2
b 0
f 0
lcom 1
cbo 1
dl 0
loc 152
ccs 45
cts 48
cp 0.9375
rs 10

16 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getModelPath() 0 4 1
A getUsersPath() 0 4 1
A getMeetingsPath() 0 4 1
A getMeetingsDurationPath() 0 4 1
A getMeetingsAvailabilityPath() 0 4 1
A getUsersAvailabilityPath() 0 4 1
A getUsersMeetingsPath() 0 4 1
A getXPath() 0 4 1
A getYPath() 0 4 1
A getOutputPath() 0 4 1
A createPath() 0 12 4
A getPath() 0 4 1
A setPath() 0 4 1
A __destruct() 0 5 4
A delTree() 0 8 3
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Claudio Cardinale <[email protected]>
5
 * Date: 18/12/15
6
 * Time: 15.20
7
 * This program is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License
9
 * as published by the Free Software Foundation; either version 2
10
 * of the License, or (at your option) any later version.
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18
 */
19
20
namespace plunner\Console\Commands\Optimise;
21
22
/**
23
 * Class Path
24
 * tmp path where csv files for the solver task
25
 * @package plunner\Console\Commands\Optimise
26
 * @author Claudio Cardinale <[email protected]>
27
 * @copyright 2015 Claudio Cardinale
28
 * @version 1.0.0
29
 */
30
class Path
31
{
32
    /**
33
     * @var string
34
     */
35
    private $path;
36
37
    /**
38
     * Path constructor.
39
     * @param string $path
40
     */
41 15
    private function __construct($path)
42
    {
43 15
        $this->path = $path;
44 15
    }
45
46
    /**
47
     * @throws OptimiseException on problems during creation of tmp dir
48
     */
49 15
    static public function createPath()
50
    {
51 15
        $path = new Path(tempnam(sys_get_temp_dir(), 'OPT')); //TODO check the return in case of errors this return false on failure
52 15
        unlink($path->getPath()); //remove file to create a dir
53 15
        if (file_exists($path->getPath()))
54 10
            throw new OptimiseException('problem during creation of tmp dir (the directory already exists)');
55 15
        if (!@mkdir($path->getPath()))
56 10
            throw new OptimiseException('problem during creation of tmp dir (mkdir problem)');;
57 15
        if (!is_dir($path->getPath()))
58 10
            throw new OptimiseException('problem during creation of tmp dir (it is not possible to create directory)');
59 15
        return $path;
60
    }
61
62
    /**
63
     * @return string
64
     */
65 15
    public function getPath()
66
    {
67 15
        return $this->path;
68
    }
69
70
    /**
71
     * @param string $path
72
     */
73
    public function setPath($path)
74
    {
75
        $this->path = $path;
76
    }
77
78
    /**
79
     * @throws OptimiseException
80
     */
81 8
    public function __destruct()
82
    {
83 8
        if ($this->path && is_dir($this->path) && !self::delTree($this->path))
84 6
            throw new OptimiseException('problems during removing of path directory');
85 8
    }
86
87
    /**
88
     * remove a no empty dir
89
     * @param $dir
90
     * @return bool
91
     */
92 8
    private static function delTree($dir)
93
    {
94 8
        $files = array_diff(scandir($dir), array('.', '..'));
95 8
        foreach ($files as $file) {
96 2
            (is_dir("$dir/$file")) ? delTree("$dir/$file") : unlink("$dir/$file");
97 6
        }
98 8
        return rmdir($dir);
99
    }
100
101
102
    /**
103
     * @return string
104
     */
105 9
    public function getModelPath()
106
    {
107 9
        return $this->path . '/model.mod';
108
    }
109
110
    /**
111
     * @return string
112
     */
113 9
    public function getUsersPath()
114
    {
115 9
        return $this->path . '/Users.csv';
116
    }
117
118
    /**
119
     * @return string
120
     */
121 9
    public function getMeetingsPath()
122
    {
123 9
        return $this->path . '/Meeting.csv';
124
    }
125
126
    /**
127
     * @return string
128
     */
129 9
    public function getMeetingsDurationPath()
130
    {
131 9
        return $this->path . '/MeetingsDuration.csv';
132
    }
133
134
    /**
135
     * @return string
136
     */
137 9
    public function getMeetingsAvailabilityPath()
138
    {
139 9
        return $this->path . '/MeetingsAvailability.csv';
140
    }
141
142
    /**
143
     * @return string
144
     */
145 9
    public function getUsersAvailabilityPath()
146
    {
147 9
        return $this->path . '/UsersAvailability.csv';
148
    }
149
150
    /**
151
     * @return string
152
     */
153 9
    public function getUsersMeetingsPath()
154
    {
155 9
        return $this->path . '/UsersMeetings.csv';
156
    }
157
158
    /**
159
     * @return string
160
     */
161 9
    public function getXPath()
162
    {
163 9
        return $this->path . '/x.csv';
164
    }
165
166
    /**
167
     * @return string
168
     */
169 9
    public function getYPath()
170
    {
171 9
        return $this->path . '/y.csv';
172
    }
173
174
    /**
175
     * @return string
176
     */
177 9
    public function getOutputPath()
178
    {
179 9
        return $this->path . '/out.txt';
180
    }
181
}