AbstractMapper::getDbTable()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 10
ccs 7
cts 7
cp 1
rs 10
cc 2
nc 2
nop 0
crap 2
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