GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

SaleTransformer   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 1
c 2
b 1
f 0
lcom 1
cbo 3
dl 0
loc 28
rs 10
ccs 0
cts 18
cp 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A transform() 0 18 1
1
<?php
2
3
namespace App\Transformers;
4
5
use App\Sale;
6
use League\Fractal\TransformerAbstract;
7
8
class SaleTransformer extends TransformerAbstract
9
{
10
    /**
11
     * Turn this item object into a generic array.
12
     *
13
     * @param Sale $sale
14
     *
15
     * @return array
16
     */
17
    public function transform(Sale $sale)
18
    {
19
        return [
20
            'id'      => $sale->id,
21
            'name'    => $sale->name,
22
            'address' => $sale->address,
23
            'isShop'  => is_null($this->shop_id),
0 ignored issues
show
Bug introduced by
The property shop_id does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
24
            'make'    => [
25
                'id'   => $sale->make->id,
0 ignored issues
show
Documentation introduced by
The property make does not exist on object<App\Sale>. 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...
26
                'name' => $sale->make->name,
0 ignored issues
show
Documentation introduced by
The property make does not exist on object<App\Sale>. 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...
27
            ],
28
            'bought'  => [
29
                'timestamp' => $sale->created_at->getTimestamp(),
30
                'date'      => $sale->created_at->toFormattedDateString(),
31
                'readable'  => $sale->created_at->diffForHumans(),
32
            ],
33
        ];
34
    }
35
}
36