FileStore   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 35
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A findAll() 0 10 3
A store() 0 7 1
A clear() 0 6 2
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