Completed
Push — master ( a964bf...08af9f )
by David
05:01 queued 18s
created

TemplateTransformer::includeDetail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php namespace App\LaravelRestCms\Template;
2
3
use App\LaravelRestCms\BaseModel;
4
use App\LaravelRestCms\BaseTransformer;
5
6
class TemplateTransformer extends BaseTransformer {
7
8
	/**
9
	 * List of resources possible to include
10
	 *
11
	 * @var array
12
	 */
13
	protected $availableIncludes = [
14
		'detail',
15
	];
16
17
    /**
18
     * Transforms a Page model
19
     * 
20
     * @param  \App\LaravelRestCms\BaseModel $page
21
     * @return array
22
     
23
    public function transform(BaseModel $page)
24
    {
25
        return [
26
            'id' => (int) $page->id,
27
            'parent_id' => (int)$page->parent_id,
28
            'template_id' => (int) $page->template_id,
29
            'nav_name' => $page->nav_name,
30
            'url' => $page->url,
31
            'title' => $page->title,
32
        ];
33
    }
34
*/
35
    /**
36
     * Include Template Detail
37
     * 
38
     * @param \App\LaravelRestCms\Template\Template $template
39
     * @return \League\Fractal\ItemResource
40
     */
41
    public function includeDetail(Template $template)
42
    {
43
        return $this->collection($template->detail, new TemplateDetailTransformer);
0 ignored issues
show
Documentation introduced by
The property detail does not exist on object<App\LaravelRestCms\Template\Template>. 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...
Documentation introduced by
new \App\LaravelRestCms\...lateDetailTransformer() is of type object<App\LaravelRestCm...plateDetailTransformer>, but the function expects a callable.

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...
44
    }
45
}
46