Exporter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 48
ccs 12
cts 12
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A serialize() 0 5 1
A json() 0 5 1
1
<?php
2
3
namespace ADiaz\AML\OpenList\utils;
4
5
/**
6
 * This file is part of the OpenList Parser utility.
7
 *
8
 * @category  PHP
9
 *
10
 * @author    Alberto Diaz <[email protected]>
11
 * @copyright 2016 Alberto Diaz <[email protected]>
12
 * @license   This source file is subject to the MIT license that is bundled
13
 *
14
 * @version Release: @package_version@
15
 *
16
 * @link http://tytem.com
17
 */
18
class Exporter
19
{
20
    /**
21
     * @var string output files path
22
     */
23
    public $output_path;
24
25
    /**
26
     * @var string date format to be used in the date function such as 'Y-m-d'
27
     */
28
    public $date_format;
29
30
    /**
31
     * Exporter constructor.
32
     *
33
     * @param string $outputPath
34
     * @param string $date_format
35
     */
36 11
    public function __construct($outputPath, $date_format = 'Y-m-d')
37
    {
38 11
        $this->output_path = $outputPath;
39 11
        $this->date_format = $date_format;
40 11
    }
41
42
    /**
43
     * Serialize the entities.
44
     *
45
     * @param array  $entities
46
     * @param string $listId   name of the list to serialized
47
     */
48 2
    public function serialize($entities, $listId)
49
    {
50 2
        $nameFile = $this->output_path.$listId.'_'.date($this->date_format).'.serialized';
51 2
        file_put_contents($nameFile, serialize($entities));
52 2
    }
53
54
    /**
55
     * Create a json file.
56
     *
57
     * @param array  $entities
58
     * @param string $listId   name of the list to encode
59
     */
60 10
    public function json($entities, $listId)
61
    {
62 10
        $nameFile = $this->output_path.$listId.'_'.date($this->date_format).'.json';
63 10
        file_put_contents($nameFile, Utils::removeEmptyAndNullJson(json_encode($entities)));
64 10
    }
65
}
66