Completed
Push — master ( 3e9aa7...1cfafa )
by Francesco
03:13
created

Reacts::reactTo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 5
nc 1
nop 2
1
<?php
2
3
namespace FrancescoMalatesta\LaravelReactions\Traits;
4
5
use FrancescoMalatesta\LaravelReactions\Contracts\ReactableInterface;
6
use FrancescoMalatesta\LaravelReactions\Models\Reaction;
7
8
trait Reacts
9
{
10
    public function reactTo(ReactableInterface $reactable, Reaction $reaction)
11
    {
12
        $reactable->reactions()->attach(
13
            $reaction->id,
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<FrancescoMalatest...ctions\Models\Reaction>. 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...
14
            [
15
                'reagent_id' => $this->id,
0 ignored issues
show
Bug introduced by
The property 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...
16
                'reagent_type' => get_class($this)
17
            ]
18
        );
19
    }
20
}
21