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

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