PersistentCollection   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 92.31%

Importance

Changes 0
Metric Value
dl 0
loc 24
ccs 12
cts 13
cp 0.9231
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A load() 0 4 1
A flush() 0 8 2
1
<?php declare(strict_types=1);
2
/* (c) Anton Medvedev <[email protected]>
3
 *
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 */
7
8
namespace Deployer\Collection;
9
10
class PersistentCollection extends Collection
11
{
12
    private $file;
13
14 5
    public function __construct(string $file, array $collection = [])
15
    {
16 5
        $this->file = $file;
17 5
        parent::__construct($collection);
18 5
    }
19
20 2
    public function load()
21
    {
22 2
        $this->values = unserialize(file_get_contents($this->file));
23 2
    }
24
25 5
    public function flush()
26
    {
27 5
        $dir = dirname($this->file);
28 5
        if (!is_dir($dir)) {
29
            mkdir($dir, 0777, true);
30
        }
31 5
        file_put_contents($this->file, serialize($this->values));
32 5
    }
33
}
34