PersistentCollection::load()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
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