UserAdapter::fromEloquent()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace NilPortugues\Example\Service;
4
5
use DateTimeImmutable;
6
use NilPortugues\Example\Domain\User;
7
use NilPortugues\Example\Domain\UserId;
8
use NilPortugues\Example\Persistence\Eloquent\User as MongoDBUser;
9
10
class UserAdapter
11
{
12
    /**
13
     * @param User $user
14
     *
15
     * @return \NilPortugues\Example\Persistence\Eloquent\User
16
     */
17
    public function toEloquent(User $user)
18
    {
19
        $mongoDB = new MongoDBUser();
20
        $mongoDB->id = $user->id();
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<NilPortugues\Exam...sistence\Eloquent\User>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
21
        $mongoDB->name = $user->name();
0 ignored issues
show
Documentation introduced by
The property name does not exist on object<NilPortugues\Exam...sistence\Eloquent\User>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
22
        $mongoDB->created_at = $user->registrationDate();
0 ignored issues
show
Documentation introduced by
The property created_at does not exist on object<NilPortugues\Exam...sistence\Eloquent\User>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
23
24
        return $mongoDB;
25
    }
26
    /**
27
     * @param array $model
28
     *
29
     * @return \NilPortugues\Example\Domain\User
30
     */
31
    public function fromEloquent(array $model)
32
    {
33
        return new User(new UserId($model['id']), $model['name'], new DateTimeImmutable($model['created_at']));
34
    }
35
}
36