Code Duplication    Length = 23-23 lines in 3 locations

app/lib/FFCMS/Controllers/API/OAuth2Apps.php 1 location

@@ 66-88 (lines=23) @@
63
        ]);
64
65
        $errors = $m->validate(false);
66
        if (true !== $errors) {
67
            foreach ($errors as $error) {
68
                $this->setOAuthError('invalid_request');
69
                $this->failure($error['field'], $error['rule']);
70
            }
71
        } else {
72
            // load original record, ovewrite
73
            if (!empty($data['uuid'])) {
74
                $m->load(['uuid = ?', $data['uuid']]);
75
            }
76
            $m->copyfrom($data);
77
78
            // load in original data and then replace for save
79
            if (!$m->save()) {
80
                $this->setOAuthError('invalid_request');
81
                $this->failure('error', 'Unable to update object.');
82
                return;
83
            }
84
85
            // return raw data for object?
86
            $adminView = $f3->get('isAdmin') && 'admin' == $f3->get('REQUEST.view');
87
            $this->data = $adminView ? $m->castFields($f3->get('REQUEST.fields')) : $m->exportArray($f3->get('REQUEST.fields'));
88
        }
89
    }
90
91

app/lib/FFCMS/Controllers/API/OAuth2Tokens.php 1 location

@@ 70-92 (lines=23) @@
67
        ]);
68
69
        $errors = $m->validate(false);
70
        if (true !== $errors) {
71
            foreach ($errors as $error) {
72
                $this->setOAuthError('invalid_request');
73
                $this->failure($error['field'], $error['rule']);
74
            }
75
        } else {
76
            // load original record, ovewrite
77
            if (!empty($data['uuid'])) {
78
                $m->load(['uuid = ?', $data['uuid']]);
79
            }
80
            $m->copyfrom($data);
81
82
            // load in original data and then replace for save
83
            if (!$m->save()) {
84
                $this->setOAuthError('invalid_request');
85
                $this->failure('error', 'Unable to update object.');
86
                return;
87
            }
88
89
            // return raw data for object?
90
            $adminView = $f3->get('isAdmin') && 'admin' == $f3->get('REQUEST.view');
91
            $this->data = $adminView ? $m->castFields($f3->get('REQUEST.fields')) : $m->exportArray($f3->get('REQUEST.fields'));
92
        }
93
    }
94
95

app/lib/FFCMS/Controllers/API/Audit.php 1 location

@@ 56-78 (lines=23) @@
53
        ]);
54
55
        $errors = $m->validate(false);
56
        if (true !== $errors) {
57
            foreach ($errors as $error) {
58
                $this->setOAuthError('invalid_request');
59
                $this->failure($error['field'], $error['rule']);
60
            }
61
        } else {
62
            // load original record, ovewrite
63
            if (!empty($data['uuid'])) {
64
                $m->load(['uuid = ?', $data['uuid']]);
65
            }
66
            $m->copyfrom($data);
67
68
            // load in original data and then replace for save
69
            if (!$m->save()) {
70
                $this->setOAuthError('invalid_request');
71
                $this->failure('error', 'Unable to update object.');
72
                return;
73
            }
74
75
            // return raw data for object?
76
            $adminView = $f3->get('isAdmin') && 'admin' == $f3->get('REQUEST.view');
77
            $this->data = $adminView ? $m->castFields($f3->get('REQUEST.fields')) : $m->exportArray($f3->get('REQUEST.fields'));
78
        }
79
    }
80
81
}