Code Duplication    Length = 22-22 lines in 2 locations

src/Model/LDAPGateway.php 1 location

@@ 62-83 (lines=22) @@
59
        $records = $this->ldap->search($filter, $baseDn, $scope, $attributes, $sort);
60
61
        $results = [];
62
        foreach ($records as $record) {
63
            foreach ($record as $attribute => $value) {
64
                // if the value is an array with a single value, e.g. 'samaccountname' => array(0 => 'myusername')
65
                // then make sure it's just set in the results as 'samaccountname' => 'myusername' so that it
66
                // can be used directly by ArrayData
67
                if (is_array($value) && count($value) == 1) {
68
                    $value = $value[0];
69
                }
70
71
                // ObjectGUID and ObjectSID attributes are in binary, we need to convert those to strings
72
                if ($attribute == 'objectguid') {
73
                    $value = LDAPUtil::bin_to_str_guid($value);
74
                }
75
                if ($attribute == 'objectsid') {
76
                    $value = LDAPUtil::bin_to_str_sid($value);
77
                }
78
79
                $record[$attribute] = $value;
80
            }
81
82
            $results[] = $record;
83
        }
84
85
        return $results;
86
    }

tests/php/Model/LDAPFakeGateway.php 1 location

@@ 120-141 (lines=22) @@
117
    {
118
        $records = self::$data;
119
        $results = [];
120
        foreach ($records as $record) {
121
            foreach ($record as $attribute => $value) {
122
                // if the value is an array with a single value, e.g. 'samaccountname' => array(0 => 'myusername')
123
                // then make sure it's just set in the results as 'samaccountname' => 'myusername' so that it
124
                // can be used directly by ArrayData
125
                if (is_array($value) && count($value) == 1) {
126
                    $value = $value[0];
127
                }
128
129
                // ObjectGUID and ObjectSID attributes are in binary, we need to convert those to strings
130
                if ($attribute == 'objectguid') {
131
                    $value = LDAPUtil::bin_to_str_guid($value);
132
                }
133
                if ($attribute == 'objectsid') {
134
                    $value = LDAPUtil::bin_to_str_sid($value);
135
                }
136
137
                $record[$attribute] = $value;
138
            }
139
140
            $results[] = $record;
141
        }
142
143
        return $results;
144
    }