Completed
Branch develop (c3857f)
by Mohamed
03:30
created

Activity::dataValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
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\User;
13
14
use Illuminate\Database\Eloquent\Model;
15
use Illuminate\Support\Collection;
16
use Tinyissue\Model\Traits\User\Activity\RelationTrait;
17
18
/**
19
 * Activity is model class for user activities.
20
 *
21
 * @author Mohamed Alsharaf <[email protected]>
22
 *
23
 * @property int    $id
24
 * @property string $data
25
 * @property int    $type_id
26
 * @property int    $parent_id
27
 * @property int    $user_id
28
 * @property int    $item_id
29
 * @property int    $action_id
30
 */
31
class Activity extends Model
32
{
33
    use RelationTrait;
34
35
    /**
36
     * Timestamp enabled.
37
     *
38
     * @var bool
39
     */
40
    public $timestamps = true;
41
42
    /**
43
     * Name of database table.
44
     *
45
     * @var string
46
     */
47
    protected $table = 'users_activity';
48
49
    /**
50
     * List of allowed columns to be used in $this->fill().
51
     *
52
     * @var array
53
     */
54
    protected $fillable = ['type_id', 'parent_id', 'user_id', 'item_id', 'action_id', 'data'];
55
56
    /**
57
     * List of columns and their cast data-type.
58
     *
59
     * @var array
60
     */
61
    protected $casts = [
62
        'data' => 'array',
63
    ];
64
65
     /**
66
      * Get a value from the data field using "dot" notation.
67
      *
68
      * @param string $name
69
      *
70
      * @return Collection
71
      */
72 1
     public function dataCollection($name)
73
     {
74 1
         return new Collection($this->dataValue($name));
75
     }
76
77
     /*
78
      * Get a value from the data field using "dot" notation.
79
      *
80
      * @param string $name
81
      *
82
      * @return mixed
83
      */
84 1
     public function dataValue($name)
85
     {
86 1
         return array_get($this->data, $name);
0 ignored issues
show
Documentation introduced by
$this->data is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
87
     }
88
}
89