| Conditions | 4 |
| Paths | 3 |
| Total Lines | 24 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 21 | protected function hookTimestampableIntoLifecycle() |
||
| 22 | { |
||
| 23 | $updateCallback = function ($record, $manager, $type) { |
||
| 24 | if (method_exists($manager, 'getTimestampAttributes')) { |
||
| 25 | $attributes = $this->getTimestampAttributes($type); |
||
| 26 | } else { |
||
| 27 | $attributes = $type; |
||
| 28 | } |
||
| 29 | |||
| 30 | /** @var TimestampableTrait $record */ |
||
| 31 | $record->updatedTimestamps($attributes); |
||
| 32 | }; |
||
| 33 | |||
| 34 | $events = ['creating' => 'create', 'updating' => 'update']; |
||
| 35 | foreach ($events as $event => $type) { |
||
| 36 | if (is_callable('static::' . $event) == false) { |
||
|
|
|||
| 37 | continue; |
||
| 38 | } |
||
| 39 | static::$event( |
||
| 40 | function (Event $event) use ($updateCallback, $type) { |
||
| 41 | $record = $event->getRecord(); |
||
| 42 | /** @var static|RecordManager $manager */ |
||
| 43 | $manager = $event->getManager(); |
||
| 44 | $updateCallback($record, $manager, $type); |
||
| 45 | } |
||
| 50 |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.