RoomItem::store()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 14
nc 2
nop 9

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace App\Models;
4
5
/**
6
 * Class RoomItem.
7
 */
8
class RoomItem extends ChocolateyModel
9
{
10
    /**
11
     * Disable Timestamps.
12
     *
13
     * @var bool
14
     */
15
    public $timestamps = false;
16
17
    /**
18
     * The table associated with the model.
19
     *
20
     * @var string
21
     */
22
    protected $table = 'items';
23
24
    /**
25
     * Primary Key of the Table.
26
     *
27
     * @var string
28
     */
29
    protected $primaryKey = 'id';
30
31
    /**
32
     * Store a RoomItem.
33
     *
34
     * @param int    $userId
35
     * @param int    $roomId
36
     * @param int    $itemId
37
     * @param int    $xPosition
38
     * @param int    $yPosition
39
     * @param string $zPosition
40
     * @param int    $rotation
41
     * @param string $extraData
42
     * @param string $wallPosition
43
     *
44
     * @return RoomItem
45
     */
46
    public function store(int $userId, int $roomId, int $itemId, int $xPosition, int $yPosition, string $zPosition, int $rotation, string $extraData, string $wallPosition = ''): RoomItem
47
    {
48
        $this->attributes['user_id'] = $userId;
49
        $this->attributes['room_id'] = $roomId;
50
        $this->attributes['item_id'] = $itemId;
51
        $this->attributes['x'] = $xPosition;
52
        $this->attributes['y'] = $yPosition;
53
        $this->attributes['z'] = $zPosition;
54
        $this->attributes['rot'] = $rotation;
55
        $this->attributes['extra_data'] = $extraData;
56
        $this->timestamps = false;
57
58
        if (!empty($wallPosition)) {
59
            $this->attributes['wall_pos'] = $wallPosition;
60
        }
61
62
        $this->save();
63
64
        return $this;
65
    }
66
}
67