Completed
Push — master ( 665782...a8382c )
by Matthijs
02:49
created

FileSerializedResourcePersistenceHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 5
Bugs 0 Features 2
Metric Value
wmc 3
c 5
b 0
f 2
lcom 1
cbo 1
dl 0
loc 20
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A persist() 0 9 2
A current() 0 4 1
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