Test Setup Failed
Push — master ( 43ee18...a50601 )
by Josh
04:51
created

Format   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 21
dl 0
loc 57
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getMigrationName() 0 13 3
A prettyVarExport() 0 14 3
A __construct() 0 6 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: joshgulledge
5
 * Date: 9/12/18
6
 * Time: 12:38 PM
7
 */
8
9
namespace LCI\Blend\Helpers;
10
11
12
class Format
13
{
14
    protected $path_time_stamp;
15
16
    /**
17
     * Format constructor.
18
     * @param null $path_time_stamp
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $path_time_stamp is correct as it would always require null to be passed?
Loading history...
19
     */
20
    public function __construct($path_time_stamp=null)
21
    {
22
        if (!empty($path_time_stamp)) {
23
            $this->path_time_stamp = $path_time_stamp;
24
        } else {
25
            $this->path_time_stamp = date('Y_m_d_His');
26
        }
27
    }
28
29
    /**
30
     * @param $type
31
     * @param null $name
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $name is correct as it would always require null to be passed?
Loading history...
32
     * @return string
33
     */
34
    public function getMigrationName($type, $name=null)
35
    {
36
        $dir_name = 'm'.$this->path_time_stamp.'_';
37
        if (empty($name)) {
38
            $name = ucfirst(strtolower($type));
39
            if ($name == 'Mediasource') {
40
                $name = 'MediaSource';
41
            }
42
        }
43
44
        $dir_name .= preg_replace('/[^A-Za-z0-9\_]/', '', str_replace(['/', ' '], '_', $name));
45
46
        return $dir_name;
47
    }
48
49
    /**
50
     * @param mixed|array $data
51
     * @param int $tabs
52
     *
53
     * @return string
54
     */
55
    public function prettyVarExport($data, $tabs=1)
56
    {
57
        $spacing = str_repeat(' ', 4*$tabs);
58
59
        $string = '';
60
        $parts = preg_split('/\R/', var_export($data, true));
61
        foreach ($parts as $k => $part) {
62
            if ($k > 0) {
63
                $string .= $spacing;
64
            }
65
            $string .= $part.PHP_EOL;
66
        }
67
68
        return trim($string);
69
    }
70
71
}