AbstractMapper   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 11
c 1
b 0
f 0
dl 0
loc 33
ccs 11
cts 11
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getDbTable() 0 10 2
A getShortClassName() 0 6 1
1
<?php
2
3
namespace mQueue\Model;
4
5
use Zend_Db_Table_Abstract;
6
7
abstract class AbstractMapper
8
{
9
    private static $dbTables = [];
10
11
    /**
12
     * Returns the Zend_Db_Table for the current model class
13
     *
14
     * @return Zend_Db_Table_Abstract
15
     */
16 16
    public static function getDbTable()
17
    {
18 16
        $className = self::getShortClassName();
19 16
        $dbTableClassName = '\mQueue\Model\DbTable\\' . $className;
20 16
        if (!array_key_exists($dbTableClassName, self::$dbTables)) {
21 2
            $dbTable = new $dbTableClassName();
22 2
            self::$dbTables[$dbTableClassName] = $dbTable;
23
        }
24
25 16
        return self::$dbTables[$dbTableClassName];
26
    }
27
28
    /**
29
     * Returns the short class name of the model
30
     * eg: called from \mQueue\Model\ChapterMapper, it will return 'Chapter'
31
     *
32
     * @return string short class name
33
     */
34 16
    private static function getShortClassName()
35
    {
36 16
        $className = get_called_class();
37 16
        preg_match('/([^\\\\]*)Mapper$/', $className, $r);
38
39 16
        return $r[1];
40
    }
41
}
42