Code Duplication    Length = 31-31 lines in 2 locations

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

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

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

@@ 71-101 (lines=31) @@
68
        ]);
69
70
        $errors = $m->validate(false);
71
        if (true !== $errors) {
72
            foreach ($errors as $error) {
73
                $this->setOAuthError('invalid_request');
74
                $this->failure($error['field'], $error['rule']);
75
            }
76
        } else {
77
            // load original record, ovewrite
78
            if (!empty($data['uuid'])) {
79
                $m->load(['uuid = ?', $data['uuid']]);
80
            }
81
            $m->copyfrom($data);
82
83
            // load in original data and then replace for save
84
            if (!$m->validateSave()) {
85
                $this->setOAuthError('invalid_request');
86
                $this->failure('error', 'Unable to update object.');
87
                return;
88
            }
89
90
            $this->audit([
91
                'users_uuid' => $m->users_uuid,
92
                'actor' => $m->client_id,
93
                'event' => ' App Updated via API',
94
                'old' => $oldMapper->cast(),
95
                'new' => $m->cast()
96
            ]);
97
98
            // return raw data for object?
99
            $adminView = $f3->get('isAdmin') && 'admin' == $f3->get('REQUEST.view');
100
            $this->data = $adminView ? $m->castFields($f3->get('REQUEST.fields')) : $m->exportArray($f3->get('REQUEST.fields'));
101
        }
102
    }
103
104