Total Complexity | 5 |
Total Lines | 38 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
17 | class MediaUpdater extends Component |
||
18 | { |
||
19 | use SaveModelTrait; |
||
|
|||
20 | |||
21 | /** |
||
22 | * @var \app\models\Media |
||
23 | */ |
||
24 | public $media; |
||
25 | |||
26 | public function init() |
||
27 | { |
||
28 | parent::init(); |
||
29 | if (!$this->media instanceof Media) { |
||
30 | throw new InvalidConfigException('Property \'media\' must be set and by type od \'\app\models\Media\''); |
||
31 | } |
||
32 | } |
||
33 | |||
34 | public function setDetails(Post $post) |
||
35 | { |
||
36 | $this->media->instagram_id = $post->id; |
||
37 | $this->media->shortcode = $post->shortcode; |
||
38 | $this->media->is_video = $post->isVideo; |
||
39 | $this->media->caption = $post->caption; |
||
40 | $this->media->taken_at = $this->getNormalizedTakenAt($post); |
||
41 | $this->media->likes = $post->likes; |
||
42 | $this->media->comments = $post->comments; |
||
43 | |||
44 | return $this; |
||
45 | } |
||
46 | |||
47 | public function save() |
||
48 | { |
||
49 | $this->saveModel($this->media); |
||
50 | } |
||
51 | |||
52 | protected function getNormalizedTakenAt(Post $post): string |
||
55 | } |
||
56 | } |