Article   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 9
eloc 28
c 2
b 0
f 0
dl 0
loc 58
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A scopeFindArticle() 0 5 1
A user() 0 2 1
A _construct() 0 2 1
A getNameAttribute() 0 2 1
A scopeFindArticles() 0 2 1
A get() 0 17 4
1
<?php
2
3
namespace Sirgrimorum\TransArticles\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
class Article extends Model {
8
9
    public $rules = [//The validation rules
10
        'nickname' => 'bail|required|max:255',
11
        'scope' => 'bail|required|max:255',
12
        'lang' => 'bail|required|max:255',
13
        'content' => 'required',
14
    ];
15
    public $error_messages = []; //The validation error messages
16
17
    public function _construct() {
18
        $this->error_messages = [
19
        ];
20
    }
21
22
    public function scopeFindArticle($query, $name) {
23
        $segments = explode(".", $name);
24
        $scope = array_shift($segments);
25
        $nickname = implode(".", $segments);
26
        return $query->where("activated", "=", "1")->where("scope", "=", $scope)->where("nickname", "=", $nickname);
27
    }
28
29
    public function scopeFindArticles($query, $scope) {
30
        return $query->where("activated", "=", "1")->where("scope", "=", $scope);
31
    }
32
33
    public function getNameAttribute() {
34
        return $this->scope . "." . $this->nickname . " (" . $this->lang . ")";
35
    }
36
    
37
    public function user() {
38
        return $this->belongsTo('App\User');
39
    }
40
41
    /**
42
     * Get the flied value using the configuration array
43
     * 
44
     * @param string $key The field to return
45
     * @param boolean $justValue Optional If return just the formated value (true) or an array with 3 elements, label, value and data (detailed data for the field)
46
     * @return mixed
47
     */
48
    public function get($key, $justValue = true)
49
    {
50
        if (!class_exists('\Sirgrimorum\CrudGenerator\CrudGenerator')) {
51
            $celda = \Sirgrimorum\CrudGenerator\CrudGenerator::field_array($this, $key);
0 ignored issues
show
Bug introduced by
The type Sirgrimorum\CrudGenerator\CrudGenerator was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
52
            if ($justValue) {
53
                return $celda['value'];
54
            } else {
55
                return $celda;
56
            }
57
        }
58
        if ($justValue) {
59
            return $this->{$key};
60
        } else {
61
            return [
62
                'value' => $this->{$key},
63
                "data" => $this->{$key},
64
                "label" => $key
65
            ];
66
        }
67
    }
68
69
}
70