Advert::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of ibrand/advert.
5
 *
6
 * (c) iBrand <https://www.ibrand.cc>
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 iBrand\Component\Advert\Models;
13
14
use Illuminate\Database\Eloquent\Model;
15
16
class Advert extends Model
17
{
18
19
    const STATUS_OPEN = 1; // 可用状态
20
21
    const STATUS_CLOSE = 0;  // 关闭状态
22
23
    protected $guarded = ['id'];
24
25
    /**
26
     * Address constructor.
27
     *
28
     * @param array $attributes
29
     */
30 4
    public function __construct(array $attributes = [])
31
    {
32
33 4
        $this->setTable(config('ibrand.app.database.prefix', 'ibrand_').'advert');
34
35 4
        parent::__construct($attributes);
36 4
    }
37
38 1
    public function addAdvertItem(array $attributes = []){
39
40 1
        $attributes['advert_id'] = $this->id;
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<iBrand\Component\Advert\Models\Advert>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
41
42 1
       return AdvertItem::create($attributes);
43
44
    }
45
46
47
}
48