Passed
Push — master ( 3b518a...cd2a02 )
by Adam
11:23
created

Comment::job()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Coyote\Services\Stream\Objects;
4
5
use Coyote\Services\UrlBuilder;
6
use Coyote\Comment as Model;
7
8
class Comment extends ObjectAbstract
9
{
10
    /**
11
     * @param array ...$args
12
     * @return $this
13
     * @throws \Exception
14
     */
15
    public function map(...$args)
16
    {
17
        $object = $args[0];
18
19
        $class = class_basename($object);
20
        if (!method_exists($this, $class)) {
21
            throw new \Exception("There is not method called $class");
22
        }
23
24
        $this->$class(...$args);
25
26
        return $this;
27
    }
28
29
    /**
30
     * @param \Coyote\Microblog $microblog
31
     */
32
    private function microblog($microblog)
33
    {
34
        $this->id = $microblog->id;
35
        $this->url = UrlBuilder::microblogComment($microblog);
36
        $this->displayName = excerpt($microblog->html);
37
    }
38
39
    /**
40
     * @param \Coyote\Post $post
41
     * @param \Coyote\Post\Comment $comment
42
     * @param \Coyote\Topic $topic
43
     */
44
    private function post($post, $comment, $topic)
45
    {
46
        $this->id = $comment->id;
47
        $this->displayName = excerpt($comment->html);
48
        $this->url = UrlBuilder::topic($topic) . '?p=' . $post->id . '#comment-' . $comment->id;
49
    }
50
51
    /**
52
     * @param \Coyote\Wiki $wiki
53
     * @param \Coyote\Wiki\Comment $comment
54
     */
55
    private function wiki($wiki, $comment)
56
    {
57
        $this->id = $comment->id;
58
        $this->displayName = excerpt($comment->html);
59
        $this->url = UrlBuilder::wikiComment($wiki, $comment->id);
60
    }
61
62
    public function comment(Model $comment)
63
    {
64
        $this->id = $comment->id;
65
        $this->displayName = excerpt($comment->html);
66
        $this->url = UrlBuilder::url($comment->resource) . '#comment-' . $comment->id;
67
68
        return $this;
69
    }
70
}
71