CommitFile   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 1
dl 0
loc 72
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A commit() 0 4 1
A filePhpcs() 0 4 1
A totalLines() 0 6 1
A totalPHPCS() 0 4 1
A getAdditionsAttribute() 0 4 2
A getChangesAttribute() 0 4 2
A getDeletionsAttribute() 0 4 2
A comments() 0 4 1
1
<?php
2
/**
3
 * GitScrum v0.1.
4
 *
5
 * @author  Renato Marinho <[email protected]>
6
 * @license http://opensource.org/licenses/GPL-3.0 GPLv3
7
 */
8
9
namespace GitScrum\Models;
10
11
use Illuminate\Database\Eloquent\Model;
12
13
class CommitFile extends Model
14
{
15
    /**
16
     * The database table used by the model.
17
     *
18
     * @var string
19
     */
20
    protected $table = 'commit_files';
21
22
    /**
23
     * Attributes that should be mass-assignable.
24
     *
25
     * @var array
26
     */
27
    protected $fillable = ['commit_id', 'sha', 'filename', 'status', 'additions', 'deletions', 'changes', 'raw_url', 'raw', 'phpcs', 'patch', 'phploc_size', 'phploc_lines_of_code', 'phploc_lines_of_code_percent', 'phploc_comment_lines_of_code', 'phploc_comment_lines_of_code_percent', 'phploc_non-comment_lines_of_code', 'phploc_non-comment_lines_of_code_percent', 'phploc_logical_lines_of_code', 'phploc_logical_lines_of_code_percent', 'phploc_namespaces', 'phploc_interfaces', 'phploc_traits', 'phploc_classes', 'phploc_scope_non-static', 'phploc_scope_static', 'phploc_visibility_public', 'phploc_visibility_public_percent', 'phploc_visibility_non-public', 'phploc_visibility_non-public_percent', 'phploc_named_functions', 'phploc_named_functions_percent', 'phploc_anonymous_functions', 'phploc_constants_global', 'phploc_constants_global_percent', 'phploc_constants_class', 'phploc_constants_class_percent', 'deleted_at'];
28
29
    /**
30
     * The attributes excluded from the model's JSON form.
31
     *
32
     * @var array
33
     */
34
    protected $hidden = [];
35
36
    /**
37
     * The attributes that should be casted to native types.
38
     *
39
     * @var array
40
     */
41
    protected $casts = [];
42
43
    public function commit()
44
    {
45
        return $this->belongsTo(\GitScrum\Models\Commit::class, 'commit_id', 'id');
46
    }
47
48
    public function filePhpcs()
49
    {
50
        return $this->hasMany(\GitScrum\Models\CommitFilePhpc::class, 'commit_file_id', 'id');
51
    }
52
53
    public function totalLines()
54
    {
55
        $total = preg_split('/\R/', $this->raw);
0 ignored issues
show
Documentation introduced by
The property raw does not exist on object<GitScrum\Models\CommitFile>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
56
57
        return count($total);
58
    }
59
60
    public function totalPHPCS($type = 'ERROR')
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
61
    {
62
        return $this->filePhpcs()->where('type', '=', $type)->groupBy('type')->count();
63
    }
64
65
    public function getAdditionsAttribute()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
66
    {
67
        return $this->attributes['additions'] !== null ? $this->attributes['additions'] : 0;
68
    }
69
70
    public function getChangesAttribute()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
71
    {
72
        return $this->attributes['changes'] !== null ? $this->attributes['changes'] : 0;
73
    }
74
75
    public function getDeletionsAttribute()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
76
    {
77
        return $this->attributes['deletions'] !== null ? $this->attributes['deletions'] : 0;
78
    }
79
80
    public function comments()
81
    {
82
        return $this->morphMany('GitScrum\Comment', 'commentable');
83
    }
84
}
85