Completed
Push — master ( 8004d0...4e5693 )
by Rougin
02:29
created

TableHelper::getModelName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
cc 2
eloc 5
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Rougin\Wildfire\Helpers;
4
5
/**
6
 * Table Helper
7
 *
8
 * @package Wildfire
9
 * @author  Rougin Royce Gutib <[email protected]>
10
 */
11
class TableHelper
12
{
13
    /**
14
     * Parses the table name from Describe class.
15
     *
16
     * @param  string $table
17
     * @return string
18
     */
19 36
    public static function getModelName($table)
20
    {
21 36
        $tableName = $table;
22
23 36
        $tableName  = ucfirst(singular($tableName));
24 36
        $tableNames = explode('.', $tableName);
25
26 36
        return isset($tableNames[1]) ? $tableNames[1] : $tableName;
27
    }
28
29
    /**
30
     * Gets the table name specified from the model.
31
     * NOTE: To be removed in v1.0.0. Use $model->getTableName()
32
     *
33
     * @param  object $model
34
     * @return string
35
     */
36 39
    public static function getNameFromModel($model)
37
    {
38 39
        $tableName = '';
39
40 39
        if (method_exists($model, 'getTableName')) {
41 39
            $tableName = $model->getTableName();
42 39
        }
43
44 39
        if (isset($model->table)) {
45 3
            $tableName = $model->table;
46 3
        }
47
48 39
        return $tableName;
49
    }
50
}
51