Completed
Push — master ( 4842a8...ce9dbc )
by Samuel
02:23
created

JsynExtractor::setJsynFile()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 2 Features 2
Metric Value
c 5
b 2
f 2
dl 0
loc 14
rs 9.4285
cc 3
eloc 8
nc 3
nop 1
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 41 and the first side effect is on line 21.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
/*
4
 * This file is part of the samshal/scripd package.
5
 *
6
 * (c) Samuel Adeshina <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Samshal\Scripd;
13
14
/**
15
 * Contains utility methods for parsing a jsyn file.
16
 *
17
 * @since  1.0
18
 *
19
 * @author Samuel Adeshina <[email protected]>
20
 */
21
final class JsynExtractor
0 ignored issues
show
Bug introduced by
Possible parse error: class missing opening or closing brace
Loading history...
22
{
23
    /**
24
     * @var string
25
     *
26
     * Content of the JSYN File
27
     */
28
    private $jsyn;
29
30
    /**
31
     * @var string
32
     *
33
     * SQL Syntax to use for script generation
34
     */
35
    private $sqlSyntax;
36
37
    /**
38
     * @param $jsynFile string | PathUtil
39
     * @param $sqlSyntax string
40
     */
41
    public function __construct($jsynFile, $sqlSyntax)
42
    {
43
        self::setJsynFile($jsynFile);
44
        self::setSqlSyntax($sqlSyntax);
45
    }
46
47
    /**
48
     * @param $jsynFile string | PathUtil
49
     *
50
     * Setter function for the jsonFile global property
51
     *
52
     * @return void
53
     */
54
    public function setJsynFile($jsynFile)
55
    {
56
        $this->jsyn = json_decode(file_get_contents($jsynFile));
57
58
        if (isset($this->sqlSyntax)) {
59
            $sqlSyntax = $this->sqlSyntax;
60
<<<<<<< HEAD
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_SL
Loading history...
61
            if (!isset($this->jsyn->$sqlSyntax)) {
62
=======
63
            if (!isset($this->jsyn->$sqlSyntax)){
64
>>>>>>> 4842a8f3c157a08b4e970aaaefdcc71fbe6b6c13
65
                $sqlSyntax = "default";
66
            }
67
            $this->jsyn = $this->jsyn->$sqlSyntax;
68
        }
69
70
        return;
71
    }
72
73
    /**
74
     * @param $sqlSyntax string
75
     *
76
     * Setter function for the sqlSyntax global property
77
     *
78
     * @return void
79
     */
80
    public function setSqlSyntax($sqlSyntax)
81
    {
82
        $this->sqlSyntax = $sqlSyntax;
83
84
        if (isset($this->jsyn->$sqlSyntax)) {
85
            $this->jsyn = $this->jsyn->$sqlSyntax;
86
        } else {
87
            $sqlSyntax ="default";
88
            $this->jsyn = $this->jsyn->$sqlSyntax;
89
        }
90
        else {
91
            $sqlSyntax ="default";
92
            $this->jsyn = $this->jsyn->$sqlSyntax;
93
        }
94
95
        return;
96
    }
97
98
    /**
99
     * @return array
100
     */
101
    public function getJsyn()
102
    {
103
        return $this->jsyn;
104
    }
105
106
    /**
107
     * Performs extraction of the appropriate sql syntax
108
     * fromthe supplied jsyn file.
109
     *
110
     * @return void
111
     */
112
    public function formatJsyn()
113
    {
114
        for ($i = 0; $i < count($this->jsyn); ++$i) {
115
            if (strpos($this->jsyn[$i], '[') === 0 || strpos($this->jsyn[$i], '{') === (int) 0) {
116
                $this->jsyn[$i] = strtolower($this->jsyn[$i]);
117
            } else {
118
                $this->jsyn[$i] = strtoupper($this->jsyn[$i]);
119
            }
120
        }
121
122
        return;
123
    }
124
125
    /**
126
     * Returns the extracted jsyn as a string.
127
     *
128
     * @return string
129
     */
130
    public function __toString()
131
    {
132
        return implode(' ', $this->getJsyn());
133
    }
134
}
135