GroupSync   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 53
rs 10
c 0
b 0
f 0
wmc 9
lcom 0
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A synchronize() 0 6 1
A addGroups() 0 14 4
A removeGroups() 0 8 4
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
 * Group Synchronization.
18
 */
19
class GroupSync extends Base
20
{
21
    /**
22
     * Synchronize group membership.
23
     *
24
     * @param int   $userId
25
     * @param array $externalGroupIds
26
     */
27
    public function synchronize($userId, array $externalGroupIds)
28
    {
29
        $userGroups = $this->groupMemberModel->getGroups($userId);
0 ignored issues
show
Documentation introduced by
The property groupMemberModel does not exist on object<Jitamin\Foundation\Identity\GroupSync>. 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...
30
        $this->addGroups($userId, $userGroups, $externalGroupIds);
31
        $this->removeGroups($userId, $userGroups, $externalGroupIds);
32
    }
33
34
    /**
35
     * Add missing groups to the user.
36
     *
37
     * @param int   $userId
38
     * @param array $userGroups
39
     * @param array $externalGroupIds
40
     */
41
    protected function addGroups($userId, array $userGroups, array $externalGroupIds)
42
    {
43
        $userGroupIds = array_column($userGroups, 'external_id', 'external_id');
44
45
        foreach ($externalGroupIds as $externalGroupId) {
46
            if (!isset($userGroupIds[$externalGroupId])) {
47
                $group = $this->groupModel->getByExternalId($externalGroupId);
0 ignored issues
show
Documentation introduced by
The property groupModel does not exist on object<Jitamin\Foundation\Identity\GroupSync>. 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...
48
49
                if (!empty($group)) {
50
                    $this->groupMemberModel->addUser($group['id'], $userId);
0 ignored issues
show
Documentation introduced by
The property groupMemberModel does not exist on object<Jitamin\Foundation\Identity\GroupSync>. 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...
51
                }
52
            }
53
        }
54
    }
55
56
    /**
57
     * Remove groups from the user.
58
     *
59
     * @param int   $userId
60
     * @param array $userGroups
61
     * @param array $externalGroupIds
62
     */
63
    protected function removeGroups($userId, array $userGroups, array $externalGroupIds)
64
    {
65
        foreach ($userGroups as $userGroup) {
66
            if (!empty($userGroup['external_id']) && !in_array($userGroup['external_id'], $externalGroupIds)) {
67
                $this->groupMemberModel->removeUser($userGroup['id'], $userId);
0 ignored issues
show
Documentation introduced by
The property groupMemberModel does not exist on object<Jitamin\Foundation\Identity\GroupSync>. 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...
68
            }
69
        }
70
    }
71
}
72