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

ModelHelper::createInstance()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Rougin\Wildfire\Helpers;
4
5
/**
6
 * Model Helper
7
 *
8
 * @package Wildfire
9
 * @author  Rougin Royce Gutib <[email protected]>
10
 */
11
class ModelHelper
12
{
13
    /**
14
     * Returns the model class of the said table.
15
     * NOTE: To be removed in v1.0.0. Use self::make instead.
16
     *
17
     * @param  string|object $table
18
     * @return array
19
     */
20 39
    public static function createInstance($table)
21
    {
22 39
        return self::make($table);
23
    }
24
25
    /**
26
     * Returns the model class of the said table.
27
     *
28
     * @param  string|object $table
29
     * @return array
30
     */
31 39
    public static function make($table)
32
    {
33 39
        if (is_object($table) === true) {
34 9
            $name = TableHelper::name($table);
35
36 9
            return array((string) $name, $table);
37
        }
38
39 36
        $model = TableHelper::model($table);
40
41 36
        $model = new $model;
42
43 36
        $name = TableHelper::name($model);
44
45 36
        return array((string) $name, $model);
46
    }
47
}
48