Prettifier::getInstance()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace MazenTouati\NoEmoji;
5
6
use MazenTouati\Simple2wayConfig\S2WConfig;
7
use MazenTouati\NoEmoji\Entities\File;
8
9
/**
10
 * Uses the scrapped unicodes to generate a RegEx pattern
11
 *
12
 * @author Mazen Touati <[email protected]>
13
 */
14
class Prettifier
15
{
16
    /**
17
     * The class instance
18
     *
19
     * @var Prettifier
20
     */
21
    private static $_instance = null;
22
23
    /**
24
     * File instance
25
     * @var File
26
     */
27
    private $_file;
28
29
    /**
30
     * Configuration object
31
     *
32
     * @var S2WConfig
33
     */
34
    public $config;
35
36
    /**
37
     * The pretty content
38
     * @var string
39
     */
40
    private $_content;
41
42
    /**
43
     * Retrieves the singleton instance
44
     *
45
     * @return Prettifier
46
     */
47
    public static function getInstance()
48
    {
49
        if (self::$_instance == null) {
50
            self::$_instance = new Prettifier();
51
        }
52
53
        return self::$_instance;
54
    }
55
56
    /**
57
     * Initializes the Scrapper
58
     *
59
     * @param S2WConfig $c Configuration object
60
     *
61
     * @return Prettifier
62
     */
63
    public static function factory(S2WConfig $c)
64
    {
65
        $instance = self::getInstance();
66
        $instance->config = $c;
67
68
        $instance->_file = new File($c, 'storage.output.ranges');
69
70
        return $instance;
71
    }
72
73
    /**
74
     * Starts prettifying
75
     *
76
     * @param  string $type Prettifier class name
77
     *
78
     * @return Prettifier
79
     */
80
    public function run($type = 'ArrayPrettifier')
81
    {
82
        $type = 'MazenTouati\NoEmoji\Prettifiers\\'.$type;
83
        $this->_content = $type::run($this->_file);
84
        return $this;
85
    }
86
87
    /**
88
     * Exports the pretty output
89
     *
90
     * @return boolean|array Returns false on error or the result array
91
     */
92
    public function export()
93
    {
94
        $base = $this->config->get('storage.base');
95
        $fileTitle = $this->config->get('storage.output.prettyRangesFileTitle', 'Undefined Title');
96
        $output = $this->config->get('storage.output.prettyRanges');
97
98
        $export = File::toText($base . $output, $fileTitle, $this->_content);
99
100
        if (!is_array($export)) {
101
            return false;
102
        }
103
104
        return $export;
105
    }
106
}
107