Completed
Push — master ( 509012...3eafe2 )
by David
02:34
created

PageTransformer::includeDetail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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