Completed
Branch master (243272)
by Konstantin
03:54
created

BaseEntity::setUpdatedTime()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 0
crap 2
1
<?php
2
3
namespace linkprofit\AmoCRM\entities;
4
5
use linkprofit\AmoCRM\traits\FieldList;
6
7
/**
8
 * Class BaseEntity
9
 * @package entities
10
 */
11
abstract class BaseEntity implements EntityInterface
12
{
13
    /**
14
     * @var integer id сущности
15
     */
16
    public $id;
17
18
    /**
19
     * @var string Дата и время создания сущности
20
     */
21
    public $created_at;
22
23
    /**
24
     * @var string Дата и время изменения сущности
25
     */
26
    public $updated_at;
27
28
    /**
29
     * @var integer id пользователя ответственного за сущность
30
     */
31
    public $responsible_user_id;
32
33
    /**
34
     * @var array
35
     */
36
    protected $fieldList = [];
37
38
    use FieldList;
39
40
    /**
41
     * @return array
42
     */
43 24
    public function get()
44
    {
45 24
        if ($this->id) {
46 5
            $this->setUpdatedTime();
47 5
        }
48
49 24
        $fields = $this->getExistedValues($this->fieldList);
50
51 24
        return $fields;
52
    }
53
54
    /**
55
     * @param $array
56
     */
57 30
    public function set($array)
58
    {
59 30
        $this->setFromArray($this->fieldList, $array);
60 30
    }
61
62
    /**
63
     * Задаем время обновления, если уже не задано
64
     */
65 13
    protected function setUpdatedTime()
66
    {
67 13
        if (!$this->updated_at) {
68 13
            $this->updated_at = time();
1 ignored issue
show
Documentation Bug introduced by
The property $updated_at was declared of type string, but time() is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
69 13
        }
70
    }
71
}