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
@@ 429-438 (lines=10) @@
426
     *
427
     * @return number Number of Sosas
428
     */
429
    public function getSosaCount(){
430
        if(!$this->is_setup) return 0;
431
        return Database::prepare(
432
            'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' .
433
            ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id')
434
            ->execute(array(
435
                'tree_id' => $this->tree->getTreeId(), 
436
                'user_id' => $this->user->getUserId() 
437
            ))->fetchOne() ?: 0;
438
    }
439
    
440
    /**
441
     * Get the number of Sosa in a specific generation.
@@ 483-492 (lines=10) @@
480
     *
481
     * @return number Total number of distinct individual
482
     */
483
    public function getDifferentSosaCount(){
484
        if(!$this->is_setup) return 0;
485
        return Database::prepare(
486
            'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' .
487
            ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id')
488
        ->execute(array(
489
                'tree_id' => $this->tree->getTreeId(), 
490
                'user_id' => $this->user->getUserId()
491
        ))->fetchOne() ?: 0;
492
    }
493
    
494
    /**
495
     * Get the number of distinct Sosa individual up to a specific generation.