Code Duplication    Length = 42-43 lines in 2 locations

src/APIAccess/Group.php 1 location

@@ 316-358 (lines=43) @@
313
     * @throws \Exception se houver erro no retorno json
314
     * @see \FreeIPA\APIAccess\Connection\buildRequest()
315
     */
316
    public function get($params = null, $options = array())
317
    {
318
        if (!is_array($options)) {
319
            return false;
320
        }
321
322
        if (is_string($params)) {
323
            $final_params = array($params);
324
        } else if (is_array($params)) {
325
            $final_params = $params;
326
        } else {
327
            return false;
328
        }
329
330
        // Obtained with the command ipa -vv user-show admin
331
        $default_options = array(
332
            'all' => true,
333
            'no_members' => false,
334
            'raw' => false,
335
            'rights'    => false,
336
337
        );
338
        $final_options = array_merge($options, $default_options);
339
340
        $return_request = $this->getConnection()->buildRequest('group_show', $final_params, $final_options, false);
341
        $json = $return_request[0];
342
343
        if (!empty($json->error) && strtolower($json->error->name) == 'notfound') {
344
            // group not found
345
            return false;
346
        }
347
348
        if (empty($json->result)) {
349
            throw new \Exception('Malformed json');
350
        }
351
352
        // #TODO erase this code?
353
        if (!isset($json->result->result)) {
354
            return false;
355
        }
356
357
        return $json->result->result;
358
    }
359
360
    /**
361
     * Change group data

src/APIAccess/User.php 1 location

@@ 127-168 (lines=42) @@
124
     * @see ../../docs/return_samples/user_show.txt
125
     * @see \FreeIPA\APIAccess\Connection\buildRequest()
126
     */
127
    public function get($params = null, $options = array())
128
    {
129
        if (!is_array($options)) {
130
            return false;
131
        }
132
133
        if (is_string($params)) {
134
            $final_params = array($params);
135
        } else if (is_array($params)) {
136
            $final_params = $params;
137
        } else {
138
            return false;
139
        }
140
141
        // Obtained with the command ipa -vv user-show admin
142
        $default_options = array(
143
            'all' => true,
144
            'no_members' => false,
145
            'raw' => false,
146
            'rights' => false,
147
        );
148
        $final_options = array_merge($options, $default_options);
149
150
        $return_request = $this->getConnection()->buildRequest('user_show', $final_params, $final_options, false);
151
        $json = $return_request[0];
152
153
        if (!empty($json->error) && strtolower($json->error->name) == 'notfound') {
154
            // user not found
155
            return false;
156
        }
157
158
        if (empty($json->result)) {
159
            throw new \Exception('Malformed json');
160
        }
161
162
        // #TODO erase this code?
163
        if (!isset($json->result->result)) {
164
            return false;
165
        }
166
167
        return $json->result->result;
168
    }
169
170
    /**
171
     * Adds a user