Activity::dataValue()   A
last analyzed

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 2
Bugs 1 Features 0
Metric Value
c 2
b 1
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 static $this
24
 */
25
class Activity extends Model
26
{
27
    use RelationTrait;
28
29
    /**
30
     * Timestamp enabled.
31
     *
32
     * @var bool
33
     */
34
    public $timestamps = true;
35
36
    /**
37
     * Name of database table.
38
     *
39
     * @var string
40
     */
41
    protected $table = 'users_activity';
42
43
    /**
44
     * List of allowed columns to be used in $this->fill().
45
     *
46
     * @var array
47
     */
48
    protected $fillable = ['type_id', 'parent_id', 'user_id', 'item_id', 'action_id', 'data'];
49
50
    /**
51
     * List of columns and their cast data-type.
52
     *
53
     * @var array
54
     */
55
    protected $casts = [
56
        'data' => 'array',
57
    ];
58
59
    /**
60
     * Get a value from the data field using "dot" notation.
61
     *
62
     * @param string $name
63
     *
64
     * @return Collection
65
     */
66 1
    public function dataCollection($name)
67
    {
68 1
        return new Collection($this->dataValue($name));
69
    }
70
71
    /*
72
     * Get a value from the data field using "dot" notation.
73
     *
74
     * @param string $name
75
     *
76
     * @return mixed
77
     */
78 1
    public function dataValue($name)
79
    {
80 1
        return array_get($this->data, $name);
0 ignored issues
show
Documentation introduced by
The property data does not exist on object<Tinyissue\Model\User\Activity>. 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...
81
    }
82
}
83