Completed
Push — develop ( e210c1...b7d5d2 )
by Mohamed
07:16 queued 59s
created

CountTrait::countComments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
crap 1
1
<?php
2
3
/*
4
 * This file is part of the Tinyissue package.
5
 *
6
 * (c) Mohamed Alsharaf <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Tinyissue\Model\Traits\Project\Issue;
13
14
use Illuminate\Database\Eloquent\Relations;
15
use Tinyissue\Model;
16
17
/**
18
 * CountTrait is trait class containing the methods for counting database records for the Issue model.
19
 *
20
 * @author Mohamed Alsharaf <[email protected]>
21
 *
22
 * @property int                $project_id
23
 * @property int                $created_by
24
 * @property string             $body
25
 * @property Model\Project      $project
26
 * @property Model\User         $createdBy
27
 *
28
 * @method Relations\HasOne     hasOne($related, $foreignKey = null, $localKey = null)
29
 */
30
trait CountTrait
31
{
32
    /**
33
     * Count number of comments in an issue.
34
     *
35
     * @return Relations\HasOne
36
     */
37 4
    public function countComments()
38
    {
39 4
        return $this->hasOne('Tinyissue\Model\Project\Issue\Comment', 'issue_id')
40 4
            ->selectRaw('issue_id, count(*) as aggregate')
41 4
            ->groupBy('issue_id');
42
    }
43
}
44