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

TableHelper   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 40
ccs 14
cts 14
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getModelName() 0 9 2
A getNameFromModel() 0 14 3
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