Completed
Push — master ( d58309...398f96 )
by Sebastian
06:30 queued 02:44
created

ContentBlockController::add()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers\Back\Api;
4
5
use App\Models\ContentBlock;
6
use App\Http\Controllers\Controller;
7
use Illuminate\Database\Eloquent\Model;
8
use App\Http\Requests\Back\ContentBlockRequest;
9
use App\Models\Transformers\ContentBlockTransformer;
10
11
class ContentBlockController extends Controller
12
{
13
    public function add(ContentBlockRequest $request)
14
    {
15
        $model = $this->getModelFromRequest($request);
16
17
        $contentBlock = new ContentBlock(['collection_name' => $request->collection_name]);
0 ignored issues
show
Documentation introduced by
The property collection_name does not exist on object<App\Http\Requests...ck\ContentBlockRequest>. 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...
18
19
        $model->contentBlocks()->save($contentBlock);
20
21
        return fractal($contentBlock, new ContentBlockTransformer());
22
    }
23
24
    protected function getModelFromRequest(ContentBlockRequest $request): Model
25
    {
26
        return call_user_func($request['model_name'].'::findOrFail', $request['model_id']);
27
    }
28
}
29