Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
CodeComment
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 5
30
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 newFromRow
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 newFromID
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 newFromData
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
2
 threadDepth
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace MediaWiki\Extension\CodeReview\Backend;
4
5use stdClass;
6
7/**
8 * Represents a comment made to a revision.
9 */
10class CodeComment {
11    public $id;
12
13    public $text;
14
15    public $user;
16
17    public $userText;
18
19    public $timestamp;
20
21    public $sortkey;
22
23    public $attrib;
24
25    public $removed;
26
27    public $added;
28
29    /**
30     * @var CodeRevision
31     */
32    public $rev;
33
34    /**
35     * @param CodeRevision $rev
36     */
37    public function __construct( $rev ) {
38        $this->rev = $rev;
39    }
40
41    /**
42     * @param CodeRevision $rev
43     * @param stdClass $row
44     * @return CodeComment
45     */
46    public static function newFromRow( $rev, $row ) {
47        return self::newFromData( $rev, get_object_vars( $row ) );
48    }
49
50    /**
51     * Create a comment given its ID _AND_ a repository
52     * @param int $cc_id Comment ID in the database
53     * @param CodeRevision $rev A revision object to which the comment is
54     * attached
55     * @return CodeComment
56     */
57    public static function newFromID( $cc_id, CodeRevision $rev ) {
58        $dbr = wfGetDB( DB_REPLICA );
59        $row = $dbr->selectRow(
60            'code_comment',
61            [
62                # fields needed to build a CodeRevision
63                'cc_rev_id',
64                'cc_repo_id',
65
66                # fields needed for self::newFromRow()
67                'cc_id',
68                'cc_text',
69                'cc_user',
70                'cc_user_text',
71                'cc_patch_line',
72                'cc_timestamp',
73                'cc_sortkey'
74            ],
75            [ 'cc_id' => (int)$cc_id ],
76            __METHOD__
77        );
78        return self::newFromRow( $rev, $row );
79    }
80
81    /**
82     * @param CodeRevision $rev
83     * @param array $data
84     * @return CodeComment
85     */
86    public static function newFromData( $rev, $data ) {
87        $comment = new CodeComment( $rev );
88        $comment->id = intval( $data['cc_id'] );
89        // @todo FIXME
90        $comment->text = $data['cc_text'];
91        $comment->user = $data['cc_user'];
92        $comment->userText = $data['cc_user_text'];
93        $comment->timestamp = wfTimestamp( TS_MW, $data['cc_timestamp'] );
94        $comment->sortkey = $data['cc_sortkey'];
95        return $comment;
96    }
97
98    /**
99     * @return int
100     */
101    public function threadDepth() {
102        $timestamps = explode( ',', $this->sortkey );
103        return count( $timestamps );
104    }
105}