FileSerializedResourcePersistenceHandler   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 18
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A current() 0 3 1
A persist() 0 8 2
1
<?php
2
/**
3
 * @author Matthijs van den Bos <[email protected]>
4
 * @copyright 2013 Matthijs van den Bos
5
 */
6
7
namespace VDB\Spider\PersistenceHandler;
8
9
use Symfony\Component\Finder\Finder;
10
use VDB\Spider\PersistenceHandler\FilePersistenceHandler;
11
use VDB\Spider\Resource;
12
13
class FileSerializedResourcePersistenceHandler extends FilePersistenceHandler implements PersistenceHandlerInterface
14
{
15
    public function persist(Resource $resource)
16
    {
17
        $path = $this->getResultPath() . $this->getFileSystemPath($resource);
18
        if (!is_dir($path)) {
19
            mkdir($path, 0777, true);
20
        }
21
        $file = new \SplFileObject($path . DIRECTORY_SEPARATOR . $this->getFileSystemFilename($resource), 'w');
22
        $this->totalSizePersisted += $file->fwrite(serialize($resource));
23
    }
24
25
    /**
26
     * @return Resource
27
     */
28
    public function current()
29
    {
30
        return unserialize($this->getIterator()->current()->getContents());
31
    }
32
}
33