Passed
Push — master ( 32c543...94bf2c )
by Rougin
03:19
created

CreateEntity::set()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 8
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Rougin\Windstorm\Mutators;
4
5
use Rougin\Windstorm\QueryInterface;
6
use Rougin\Windstorm\MutatorInterface;
7
8
/**
9
 * Create Entity Mutator
10
 *
11
 * @package Windstorm
12
 * @author  Rougin Gutib <[email protected]>
13
 */
14
class CreateEntity implements MutatorInterface
15
{
16
    const CREATED_AT = 'created_at';
17
18
    /**
19
     * @var array
20
     */
21
    protected $data = array();
22
23
    /**
24
     * @var string
25
     */
26
    protected $dateFormat = 'Y-m-d H:i:s';
27
28
    /**
29
     * @var string
30
     */
31
    protected $table = '';
32
33
    /**
34
     * @var boolean
35
     */
36
    protected $timestamp = true;
37
38
    /**
39
     * Initializes the mutator instance.
40
     *
41
     * @param array $data
42
     */
43 6
    public function __construct(array $data)
44
    {
45 6
        $this->data = $data;
46 6
    }
47
48
    /**
49
     * Mutates the specified query instance.
50
     *
51
     * @param \Rougin\Windstorm\QueryInterface $query
52
     */
53 6
    public function set(QueryInterface $query)
54
    {
55 6
        if ($this->timestamp)
56 4
        {
57 6
            $this->data[static::CREATED_AT] = date($this->dateFormat);
58 4
        }
59
60 6
        return $query->insertInto($this->table)->values($this->data);
61
    }
62
}
63