Completed
Push — master ( ed61e9...497a60 )
by Rougin
04:46
created

TableHelper::name()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 4
nop 1
crap 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
     * NOTE: To be removed in v1.0.0. Use self::model instead.
16
     *
17
     * @param  string $table
18
     * @return string
19
     */
20
    public static function getModelName($table)
21
    {
22
        return self::model($table);
23
    }
24
25
    /**
26
     * Parses the table name from Describe class.
27
     *
28
     * @param  string $table
29
     * @return string
30
     */
31 36
    public static function model($table)
32
    {
33 36
        $name = (string) ucfirst(singular($table));
34
35 36
        $names = (array) explode('.', $name);
36
37 36
        return isset($names[1]) ? $names[1] : $name;
38
    }
39
40
    /**
41
     * Gets the table name specified from the model.
42
     * NOTE: To be removed in v1.0.0. Use self::name instead.
43
     *
44
     * @param  object $model
45
     * @return string
46
     */
47 6
    public static function getNameFromModel($model)
48
    {
49 6
        return self::name($model);
50
    }
51
52
    /**
53
     * Gets the table name specified from the model.
54
     * NOTE: To be removed in v1.0.0. Use $model->table()
55
     *
56
     * @param  object $model
57
     * @return string
58
     */
59 39
    public static function name($model)
60
    {
61 39
        $table = '';
62
63 39
        $exists = method_exists($model, 'table');
64
65 39
        $exists && $table = $model->table();
66
67 39
        isset($model->table) && $table = $model->table;
68
69 39
        return $table;
70
    }
71
}
72