UserSync::createUser()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 2
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of Jitamin.
5
 *
6
 * Copyright (C) Jitamin Team
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Jitamin\Foundation\Identity;
13
14
use Jitamin\Foundation\Base;
15
16
/**
17
 * User Synchronization.
18
 */
19
class UserSync extends Base
20
{
21
    /**
22
     * Synchronize user profile.
23
     *
24
     * @param UserProviderInterface $user
25
     *
26
     * @return array
27
     */
28
    public function synchronize(UserProviderInterface $user)
29
    {
30
        $profile = $this->userModel->getByExternalId($user->getExternalIdColumn(), $user->getExternalId());
0 ignored issues
show
Documentation introduced by
The property userModel does not exist on object<Jitamin\Foundation\Identity\UserSync>. 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...
31
        $properties = UserProperty::getProperties($user);
32
33
        if (!empty($profile)) {
34
            $profile = $this->updateUser($profile, $properties);
35
        } elseif ($user->isUserCreationAllowed()) {
36
            $profile = $this->createUser($user, $properties);
37
        }
38
39
        return $profile;
40
    }
41
42
    /**
43
     * Update user profile.
44
     *
45
     * @param array $profile
46
     * @param array $properties
47
     *
48
     * @return array
49
     */
50
    private function updateUser(array $profile, array $properties)
51
    {
52
        $values = UserProperty::filterProperties($profile, $properties);
53
54
        if (!empty($values)) {
55
            $values['id'] = $profile['id'];
56
            $result = $this->userModel->update($values);
0 ignored issues
show
Documentation introduced by
The property userModel does not exist on object<Jitamin\Foundation\Identity\UserSync>. 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...
57
58
            return $result ? array_merge($profile, $properties) : $profile;
59
        }
60
61
        return $profile;
62
    }
63
64
    /**
65
     * Create user.
66
     *
67
     * @param UserProviderInterface $user
68
     * @param array                 $properties
69
     *
70
     * @return array
71
     */
72
    private function createUser(UserProviderInterface $user, array $properties)
73
    {
74
        $userId = $this->userModel->create($properties);
0 ignored issues
show
Documentation introduced by
The property userModel does not exist on object<Jitamin\Foundation\Identity\UserSync>. 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...
75
76
        if ($userId === false) {
77
            $this->logger->error('Unable to create user profile: '.$user->getExternalId());
0 ignored issues
show
Documentation introduced by
The property logger does not exist on object<Jitamin\Foundation\Identity\UserSync>. 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...
78
79
            return [];
80
        }
81
82
        return $this->userModel->getById($userId);
0 ignored issues
show
Documentation introduced by
The property userModel does not exist on object<Jitamin\Foundation\Identity\UserSync>. 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...
83
    }
84
}
85