Code Duplication    Length = 10-11 lines in 4 locations

src/Webtrees/Module/Sosa/Model/SosaProvider.php 4 locations

@@ 226-236 (lines=11) @@
223
     * @param Individual $indi
224
     * @return array Array of sosa numbers
225
     */
226
    public function getSosaNumbers(Individual $indi) {
227
        if(!$this->is_setup) return array();
228
        return Database::prepare(
229
                'SELECT majs_sosa, majs_gen FROM `##maj_sosa`'.
230
                ' WHERE majs_i_id=:indi_id AND majs_gedcom_id=:tree_id AND majs_user_id=:user_id'
231
            )->execute(array(
232
                'indi_id' => $indi->getXref(), 
233
                'tree_id' => $this->tree->getTreeId(), 
234
                'user_id' => $this->user->getUserId()
235
            ))->fetchAssoc();
236
    }
237
    
238
    /**
239
     * Get the last generation of Sosa ancestors
@@ 243-252 (lines=10) @@
240
     *
241
     * @return number Last generation if found, 1 otherwise
242
     */
243
    public function getLastGeneration() {
244
        if(!$this->is_setup) return;
245
        return Database::prepare(
246
                'SELECT MAX(majs_gen) FROM `##maj_sosa`'.
247
                ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'
248
            )->execute(array(
249
                'tree_id' => $this->tree->getTreeId(), 
250
                'user_id' => $this->user->getUserId()                
251
            ))->fetchOne() ?: 1;
252
    }
253
    
254
    /*************
255
     * SOSA LISTS
@@ 428-437 (lines=10) @@
425
     *
426
     * @return number Number of Sosas
427
     */
428
    public function getSosaCount(){
429
        if(!$this->is_setup) return 0;
430
        return Database::prepare(
431
            'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' .
432
            ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id')
433
            ->execute(array(
434
                'tree_id' => $this->tree->getTreeId(), 
435
                'user_id' => $this->user->getUserId() 
436
            ))->fetchOne() ?: 0;
437
    }
438
    
439
    /**
440
     * Get the number of Sosa in a specific generation.
@@ 482-491 (lines=10) @@
479
     *
480
     * @return number Total number of distinct individual
481
     */
482
    public function getDifferentSosaCount(){
483
        if(!$this->is_setup) return 0;
484
        return Database::prepare(
485
            'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' .
486
            ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id')
487
        ->execute(array(
488
                'tree_id' => $this->tree->getTreeId(), 
489
                'user_id' => $this->user->getUserId()
490
        ))->fetchOne() ?: 0;
491
    }
492
    
493
    /**
494
     * Get the number of distinct Sosa individual up to a specific generation.