Completed
Push — master ( 6db9da...f7853c )
by El
03:33
created

DataStore::store()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 9
nc 4
nop 2
crap 3
1
<?php
2
/**
3
 * PrivateBin
4
 *
5
 * a zero-knowledge paste bin
6
 *
7
 * @link      https://github.com/PrivateBin/PrivateBin
8
 * @copyright 2012 Sébastien SAUVAGE (sebsauvage.net)
9
 * @license   https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
10
 * @version   1.1
11
 */
12
13
namespace PrivateBin\Persistence;
14
15
use Exception;
16
use PrivateBin\Configuration;
17
use PrivateBin\Json;
18
19
/**
20
 * DataStore
21
 *
22
 * Handles data storage for Data\Filesystem.
23
 */
24
class DataStore extends AbstractPersistence
25
{
26
    /**
27
     * store the data
28
     *
29
     * @access public
30
     * @static
31
     * @param  string $filename
32
     * @param  string $data
33
     * @return bool
34
     */
35 44
    public static function store($filename, $data)
36
    {
37 44
        $path = self::getPath();
38 44
        if (strpos($filename, $path) === 0) {
39 44
            $filename = substr($filename, strlen($path));
40
        }
41
        try {
42 44
            self::_store($filename, Json::encode($data));
43 43
            return true;
44 2
        } catch (Exception $e) {
45 2
            return false;
46
        }
47
    }
48
}
49