Code Duplication    Length = 12-14 lines in 3 locations

code/extensions/LDAPMemberExtension.php 3 locations

@@ 162-174 (lines=13) @@
159
     * Create the user in LDAP, provided this configuration is enabled
160
     * and a username was passed to a new Member record.
161
     */
162
    public function onBeforeWrite()
163
    {
164
        $service = Injector::inst()->get('LDAPService');
165
        if (!$service->enabled()) {
166
            return;
167
        }
168
        if (!$this->owner->config()->create_users_in_ldap) {
169
            return;
170
        }
171
        if ($this->owner->Username && !$this->owner->IsImportedFromLDAP) {
172
            $service->createLDAPUser($this->owner);
173
        }
174
    }
175
176
    /**
177
     * Update the local data with LDAP, and ensure local membership is also set in
@@ 180-193 (lines=14) @@
177
     * Update the local data with LDAP, and ensure local membership is also set in
178
     * LDAP too. This writes into LDAP, provided that feature is enabled.
179
     */
180
    public function onAfterWrite()
181
    {
182
        $service = Injector::inst()->get('LDAPService');
183
        if (!$service->enabled()) {
184
            return;
185
        }
186
        if (!$this->owner->config()->update_ldap_from_local) {
187
            return;
188
        }
189
        if ($this->owner->IsImportedFromLDAP) {
190
            $service->updateLDAPFromMember($this->owner);
191
            $service->updateLDAPGroupsForMember($this->owner);
192
        }
193
    }
194
195
    public function onAfterDelete() {
196
        $service = Injector::inst()->get('LDAPService');
@@ 195-206 (lines=12) @@
192
        }
193
    }
194
195
    public function onAfterDelete() {
196
        $service = Injector::inst()->get('LDAPService');
197
        if (!$service->enabled()) {
198
            return;
199
        }
200
        if (!$this->owner->config()->delete_users_in_ldap) {
201
            return;
202
        }
203
        if ($this->owner->IsImportedFromLDAP) {
204
            $service->deleteLDAPMember($this->owner);
205
        }
206
    }
207
208
    /**
209
     * Triggered by {@link Member::logIn()} when successfully logged in,