FileStore::findAll()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 0
1
<?php
2
3
namespace Knp\RadBundle\ObjectStore;
4
5
class FileStore implements ObjectStoreInterface
6
{
7
    private $filename;
8
9
    public function __construct($filename)
10
    {
11
        $this->filename = $filename;
12
    }
13
14
    public function findAll()
15
    {
16
        if (!file_exists($this->filename)) {
17
            return array();
18
        }
19
20
        $contents = unserialize(file_get_contents($this->filename));
21
22
        return is_array($contents) ? $contents : array();
23
    }
24
25
    public function store($object)
26
    {
27
        $contents = $this->findAll();
28
        $contents[] = $object;
29
30
        file_put_contents($this->filename, serialize($contents));
31
    }
32
33
    public function clear()
34
    {
35
        if (file_exists($this->filename)) {
36
            unlink($this->filename);
37
        }
38
    }
39
}
40