Passed
Branch master (7ff405)
by Adrian
01:44
created
src/Statements/QueryInsert.php 2 patches
Indentation   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -23,81 +23,81 @@
 block discarded – undo
23 23
 class QueryInsert extends QueryStatement implements QueryStatementInterface
24 24
 {
25 25
 
26
-    use Replacement, SetFields, Ignore, DefaultPriority, LowPriority, HighPriority, Utilities;
27
-
28
-    /**
29
-     * @var string
30
-     */
31
-    protected $statement = self::QUERY_STATEMENT_INSERT;
32
-
33
-
34
-    /**
35
-     * QueryInsert constructor.
36
-     * @param QueryBuild $queryBuild
37
-     * @param string $table
38
-     */
39
-    public function __construct(QueryBuild $queryBuild, $table = null)
40
-    {
41
-        parent::__construct($queryBuild, $table);
42
-    }
43
-
44
-    /**
45
-     * @return QueryInsertMultiple
46
-     */
47
-    public function multiple()
48
-    {
49
-        return new QueryInsertMultiple($this->queryBuild, $this->queryStructure->getElement(QueryStructure::TABLE));
50
-    }
51
-
52
-    /**
53
-     * @param bool|int $replacement
54
-     * @return mixed|string
55
-     */
56
-    public function getSyntax($replacement = self::REPLACEMENT_NONE)
57
-    {
58
-        $syntax = array();
59
-
60
-        /**
61
-         *  Explain
62
-         */
63
-        $syntax[] = $this->getExplainSyntax();
64
-
65
-        /**
66
-         * UPDATE statement
67
-         */
68
-        $syntax[] = $this->statement;
69
-
70
-        /**
71
-         * PRIORITY
72
-         */
73
-        $syntax[] = $this->queryStructure->getElement(QueryStructure::PRIORITY);
74
-
75
-        /**
76
-         * IGNORE clause
77
-         */
78
-        $syntax[] = $this->queryStructure->getElement(QueryStructure::IGNORE) ? 'IGNORE' : '';
79
-
80
-        /**
81
-         * INTO table
82
-         */
83
-        $syntax[] = 'INTO ' . $this->queryStructure->getElement(QueryStructure::TABLE);
84
-
85
-        /**
86
-         * FIELDS update
87
-         */
88
-        $syntax[] = $this->getSettingFieldsSyntax();
89
-
90
-        $syntax = implode(' ', $syntax);
91
-
92
-        return $this->getSyntaxReplace($syntax, $replacement);
93
-
94
-    }
95
-
96
-
97
-    public function execute()
98
-    {
99
-        return DbService::getInstance()->query($this->getSyntax(), $this->queryStructure->getElement(QueryStructure::BIND_PARAMS));
100
-    }
26
+	use Replacement, SetFields, Ignore, DefaultPriority, LowPriority, HighPriority, Utilities;
27
+
28
+	/**
29
+	 * @var string
30
+	 */
31
+	protected $statement = self::QUERY_STATEMENT_INSERT;
32
+
33
+
34
+	/**
35
+	 * QueryInsert constructor.
36
+	 * @param QueryBuild $queryBuild
37
+	 * @param string $table
38
+	 */
39
+	public function __construct(QueryBuild $queryBuild, $table = null)
40
+	{
41
+		parent::__construct($queryBuild, $table);
42
+	}
43
+
44
+	/**
45
+	 * @return QueryInsertMultiple
46
+	 */
47
+	public function multiple()
48
+	{
49
+		return new QueryInsertMultiple($this->queryBuild, $this->queryStructure->getElement(QueryStructure::TABLE));
50
+	}
51
+
52
+	/**
53
+	 * @param bool|int $replacement
54
+	 * @return mixed|string
55
+	 */
56
+	public function getSyntax($replacement = self::REPLACEMENT_NONE)
57
+	{
58
+		$syntax = array();
59
+
60
+		/**
61
+		 *  Explain
62
+		 */
63
+		$syntax[] = $this->getExplainSyntax();
64
+
65
+		/**
66
+		 * UPDATE statement
67
+		 */
68
+		$syntax[] = $this->statement;
69
+
70
+		/**
71
+		 * PRIORITY
72
+		 */
73
+		$syntax[] = $this->queryStructure->getElement(QueryStructure::PRIORITY);
74
+
75
+		/**
76
+		 * IGNORE clause
77
+		 */
78
+		$syntax[] = $this->queryStructure->getElement(QueryStructure::IGNORE) ? 'IGNORE' : '';
79
+
80
+		/**
81
+		 * INTO table
82
+		 */
83
+		$syntax[] = 'INTO ' . $this->queryStructure->getElement(QueryStructure::TABLE);
84
+
85
+		/**
86
+		 * FIELDS update
87
+		 */
88
+		$syntax[] = $this->getSettingFieldsSyntax();
89
+
90
+		$syntax = implode(' ', $syntax);
91
+
92
+		return $this->getSyntaxReplace($syntax, $replacement);
93
+
94
+	}
95
+
96
+
97
+	public function execute()
98
+	{
99
+		return DbService::getInstance()->query($this->getSyntax(), $this->queryStructure->getElement(QueryStructure::BIND_PARAMS));
100
+	}
101 101
 
102 102
 
103 103
 }
104 104
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -36,9 +36,9 @@  discard block
 block discarded – undo
36 36
      * @param QueryBuild $queryBuild
37 37
      * @param string $table
38 38
      */
39
-    public function __construct(QueryBuild $queryBuild, $table = null)
39
+    public function __construct( QueryBuild $queryBuild, $table = null )
40 40
     {
41
-        parent::__construct($queryBuild, $table);
41
+        parent::__construct( $queryBuild, $table );
42 42
     }
43 43
 
44 44
     /**
@@ -46,57 +46,57 @@  discard block
 block discarded – undo
46 46
      */
47 47
     public function multiple()
48 48
     {
49
-        return new QueryInsertMultiple($this->queryBuild, $this->queryStructure->getElement(QueryStructure::TABLE));
49
+        return new QueryInsertMultiple( $this->queryBuild, $this->queryStructure->getElement( QueryStructure::TABLE ) );
50 50
     }
51 51
 
52 52
     /**
53 53
      * @param bool|int $replacement
54 54
      * @return mixed|string
55 55
      */
56
-    public function getSyntax($replacement = self::REPLACEMENT_NONE)
56
+    public function getSyntax( $replacement = self::REPLACEMENT_NONE )
57 57
     {
58 58
         $syntax = array();
59 59
 
60 60
         /**
61 61
          *  Explain
62 62
          */
63
-        $syntax[] = $this->getExplainSyntax();
63
+        $syntax[ ] = $this->getExplainSyntax();
64 64
 
65 65
         /**
66 66
          * UPDATE statement
67 67
          */
68
-        $syntax[] = $this->statement;
68
+        $syntax[ ] = $this->statement;
69 69
 
70 70
         /**
71 71
          * PRIORITY
72 72
          */
73
-        $syntax[] = $this->queryStructure->getElement(QueryStructure::PRIORITY);
73
+        $syntax[ ] = $this->queryStructure->getElement( QueryStructure::PRIORITY );
74 74
 
75 75
         /**
76 76
          * IGNORE clause
77 77
          */
78
-        $syntax[] = $this->queryStructure->getElement(QueryStructure::IGNORE) ? 'IGNORE' : '';
78
+        $syntax[ ] = $this->queryStructure->getElement( QueryStructure::IGNORE ) ? 'IGNORE' : '';
79 79
 
80 80
         /**
81 81
          * INTO table
82 82
          */
83
-        $syntax[] = 'INTO ' . $this->queryStructure->getElement(QueryStructure::TABLE);
83
+        $syntax[ ] = 'INTO ' . $this->queryStructure->getElement( QueryStructure::TABLE );
84 84
 
85 85
         /**
86 86
          * FIELDS update
87 87
          */
88
-        $syntax[] = $this->getSettingFieldsSyntax();
88
+        $syntax[ ] = $this->getSettingFieldsSyntax();
89 89
 
90
-        $syntax = implode(' ', $syntax);
90
+        $syntax = implode( ' ', $syntax );
91 91
 
92
-        return $this->getSyntaxReplace($syntax, $replacement);
92
+        return $this->getSyntaxReplace( $syntax, $replacement );
93 93
 
94 94
     }
95 95
 
96 96
 
97 97
     public function execute()
98 98
     {
99
-        return DbService::getInstance()->query($this->getSyntax(), $this->queryStructure->getElement(QueryStructure::BIND_PARAMS));
99
+        return DbService::getInstance()->query( $this->getSyntax(), $this->queryStructure->getElement( QueryStructure::BIND_PARAMS ) );
100 100
     }
101 101
 
102 102
 
Please login to merge, or discard this patch.
src/Statements/QueryInsertMultiple.php 2 patches
Indentation   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -23,67 +23,67 @@
 block discarded – undo
23 23
 class QueryInsertMultiple extends QueryStatement implements QueryStatementInterface
24 24
 {
25 25
 
26
-    use InsertMultiple, Replacement, Ignore, DefaultPriority, LowPriority, HighPriority, Utilities;
27
-
28
-    /**
29
-     * @var string
30
-     */
31
-    protected $statement = self::QUERY_STATEMENT_INSERT;
32
-
33
-
34
-    /**
35
-     * QueryInsert constructor.
36
-     * @param QueryBuild $queryBuild
37
-     * @param string $table
38
-     */
39
-    public function __construct(QueryBuild $queryBuild, $table = null)
40
-    {
41
-        parent::__construct($queryBuild, $table);
42
-        $this->queryStructure->setElement(QueryStructure::FIELDS, array());
43
-    }
44
-
45
-    public function getSyntax($replacement = self::REPLACEMENT_NONE)
46
-    {
47
-        $syntax = array();
48
-
49
-        /**
50
-         *  Explain
51
-         */
52
-        $syntax[] = $this->getExplainSyntax();
53
-
54
-        /**
55
-         * UPDATE statement
56
-         */
57
-        $syntax[] = $this->statement;
58
-
59
-        /**
60
-         * PRIORITY
61
-         */
62
-        $syntax[] = $this->queryStructure->getElement(QueryStructure::PRIORITY);
63
-
64
-        /**
65
-         * IGNORE clause
66
-         */
67
-        $syntax[] = $this->queryStructure->getElement(QueryStructure::IGNORE) ? 'IGNORE' : '';
68
-
69
-        /**
70
-         * INTO table
71
-         */
72
-        $syntax[] = 'INTO ' . $this->queryStructure->getElement(QueryStructure::TABLE);
73
-
74
-        /**
75
-         * FIELDS update
76
-         */
77
-        $syntax[] = $this->getInsertMultipleRowsSyntax();
78
-
79
-        $syntax = implode(' ', $syntax);
80
-
81
-        return $this->getSyntaxReplace($syntax, $replacement);
82
-
83
-    }
84
-
85
-    public function execute()
86
-    {
87
-        return DbService::getInstance()->query($this->getSyntax(), $this->queryStructure->getElement(QueryStructure::BIND_PARAMS));
88
-    }
26
+	use InsertMultiple, Replacement, Ignore, DefaultPriority, LowPriority, HighPriority, Utilities;
27
+
28
+	/**
29
+	 * @var string
30
+	 */
31
+	protected $statement = self::QUERY_STATEMENT_INSERT;
32
+
33
+
34
+	/**
35
+	 * QueryInsert constructor.
36
+	 * @param QueryBuild $queryBuild
37
+	 * @param string $table
38
+	 */
39
+	public function __construct(QueryBuild $queryBuild, $table = null)
40
+	{
41
+		parent::__construct($queryBuild, $table);
42
+		$this->queryStructure->setElement(QueryStructure::FIELDS, array());
43
+	}
44
+
45
+	public function getSyntax($replacement = self::REPLACEMENT_NONE)
46
+	{
47
+		$syntax = array();
48
+
49
+		/**
50
+		 *  Explain
51
+		 */
52
+		$syntax[] = $this->getExplainSyntax();
53
+
54
+		/**
55
+		 * UPDATE statement
56
+		 */
57
+		$syntax[] = $this->statement;
58
+
59
+		/**
60
+		 * PRIORITY
61
+		 */
62
+		$syntax[] = $this->queryStructure->getElement(QueryStructure::PRIORITY);
63
+
64
+		/**
65
+		 * IGNORE clause
66
+		 */
67
+		$syntax[] = $this->queryStructure->getElement(QueryStructure::IGNORE) ? 'IGNORE' : '';
68
+
69
+		/**
70
+		 * INTO table
71
+		 */
72
+		$syntax[] = 'INTO ' . $this->queryStructure->getElement(QueryStructure::TABLE);
73
+
74
+		/**
75
+		 * FIELDS update
76
+		 */
77
+		$syntax[] = $this->getInsertMultipleRowsSyntax();
78
+
79
+		$syntax = implode(' ', $syntax);
80
+
81
+		return $this->getSyntaxReplace($syntax, $replacement);
82
+
83
+	}
84
+
85
+	public function execute()
86
+	{
87
+		return DbService::getInstance()->query($this->getSyntax(), $this->queryStructure->getElement(QueryStructure::BIND_PARAMS));
88
+	}
89 89
 }
90 90
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -36,54 +36,54 @@
 block discarded – undo
36 36
      * @param QueryBuild $queryBuild
37 37
      * @param string $table
38 38
      */
39
-    public function __construct(QueryBuild $queryBuild, $table = null)
39
+    public function __construct( QueryBuild $queryBuild, $table = null )
40 40
     {
41
-        parent::__construct($queryBuild, $table);
42
-        $this->queryStructure->setElement(QueryStructure::FIELDS, array());
41
+        parent::__construct( $queryBuild, $table );
42
+        $this->queryStructure->setElement( QueryStructure::FIELDS, array() );
43 43
     }
44 44
 
45
-    public function getSyntax($replacement = self::REPLACEMENT_NONE)
45
+    public function getSyntax( $replacement = self::REPLACEMENT_NONE )
46 46
     {
47 47
         $syntax = array();
48 48
 
49 49
         /**
50 50
          *  Explain
51 51
          */
52
-        $syntax[] = $this->getExplainSyntax();
52
+        $syntax[ ] = $this->getExplainSyntax();
53 53
 
54 54
         /**
55 55
          * UPDATE statement
56 56
          */
57
-        $syntax[] = $this->statement;
57
+        $syntax[ ] = $this->statement;
58 58
 
59 59
         /**
60 60
          * PRIORITY
61 61
          */
62
-        $syntax[] = $this->queryStructure->getElement(QueryStructure::PRIORITY);
62
+        $syntax[ ] = $this->queryStructure->getElement( QueryStructure::PRIORITY );
63 63
 
64 64
         /**
65 65
          * IGNORE clause
66 66
          */
67
-        $syntax[] = $this->queryStructure->getElement(QueryStructure::IGNORE) ? 'IGNORE' : '';
67
+        $syntax[ ] = $this->queryStructure->getElement( QueryStructure::IGNORE ) ? 'IGNORE' : '';
68 68
 
69 69
         /**
70 70
          * INTO table
71 71
          */
72
-        $syntax[] = 'INTO ' . $this->queryStructure->getElement(QueryStructure::TABLE);
72
+        $syntax[ ] = 'INTO ' . $this->queryStructure->getElement( QueryStructure::TABLE );
73 73
 
74 74
         /**
75 75
          * FIELDS update
76 76
          */
77
-        $syntax[] = $this->getInsertMultipleRowsSyntax();
77
+        $syntax[ ] = $this->getInsertMultipleRowsSyntax();
78 78
 
79
-        $syntax = implode(' ', $syntax);
79
+        $syntax = implode( ' ', $syntax );
80 80
 
81
-        return $this->getSyntaxReplace($syntax, $replacement);
81
+        return $this->getSyntaxReplace( $syntax, $replacement );
82 82
 
83 83
     }
84 84
 
85 85
     public function execute()
86 86
     {
87
-        return DbService::getInstance()->query($this->getSyntax(), $this->queryStructure->getElement(QueryStructure::BIND_PARAMS));
87
+        return DbService::getInstance()->query( $this->getSyntax(), $this->queryStructure->getElement( QueryStructure::BIND_PARAMS ) );
88 88
     }
89 89
 }
90 90
\ No newline at end of file
Please login to merge, or discard this patch.
src/Statements/QueryStatement.php 2 patches
Indentation   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -18,71 +18,71 @@
 block discarded – undo
18 18
 abstract class QueryStatement
19 19
 {
20 20
 
21
-    use Utilities, TableValidation, ColumnValidation;
22
-
23
-
24
-    /**
25
-     * Statements
26
-     */
27
-    const QUERY_STATEMENT_SELECT = 'SELECT';
28
-    const QUERY_STATEMENT_UPDATE = 'UPDATE';
29
-    const QUERY_STATEMENT_DELETE = 'DELETE';
30
-    const QUERY_STATEMENT_INSERT = 'INSERT';
31
-    const QUERY_STATEMENT_CUSTOM = 'CUSTOM';
32
-
33
-
34
-    /**
35
-     * @var string
36
-     */
37
-    protected $statement;
38
-
39
-    /**
40
-     * @var QueryBuild
41
-     */
42
-    protected $queryBuild;
43
-
44
-    /**
45
-     * @var QueryStructure
46
-     */
47
-    protected $queryStructure;
48
-
49
-    /**
50
-     * @var array
51
-     */
52
-    protected $usedInstanceIds = [];
53
-
54
-    /**
55
-     * @var string
56
-     */
57
-    protected $tablePrefix;
58
-
59
-
60
-    /**
61
-     * QueryStatement constructor.
62
-     * @param QueryBuild $queryBuild
63
-     * @param string|QuerySelect $table
64
-     * @throws QueryException
65
-     */
66
-    public function __construct(QueryBuild $queryBuild, $table = '')
67
-    {
68
-
69
-        $table = $this->validateTable($table);
70
-
71
-        $this->queryBuild = $queryBuild;
72
-        $this->queryStructure = new QueryStructure();
73
-        $this->queryStructure->setElement(QueryStructure::TABLE, $table);
74
-        $this->queryStructure->setElement(QueryStructure::STATEMENT, $this->statement);
75
-        $this->queryStructure->setElement(QueryStructure::QUERY_TYPE, $this->queryBuild->getType());
76
-
77
-    }
78
-
79
-    /**
80
-     * @return mixed
81
-     */
82
-    public function getBindParams()
83
-    {
84
-        return $this->queryStructure->getElement(QueryStructure::BIND_PARAMS);
85
-    }
21
+	use Utilities, TableValidation, ColumnValidation;
22
+
23
+
24
+	/**
25
+	 * Statements
26
+	 */
27
+	const QUERY_STATEMENT_SELECT = 'SELECT';
28
+	const QUERY_STATEMENT_UPDATE = 'UPDATE';
29
+	const QUERY_STATEMENT_DELETE = 'DELETE';
30
+	const QUERY_STATEMENT_INSERT = 'INSERT';
31
+	const QUERY_STATEMENT_CUSTOM = 'CUSTOM';
32
+
33
+
34
+	/**
35
+	 * @var string
36
+	 */
37
+	protected $statement;
38
+
39
+	/**
40
+	 * @var QueryBuild
41
+	 */
42
+	protected $queryBuild;
43
+
44
+	/**
45
+	 * @var QueryStructure
46
+	 */
47
+	protected $queryStructure;
48
+
49
+	/**
50
+	 * @var array
51
+	 */
52
+	protected $usedInstanceIds = [];
53
+
54
+	/**
55
+	 * @var string
56
+	 */
57
+	protected $tablePrefix;
58
+
59
+
60
+	/**
61
+	 * QueryStatement constructor.
62
+	 * @param QueryBuild $queryBuild
63
+	 * @param string|QuerySelect $table
64
+	 * @throws QueryException
65
+	 */
66
+	public function __construct(QueryBuild $queryBuild, $table = '')
67
+	{
68
+
69
+		$table = $this->validateTable($table);
70
+
71
+		$this->queryBuild = $queryBuild;
72
+		$this->queryStructure = new QueryStructure();
73
+		$this->queryStructure->setElement(QueryStructure::TABLE, $table);
74
+		$this->queryStructure->setElement(QueryStructure::STATEMENT, $this->statement);
75
+		$this->queryStructure->setElement(QueryStructure::QUERY_TYPE, $this->queryBuild->getType());
76
+
77
+	}
78
+
79
+	/**
80
+	 * @return mixed
81
+	 */
82
+	public function getBindParams()
83
+	{
84
+		return $this->queryStructure->getElement(QueryStructure::BIND_PARAMS);
85
+	}
86 86
 
87 87
 
88 88
 }
89 89
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
     /**
50 50
      * @var array
51 51
      */
52
-    protected $usedInstanceIds = [];
52
+    protected $usedInstanceIds = [ ];
53 53
 
54 54
     /**
55 55
      * @var string
@@ -63,16 +63,16 @@  discard block
 block discarded – undo
63 63
      * @param string|QuerySelect $table
64 64
      * @throws QueryException
65 65
      */
66
-    public function __construct(QueryBuild $queryBuild, $table = '')
66
+    public function __construct( QueryBuild $queryBuild, $table = '' )
67 67
     {
68 68
 
69
-        $table = $this->validateTable($table);
69
+        $table = $this->validateTable( $table );
70 70
 
71 71
         $this->queryBuild = $queryBuild;
72 72
         $this->queryStructure = new QueryStructure();
73
-        $this->queryStructure->setElement(QueryStructure::TABLE, $table);
74
-        $this->queryStructure->setElement(QueryStructure::STATEMENT, $this->statement);
75
-        $this->queryStructure->setElement(QueryStructure::QUERY_TYPE, $this->queryBuild->getType());
73
+        $this->queryStructure->setElement( QueryStructure::TABLE, $table );
74
+        $this->queryStructure->setElement( QueryStructure::STATEMENT, $this->statement );
75
+        $this->queryStructure->setElement( QueryStructure::QUERY_TYPE, $this->queryBuild->getType() );
76 76
 
77 77
     }
78 78
 
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
      */
82 82
     public function getBindParams()
83 83
     {
84
-        return $this->queryStructure->getElement(QueryStructure::BIND_PARAMS);
84
+        return $this->queryStructure->getElement( QueryStructure::BIND_PARAMS );
85 85
     }
86 86
 
87 87
 
Please login to merge, or discard this patch.
src/Statements/QueryStatementInterface.php 2 patches
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -11,17 +11,17 @@
 block discarded – undo
11 11
 interface QueryStatementInterface
12 12
 {
13 13
 
14
-    const REPLACEMENT_NONE = 0;
15
-    const REPLACEMENT_VALUES = 1;
14
+	const REPLACEMENT_NONE = 0;
15
+	const REPLACEMENT_VALUES = 1;
16 16
 
17
-    /**
18
-     * @param bool $replacement
19
-     * @return string
20
-     */
21
-    public function getSyntax($replacement = self::REPLACEMENT_NONE);
17
+	/**
18
+	 * @param bool $replacement
19
+	 * @return string
20
+	 */
21
+	public function getSyntax($replacement = self::REPLACEMENT_NONE);
22 22
 
23
-    public function execute();
23
+	public function execute();
24 24
 
25
-    public function getBindParams();
25
+	public function getBindParams();
26 26
 
27 27
 }
28 28
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@
 block discarded – undo
18 18
      * @param bool $replacement
19 19
      * @return string
20 20
      */
21
-    public function getSyntax($replacement = self::REPLACEMENT_NONE);
21
+    public function getSyntax( $replacement = self::REPLACEMENT_NONE );
22 22
 
23 23
     public function execute();
24 24
 
Please login to merge, or discard this patch.
src/Statements/QueryDelete.php 3 patches
Indentation   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -27,81 +27,81 @@
 block discarded – undo
27 27
 class QueryDelete extends QueryStatement implements QueryStatementInterface
28 28
 {
29 29
 
30
-    use Limit, Where, WhereAndHavingBuilder, Replacement, OrderBy, SetFields, Ignore, DefaultPriority, LowPriority, Utilities;
31
-
32
-    /**
33
-     * @var string
34
-     */
35
-    protected $statement = self::QUERY_STATEMENT_DELETE;
36
-
37
-
38
-    /**
39
-     * QueryDelete constructor.
40
-     * @param QueryBuild $queryBuild
41
-     * @param string $table
42
-     */
43
-    public function __construct(QueryBuild $queryBuild, $table = null)
44
-    {
45
-        parent::__construct($queryBuild, $table);
46
-    }
47
-
48
-    public function getSyntax($replacement = self::REPLACEMENT_NONE)
49
-    {
50
-        $syntax = array();
51
-
52
-        /**
53
-         *  Explain
54
-         */
55
-        $syntax[] = $this->getExplainSyntax();
56
-
57
-        /**
58
-         * UPDATE statement
59
-         */
60
-        $syntax[] = $this->statement;
61
-
62
-        /**
63
-         * PRIORITY
64
-         */
65
-        $syntax[] = $this->queryStructure->getElement(QueryStructure::PRIORITY);
66
-
67
-        /**
68
-         * TABLE update
69
-         */
70
-        $syntax[] = 'FROM ' . $this->queryStructure->getElement(QueryStructure::TABLE);
71
-
72
-        /**
73
-         * WHERE clause
74
-         */
75
-        $syntax[] = $this->getWhereSyntax();
76
-
77
-        /**
78
-         * ORDER BY clause
79
-         */
80
-        $syntax[] = $this->getOrderBySyntax();
81
-
82
-        /**
83
-         * LIMIT clause
84
-         */
85
-        $syntax[] = $this->getLimitSyntax();
86
-
87
-        $syntax = implode(' ', $syntax);
88
-
89
-        return $this->getSyntaxReplace($syntax, $replacement);
90
-    }
91
-
92
-    /**
93
-     * @return array|int|null
94
-     * @throws QueryException
95
-     */
96
-    public function execute()
97
-    {
98
-
99
-        if ($this->queryStructure->getElement((QueryStructure::WHERE_TRIGGER)) && !count($this->queryStructure->getElement(QueryStructure::WHERE)))
100
-            throw new QueryException('Where or Having clause is required for this statement!', QueryException::QUERY_ERROR_DELETE_NOT_FILTER);
101
-
102
-        return DbService::getInstance()->query($this->getSyntax(), $this->queryStructure->getElement(QueryStructure::BIND_PARAMS));
103
-
104
-    }
30
+	use Limit, Where, WhereAndHavingBuilder, Replacement, OrderBy, SetFields, Ignore, DefaultPriority, LowPriority, Utilities;
31
+
32
+	/**
33
+	 * @var string
34
+	 */
35
+	protected $statement = self::QUERY_STATEMENT_DELETE;
36
+
37
+
38
+	/**
39
+	 * QueryDelete constructor.
40
+	 * @param QueryBuild $queryBuild
41
+	 * @param string $table
42
+	 */
43
+	public function __construct(QueryBuild $queryBuild, $table = null)
44
+	{
45
+		parent::__construct($queryBuild, $table);
46
+	}
47
+
48
+	public function getSyntax($replacement = self::REPLACEMENT_NONE)
49
+	{
50
+		$syntax = array();
51
+
52
+		/**
53
+		 *  Explain
54
+		 */
55
+		$syntax[] = $this->getExplainSyntax();
56
+
57
+		/**
58
+		 * UPDATE statement
59
+		 */
60
+		$syntax[] = $this->statement;
61
+
62
+		/**
63
+		 * PRIORITY
64
+		 */
65
+		$syntax[] = $this->queryStructure->getElement(QueryStructure::PRIORITY);
66
+
67
+		/**
68
+		 * TABLE update
69
+		 */
70
+		$syntax[] = 'FROM ' . $this->queryStructure->getElement(QueryStructure::TABLE);
71
+
72
+		/**
73
+		 * WHERE clause
74
+		 */
75
+		$syntax[] = $this->getWhereSyntax();
76
+
77
+		/**
78
+		 * ORDER BY clause
79
+		 */
80
+		$syntax[] = $this->getOrderBySyntax();
81
+
82
+		/**
83
+		 * LIMIT clause
84
+		 */
85
+		$syntax[] = $this->getLimitSyntax();
86
+
87
+		$syntax = implode(' ', $syntax);
88
+
89
+		return $this->getSyntaxReplace($syntax, $replacement);
90
+	}
91
+
92
+	/**
93
+	 * @return array|int|null
94
+	 * @throws QueryException
95
+	 */
96
+	public function execute()
97
+	{
98
+
99
+		if ($this->queryStructure->getElement((QueryStructure::WHERE_TRIGGER)) && !count($this->queryStructure->getElement(QueryStructure::WHERE)))
100
+			throw new QueryException('Where or Having clause is required for this statement!', QueryException::QUERY_ERROR_DELETE_NOT_FILTER);
101
+
102
+		return DbService::getInstance()->query($this->getSyntax(), $this->queryStructure->getElement(QueryStructure::BIND_PARAMS));
103
+
104
+	}
105 105
 
106 106
 
107 107
 }
108 108
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -40,53 +40,53 @@  discard block
 block discarded – undo
40 40
      * @param QueryBuild $queryBuild
41 41
      * @param string $table
42 42
      */
43
-    public function __construct(QueryBuild $queryBuild, $table = null)
43
+    public function __construct( QueryBuild $queryBuild, $table = null )
44 44
     {
45
-        parent::__construct($queryBuild, $table);
45
+        parent::__construct( $queryBuild, $table );
46 46
     }
47 47
 
48
-    public function getSyntax($replacement = self::REPLACEMENT_NONE)
48
+    public function getSyntax( $replacement = self::REPLACEMENT_NONE )
49 49
     {
50 50
         $syntax = array();
51 51
 
52 52
         /**
53 53
          *  Explain
54 54
          */
55
-        $syntax[] = $this->getExplainSyntax();
55
+        $syntax[ ] = $this->getExplainSyntax();
56 56
 
57 57
         /**
58 58
          * UPDATE statement
59 59
          */
60
-        $syntax[] = $this->statement;
60
+        $syntax[ ] = $this->statement;
61 61
 
62 62
         /**
63 63
          * PRIORITY
64 64
          */
65
-        $syntax[] = $this->queryStructure->getElement(QueryStructure::PRIORITY);
65
+        $syntax[ ] = $this->queryStructure->getElement( QueryStructure::PRIORITY );
66 66
 
67 67
         /**
68 68
          * TABLE update
69 69
          */
70
-        $syntax[] = 'FROM ' . $this->queryStructure->getElement(QueryStructure::TABLE);
70
+        $syntax[ ] = 'FROM ' . $this->queryStructure->getElement( QueryStructure::TABLE );
71 71
 
72 72
         /**
73 73
          * WHERE clause
74 74
          */
75
-        $syntax[] = $this->getWhereSyntax();
75
+        $syntax[ ] = $this->getWhereSyntax();
76 76
 
77 77
         /**
78 78
          * ORDER BY clause
79 79
          */
80
-        $syntax[] = $this->getOrderBySyntax();
80
+        $syntax[ ] = $this->getOrderBySyntax();
81 81
 
82 82
         /**
83 83
          * LIMIT clause
84 84
          */
85
-        $syntax[] = $this->getLimitSyntax();
85
+        $syntax[ ] = $this->getLimitSyntax();
86 86
 
87
-        $syntax = implode(' ', $syntax);
87
+        $syntax = implode( ' ', $syntax );
88 88
 
89
-        return $this->getSyntaxReplace($syntax, $replacement);
89
+        return $this->getSyntaxReplace( $syntax, $replacement );
90 90
     }
91 91
 
92 92
     /**
@@ -96,10 +96,10 @@  discard block
 block discarded – undo
96 96
     public function execute()
97 97
     {
98 98
 
99
-        if ($this->queryStructure->getElement((QueryStructure::WHERE_TRIGGER)) && !count($this->queryStructure->getElement(QueryStructure::WHERE)))
100
-            throw new QueryException('Where or Having clause is required for this statement!', QueryException::QUERY_ERROR_DELETE_NOT_FILTER);
99
+        if ( $this->queryStructure->getElement( ( QueryStructure::WHERE_TRIGGER ) ) && !count( $this->queryStructure->getElement( QueryStructure::WHERE ) ) )
100
+            throw new QueryException( 'Where or Having clause is required for this statement!', QueryException::QUERY_ERROR_DELETE_NOT_FILTER );
101 101
 
102
-        return DbService::getInstance()->query($this->getSyntax(), $this->queryStructure->getElement(QueryStructure::BIND_PARAMS));
102
+        return DbService::getInstance()->query( $this->getSyntax(), $this->queryStructure->getElement( QueryStructure::BIND_PARAMS ) );
103 103
 
104 104
     }
105 105
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -96,8 +96,9 @@
 block discarded – undo
96 96
     public function execute()
97 97
     {
98 98
 
99
-        if ($this->queryStructure->getElement((QueryStructure::WHERE_TRIGGER)) && !count($this->queryStructure->getElement(QueryStructure::WHERE)))
100
-            throw new QueryException('Where or Having clause is required for this statement!', QueryException::QUERY_ERROR_DELETE_NOT_FILTER);
99
+        if ($this->queryStructure->getElement((QueryStructure::WHERE_TRIGGER)) && !count($this->queryStructure->getElement(QueryStructure::WHERE))) {
100
+                    throw new QueryException('Where or Having clause is required for this statement!', QueryException::QUERY_ERROR_DELETE_NOT_FILTER);
101
+        }
101 102
 
102 103
         return DbService::getInstance()->query($this->getSyntax(), $this->queryStructure->getElement(QueryStructure::BIND_PARAMS));
103 104
 
Please login to merge, or discard this patch.
src/DB/DbLog.php 2 patches
Indentation   +106 added lines, -106 removed lines patch added patch discarded remove patch
@@ -11,111 +11,111 @@
 block discarded – undo
11 11
 class DbLog
12 12
 {
13 13
 
14
-    private static $instance;
15
-
16
-
17
-    /**
18
-     * @var string
19
-     */
20
-    private $path;
21
-
22
-    /**
23
-     * @var \DateTimeZone
24
-     */
25
-    private $dateTimeZone;
26
-
27
-
28
-    /**
29
-     * DbLog constructor.
30
-     */
31
-    private function __construct()
32
-    {
33
-        $this->dateTimeZone = new \DateTimeZone('Europe/Bucharest');
34
-    }
35
-
36
-
37
-    /**
38
-     * @param $query
39
-     * @param $duration
40
-     */
41
-    public function writeQueryDuration($query, $duration)
42
-    {
43
-        $backtrace = end(debug_backtrace());
44
-        $location = $backtrace['file'] . " Line: " . $backtrace['line'];
45
-
46
-        $this->path = DbConfig::getInstance()->getLogPathQueryDuration(); //my comments
47
-        $message = "Duration: " . round($duration, 5) . "\r\n";
48
-        $message .= "Location: $location\r\n";
49
-        $message .= "Query: $query";
50
-        $this->write($message);
51
-    }
52
-
53
-    /**
54
-     * @param $query
55
-     * @param $duration
56
-     */
57
-    public function writeQueryErros($query, $code, $error)
58
-    {
59
-        $backtrace = end(debug_backtrace());
60
-        $location = $backtrace['file'] . " Line: " . $backtrace['line'];
61
-
62
-        $this->path = DbConfig::getInstance()->getLogPathErrors(); //my comments
63
-        $message = "Query: $query" . "\r\n";
64
-        $message .= "Location: $location\r\n";
65
-        $message .= "Error code : " . $code . "\r\n";
66
-        $message .= "" . $error;
67
-
68
-        $this->write($message);
69
-    }
70
-
71
-
72
-    public function write($message)
73
-    {
74
-
75
-        $date = new \DateTime();
76
-        $date->setTimezone($this->dateTimeZone);
77
-
78
-        $log = $this->path . $date->format('Y-m-d') . ".txt";
79
-        $time = $date->format('H:i:s');
80
-
81
-        $messageFormat = "[$time]\r\n$message\r\n\r\n";
82
-
83
-        if (is_dir($this->path)) {
84
-            if (!file_exists($log)) {
85
-                $fh = fopen($log, 'a+');
86
-                fwrite($fh, $messageFormat);
87
-                fclose($fh);
88
-            } else {
89
-                $this->edit($log, $messageFormat);
90
-            }
91
-        } else {
92
-            if (mkdir($this->path, 0777) === true) {
93
-                $this->write($message);
94
-            }
95
-        }
96
-    }
97
-
98
-
99
-    /**
100
-     * @param string $log
101
-     * @param  string $message
102
-     */
103
-    private function edit($log, $message)
104
-    {
105
-        file_put_contents($log, $message, FILE_APPEND);
106
-    }
107
-
108
-
109
-    /**
110
-     * @return DbLog
111
-     */
112
-    public static function getInstance()
113
-    {
114
-        if (null === self::$instance) {
115
-            self::$instance = new self();
116
-        }
117
-
118
-        return self::$instance;
119
-    }
14
+	private static $instance;
15
+
16
+
17
+	/**
18
+	 * @var string
19
+	 */
20
+	private $path;
21
+
22
+	/**
23
+	 * @var \DateTimeZone
24
+	 */
25
+	private $dateTimeZone;
26
+
27
+
28
+	/**
29
+	 * DbLog constructor.
30
+	 */
31
+	private function __construct()
32
+	{
33
+		$this->dateTimeZone = new \DateTimeZone('Europe/Bucharest');
34
+	}
35
+
36
+
37
+	/**
38
+	 * @param $query
39
+	 * @param $duration
40
+	 */
41
+	public function writeQueryDuration($query, $duration)
42
+	{
43
+		$backtrace = end(debug_backtrace());
44
+		$location = $backtrace['file'] . " Line: " . $backtrace['line'];
45
+
46
+		$this->path = DbConfig::getInstance()->getLogPathQueryDuration(); //my comments
47
+		$message = "Duration: " . round($duration, 5) . "\r\n";
48
+		$message .= "Location: $location\r\n";
49
+		$message .= "Query: $query";
50
+		$this->write($message);
51
+	}
52
+
53
+	/**
54
+	 * @param $query
55
+	 * @param $duration
56
+	 */
57
+	public function writeQueryErros($query, $code, $error)
58
+	{
59
+		$backtrace = end(debug_backtrace());
60
+		$location = $backtrace['file'] . " Line: " . $backtrace['line'];
61
+
62
+		$this->path = DbConfig::getInstance()->getLogPathErrors(); //my comments
63
+		$message = "Query: $query" . "\r\n";
64
+		$message .= "Location: $location\r\n";
65
+		$message .= "Error code : " . $code . "\r\n";
66
+		$message .= "" . $error;
67
+
68
+		$this->write($message);
69
+	}
70
+
71
+
72
+	public function write($message)
73
+	{
74
+
75
+		$date = new \DateTime();
76
+		$date->setTimezone($this->dateTimeZone);
77
+
78
+		$log = $this->path . $date->format('Y-m-d') . ".txt";
79
+		$time = $date->format('H:i:s');
80
+
81
+		$messageFormat = "[$time]\r\n$message\r\n\r\n";
82
+
83
+		if (is_dir($this->path)) {
84
+			if (!file_exists($log)) {
85
+				$fh = fopen($log, 'a+');
86
+				fwrite($fh, $messageFormat);
87
+				fclose($fh);
88
+			} else {
89
+				$this->edit($log, $messageFormat);
90
+			}
91
+		} else {
92
+			if (mkdir($this->path, 0777) === true) {
93
+				$this->write($message);
94
+			}
95
+		}
96
+	}
97
+
98
+
99
+	/**
100
+	 * @param string $log
101
+	 * @param  string $message
102
+	 */
103
+	private function edit($log, $message)
104
+	{
105
+		file_put_contents($log, $message, FILE_APPEND);
106
+	}
107
+
108
+
109
+	/**
110
+	 * @return DbLog
111
+	 */
112
+	public static function getInstance()
113
+	{
114
+		if (null === self::$instance) {
115
+			self::$instance = new self();
116
+		}
117
+
118
+		return self::$instance;
119
+	}
120 120
 
121 121
 }
122 122
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
      */
31 31
     private function __construct()
32 32
     {
33
-        $this->dateTimeZone = new \DateTimeZone('Europe/Bucharest');
33
+        $this->dateTimeZone = new \DateTimeZone( 'Europe/Bucharest' );
34 34
     }
35 35
 
36 36
 
@@ -38,26 +38,26 @@  discard block
 block discarded – undo
38 38
      * @param $query
39 39
      * @param $duration
40 40
      */
41
-    public function writeQueryDuration($query, $duration)
41
+    public function writeQueryDuration( $query, $duration )
42 42
     {
43
-        $backtrace = end(debug_backtrace());
44
-        $location = $backtrace['file'] . " Line: " . $backtrace['line'];
43
+        $backtrace = end( debug_backtrace() );
44
+        $location = $backtrace[ 'file' ] . " Line: " . $backtrace[ 'line' ];
45 45
 
46 46
         $this->path = DbConfig::getInstance()->getLogPathQueryDuration(); //my comments
47
-        $message = "Duration: " . round($duration, 5) . "\r\n";
47
+        $message = "Duration: " . round( $duration, 5 ) . "\r\n";
48 48
         $message .= "Location: $location\r\n";
49 49
         $message .= "Query: $query";
50
-        $this->write($message);
50
+        $this->write( $message );
51 51
     }
52 52
 
53 53
     /**
54 54
      * @param $query
55 55
      * @param $duration
56 56
      */
57
-    public function writeQueryErros($query, $code, $error)
57
+    public function writeQueryErros( $query, $code, $error )
58 58
     {
59
-        $backtrace = end(debug_backtrace());
60
-        $location = $backtrace['file'] . " Line: " . $backtrace['line'];
59
+        $backtrace = end( debug_backtrace() );
60
+        $location = $backtrace[ 'file' ] . " Line: " . $backtrace[ 'line' ];
61 61
 
62 62
         $this->path = DbConfig::getInstance()->getLogPathErrors(); //my comments
63 63
         $message = "Query: $query" . "\r\n";
@@ -65,32 +65,32 @@  discard block
 block discarded – undo
65 65
         $message .= "Error code : " . $code . "\r\n";
66 66
         $message .= "" . $error;
67 67
 
68
-        $this->write($message);
68
+        $this->write( $message );
69 69
     }
70 70
 
71 71
 
72
-    public function write($message)
72
+    public function write( $message )
73 73
     {
74 74
 
75 75
         $date = new \DateTime();
76
-        $date->setTimezone($this->dateTimeZone);
76
+        $date->setTimezone( $this->dateTimeZone );
77 77
 
78
-        $log = $this->path . $date->format('Y-m-d') . ".txt";
79
-        $time = $date->format('H:i:s');
78
+        $log = $this->path . $date->format( 'Y-m-d' ) . ".txt";
79
+        $time = $date->format( 'H:i:s' );
80 80
 
81 81
         $messageFormat = "[$time]\r\n$message\r\n\r\n";
82 82
 
83
-        if (is_dir($this->path)) {
84
-            if (!file_exists($log)) {
85
-                $fh = fopen($log, 'a+');
86
-                fwrite($fh, $messageFormat);
87
-                fclose($fh);
83
+        if ( is_dir( $this->path ) ) {
84
+            if ( !file_exists( $log ) ) {
85
+                $fh = fopen( $log, 'a+' );
86
+                fwrite( $fh, $messageFormat );
87
+                fclose( $fh );
88 88
             } else {
89
-                $this->edit($log, $messageFormat);
89
+                $this->edit( $log, $messageFormat );
90 90
             }
91 91
         } else {
92
-            if (mkdir($this->path, 0777) === true) {
93
-                $this->write($message);
92
+            if ( mkdir( $this->path, 0777 ) === true ) {
93
+                $this->write( $message );
94 94
             }
95 95
         }
96 96
     }
@@ -100,9 +100,9 @@  discard block
 block discarded – undo
100 100
      * @param string $log
101 101
      * @param  string $message
102 102
      */
103
-    private function edit($log, $message)
103
+    private function edit( $log, $message )
104 104
     {
105
-        file_put_contents($log, $message, FILE_APPEND);
105
+        file_put_contents( $log, $message, FILE_APPEND );
106 106
     }
107 107
 
108 108
 
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
      */
112 112
     public static function getInstance()
113 113
     {
114
-        if (null === self::$instance) {
114
+        if ( null === self::$instance ) {
115 115
             self::$instance = new self();
116 116
         }
117 117
 
Please login to merge, or discard this patch.
src/DB/DbService.php 3 patches
Indentation   +246 added lines, -246 removed lines patch added patch discarded remove patch
@@ -11,251 +11,251 @@
 block discarded – undo
11 11
 class DbService
12 12
 {
13 13
 
14
-    const QUERY_TYPE_INSERT = 'INSERT';
15
-    const QUERY_TYPE_DELETE = 'DELETE';
16
-    const QUERY_TYPE_UPDATE = 'UPDATE';
17
-    const QUERY_TYPE_SELECT = 'SELECT';
18
-    const QUERY_TYPE_REPLACE = 'REPLACE';
19
-    const QUERY_TYPE_SHOW = 'SHOW';
20
-    const QUERY_TYPE_DESC = 'DESC';
21
-    const QUERY_TYPE_EMPTY = 'EMPTY';
22
-    const QUERY_TYPE_OTHER = 'OTHER';
23
-    const QUERY_TYPE_EXPLAIN = 'EXPLAIN';
24
-
25
-    const ON_ERROR_THROW_EXCEPTION = 1;
26
-    const ON_ERROR_RETURN_ERROR = 2;
27
-
28
-    /**
29
-     * @var DbService
30
-     */
31
-    private static $instance;
32
-
33
-    /**
34
-     * @var \PDO
35
-     */
36
-    private $pdo;
37
-
38
-    /**
39
-     * @var \PDOStatement
40
-     */
41
-    private $sQuery;
42
-
43
-    /**
44
-     * @var array
45
-     */
46
-    private $parameters = [];
47
-
48
-    /**
49
-     * @return DbService
50
-     */
51
-    public static function getInstance()
52
-    {
53
-        if (null === self::$instance) {
54
-            self::$instance = new self();
55
-        }
56
-
57
-        return self::$instance;
58
-    }
59
-
60
-    /**
61
-     * @param string $query
62
-     * @param array $params
63
-     * @param int $fetchMode
64
-     * @return array|int|null
65
-     */
66
-    public function query($query, $params = null, $fetchMode = \PDO::FETCH_ASSOC)
67
-    {
68
-
69
-        $query = trim(str_replace("\r", " ", $query));
70
-        $statement = self::getQueryStatement($query);
71
-
72
-        $this->queryInit($query, $params);
73
-
74
-        if ($statement === self::QUERY_TYPE_SELECT || $statement === self::QUERY_TYPE_SHOW || $statement === self::QUERY_TYPE_DESC || $statement === self::QUERY_TYPE_EXPLAIN) {
75
-            return $this->sQuery->fetchAll($fetchMode);
76
-        } elseif ($statement === self::QUERY_TYPE_INSERT || $statement === self::QUERY_TYPE_UPDATE || $statement === self::QUERY_TYPE_DELETE) {
77
-            return $this->sQuery->rowCount();
78
-        } else {
79
-
80
-            return NULL;
81
-        }
82
-    }
83
-
84
-    /**
85
-     * @param $queryString
86
-     * @return string
87
-     */
88
-    public static function getQueryStatement($queryString)
89
-    {
90
-        $queryString = trim($queryString);
91
-
92
-        if ($queryString === '') {
93
-            return self::QUERY_TYPE_EMPTY;
94
-        }
95
-
96
-        if (preg_match('/^(select|insert|update|delete|replace|show|desc|explain)[\s]+/i', $queryString, $matches)) {
97
-            switch (strtolower($matches[1])) {
98
-                case 'select':
99
-                    return self::QUERY_TYPE_SELECT;
100
-                case 'insert':
101
-                    return self::QUERY_TYPE_INSERT;
102
-                case 'update':
103
-                    return self::QUERY_TYPE_UPDATE;
104
-                case 'delete':
105
-                    return self::QUERY_TYPE_DELETE;
106
-                case 'replace':
107
-                    return self::QUERY_TYPE_REPLACE;
108
-                case 'explain':
109
-                    return self::QUERY_TYPE_EXPLAIN;
110
-                default:
111
-                    return self::QUERY_TYPE_OTHER;
112
-            }
113
-        } else {
114
-            return self::QUERY_TYPE_OTHER;
115
-        }
116
-    }
117
-
118
-    /**
119
-     * @param $query
120
-     * @param array $parameters
121
-     * @throws DbException
122
-     */
123
-    private function queryInit($query, $parameters = [])
124
-    {
125
-        $this->pdo = DbConnect::getInstance()->getConnection(self::getQueryStatement($query));
126
-        $startQueryTime = microtime(true);
127
-
128
-        try {
129
-
130
-            /**
131
-             * Prepare query
132
-             */
133
-            $this->sQuery = $this->pdo->prepare($query);
134
-
135
-            /**
136
-             * Add parameters to the parameter array
137
-             */
138
-            if (self::isArrayAssoc($parameters))
139
-                $this->bindMore($parameters); else
140
-                foreach ($parameters as $key => $val)
141
-                    $this->parameters[] = array($key + 1, $val);
142
-
143
-            if (count($this->parameters)) {
144
-                foreach ($this->parameters as $param => $value) {
145
-                    if (is_int($value[1])) {
146
-                        $type = \PDO::PARAM_INT;
147
-                    } elseif (is_bool($value[1])) {
148
-                        $type = \PDO::PARAM_BOOL;
149
-                    } elseif (is_null($value[1])) {
150
-                        $type = \PDO::PARAM_NULL;
151
-                    } else {
152
-                        $type = \PDO::PARAM_STR;
153
-                    }
154
-                    $this->sQuery->bindValue($value[0], $value[1], $type);
155
-                }
156
-            }
157
-
158
-            $this->sQuery->execute();
159
-
160
-            if (DbConfig::getInstance()->isEnableLogQueryDuration()) {
161
-                $duration = microtime(true) - $startQueryTime;
162
-                DbLog::getInstance()->writeQueryDuration($query, $duration);
163
-            }
164
-
165
-        } catch (\PDOException $e) {
166
-            if (DbConfig::getInstance()->isEnableLogErrors()) {
167
-                DbLog::getInstance()->writeQueryErros($query, $e->getCode(), $e->getMessage());
168
-            }
169
-            throw new DbException('Database error!', DbException::DB_QUERY_ERROR);
170
-        }
171
-
172
-        /**
173
-         * Reset the parameters
174
-         */
175
-        $this->parameters = array();
176
-    }
177
-
178
-    /**
179
-     * @param array $arr
180
-     * @return bool
181
-     */
182
-    public static function isArrayAssoc(array $arr)
183
-    {
184
-        if (array() === $arr)
185
-            return false;
186
-
187
-        return array_keys($arr) !== range(0, count($arr) - 1);
188
-    }
189
-
190
-    public function bindMore($parray)
191
-    {
192
-        if (!count($this->parameters) && is_array($parray)) {
193
-            $columns = array_keys($parray);
194
-            foreach ($columns as $i => &$column) {
195
-                $this->bind($column, $parray[ $column ]);
196
-            }
197
-        }
198
-    }
199
-
200
-    public function bind($para, $value)
201
-    {
202
-        $this->parameters[ sizeof($this->parameters) ] = [":" . $para, $value];
203
-    }
204
-
205
-    /**
206
-     * @param $query
207
-     * @param array $params
208
-     * @return array|null
209
-     */
210
-    public function column($query, $params = null)
211
-    {
212
-        $this->queryInit($query, $params);
213
-
214
-        $query = trim(str_replace("\r", " ", $query));
215
-        $statement = self::getQueryStatement($query);
216
-
217
-        if ($statement === self::QUERY_TYPE_EXPLAIN)
218
-            return $this->sQuery->fetchAll(\PDO::FETCH_ASSOC);
219
-
220
-        $Columns = $this->sQuery->fetchAll(\PDO::FETCH_NUM);
221
-
222
-        $column = null;
223
-
224
-        foreach ($Columns as $cells) {
225
-            $column[] = $cells[0];
226
-        }
227
-
228
-        return $column;
229
-    }
230
-
231
-    public function row($query, $params = null, $fetchmode = \PDO::FETCH_ASSOC)
232
-    {
233
-        $this->queryInit($query, $params);
234
-
235
-        $query = trim(str_replace("\r", " ", $query));
236
-        $statement = self::getQueryStatement($query);
237
-
238
-        if ($statement === self::QUERY_TYPE_EXPLAIN)
239
-            return $this->sQuery->fetchAll(\PDO::FETCH_ASSOC);
240
-
241
-        $result = $this->sQuery->fetch($fetchmode);
242
-        $this->sQuery->closeCursor(); // Frees up the connection to the server so that other SQL statements may be issued,
243
-
244
-        return $result;
245
-    }
246
-
247
-    public function single($query, $params = null)
248
-    {
249
-        $this->queryInit($query, $params);
250
-        $result = $this->sQuery->fetchColumn();
251
-        $this->sQuery->closeCursor(); // Frees up the connection to the server so that other SQL statements may be issued
252
-
253
-        return $result;
254
-    }
255
-
256
-    public function CloseConnection()
257
-    {
258
-        $this->pdo = null;
259
-    }
14
+	const QUERY_TYPE_INSERT = 'INSERT';
15
+	const QUERY_TYPE_DELETE = 'DELETE';
16
+	const QUERY_TYPE_UPDATE = 'UPDATE';
17
+	const QUERY_TYPE_SELECT = 'SELECT';
18
+	const QUERY_TYPE_REPLACE = 'REPLACE';
19
+	const QUERY_TYPE_SHOW = 'SHOW';
20
+	const QUERY_TYPE_DESC = 'DESC';
21
+	const QUERY_TYPE_EMPTY = 'EMPTY';
22
+	const QUERY_TYPE_OTHER = 'OTHER';
23
+	const QUERY_TYPE_EXPLAIN = 'EXPLAIN';
24
+
25
+	const ON_ERROR_THROW_EXCEPTION = 1;
26
+	const ON_ERROR_RETURN_ERROR = 2;
27
+
28
+	/**
29
+	 * @var DbService
30
+	 */
31
+	private static $instance;
32
+
33
+	/**
34
+	 * @var \PDO
35
+	 */
36
+	private $pdo;
37
+
38
+	/**
39
+	 * @var \PDOStatement
40
+	 */
41
+	private $sQuery;
42
+
43
+	/**
44
+	 * @var array
45
+	 */
46
+	private $parameters = [];
47
+
48
+	/**
49
+	 * @return DbService
50
+	 */
51
+	public static function getInstance()
52
+	{
53
+		if (null === self::$instance) {
54
+			self::$instance = new self();
55
+		}
56
+
57
+		return self::$instance;
58
+	}
59
+
60
+	/**
61
+	 * @param string $query
62
+	 * @param array $params
63
+	 * @param int $fetchMode
64
+	 * @return array|int|null
65
+	 */
66
+	public function query($query, $params = null, $fetchMode = \PDO::FETCH_ASSOC)
67
+	{
68
+
69
+		$query = trim(str_replace("\r", " ", $query));
70
+		$statement = self::getQueryStatement($query);
71
+
72
+		$this->queryInit($query, $params);
73
+
74
+		if ($statement === self::QUERY_TYPE_SELECT || $statement === self::QUERY_TYPE_SHOW || $statement === self::QUERY_TYPE_DESC || $statement === self::QUERY_TYPE_EXPLAIN) {
75
+			return $this->sQuery->fetchAll($fetchMode);
76
+		} elseif ($statement === self::QUERY_TYPE_INSERT || $statement === self::QUERY_TYPE_UPDATE || $statement === self::QUERY_TYPE_DELETE) {
77
+			return $this->sQuery->rowCount();
78
+		} else {
79
+
80
+			return NULL;
81
+		}
82
+	}
83
+
84
+	/**
85
+	 * @param $queryString
86
+	 * @return string
87
+	 */
88
+	public static function getQueryStatement($queryString)
89
+	{
90
+		$queryString = trim($queryString);
91
+
92
+		if ($queryString === '') {
93
+			return self::QUERY_TYPE_EMPTY;
94
+		}
95
+
96
+		if (preg_match('/^(select|insert|update|delete|replace|show|desc|explain)[\s]+/i', $queryString, $matches)) {
97
+			switch (strtolower($matches[1])) {
98
+				case 'select':
99
+					return self::QUERY_TYPE_SELECT;
100
+				case 'insert':
101
+					return self::QUERY_TYPE_INSERT;
102
+				case 'update':
103
+					return self::QUERY_TYPE_UPDATE;
104
+				case 'delete':
105
+					return self::QUERY_TYPE_DELETE;
106
+				case 'replace':
107
+					return self::QUERY_TYPE_REPLACE;
108
+				case 'explain':
109
+					return self::QUERY_TYPE_EXPLAIN;
110
+				default:
111
+					return self::QUERY_TYPE_OTHER;
112
+			}
113
+		} else {
114
+			return self::QUERY_TYPE_OTHER;
115
+		}
116
+	}
117
+
118
+	/**
119
+	 * @param $query
120
+	 * @param array $parameters
121
+	 * @throws DbException
122
+	 */
123
+	private function queryInit($query, $parameters = [])
124
+	{
125
+		$this->pdo = DbConnect::getInstance()->getConnection(self::getQueryStatement($query));
126
+		$startQueryTime = microtime(true);
127
+
128
+		try {
129
+
130
+			/**
131
+			 * Prepare query
132
+			 */
133
+			$this->sQuery = $this->pdo->prepare($query);
134
+
135
+			/**
136
+			 * Add parameters to the parameter array
137
+			 */
138
+			if (self::isArrayAssoc($parameters))
139
+				$this->bindMore($parameters); else
140
+				foreach ($parameters as $key => $val)
141
+					$this->parameters[] = array($key + 1, $val);
142
+
143
+			if (count($this->parameters)) {
144
+				foreach ($this->parameters as $param => $value) {
145
+					if (is_int($value[1])) {
146
+						$type = \PDO::PARAM_INT;
147
+					} elseif (is_bool($value[1])) {
148
+						$type = \PDO::PARAM_BOOL;
149
+					} elseif (is_null($value[1])) {
150
+						$type = \PDO::PARAM_NULL;
151
+					} else {
152
+						$type = \PDO::PARAM_STR;
153
+					}
154
+					$this->sQuery->bindValue($value[0], $value[1], $type);
155
+				}
156
+			}
157
+
158
+			$this->sQuery->execute();
159
+
160
+			if (DbConfig::getInstance()->isEnableLogQueryDuration()) {
161
+				$duration = microtime(true) - $startQueryTime;
162
+				DbLog::getInstance()->writeQueryDuration($query, $duration);
163
+			}
164
+
165
+		} catch (\PDOException $e) {
166
+			if (DbConfig::getInstance()->isEnableLogErrors()) {
167
+				DbLog::getInstance()->writeQueryErros($query, $e->getCode(), $e->getMessage());
168
+			}
169
+			throw new DbException('Database error!', DbException::DB_QUERY_ERROR);
170
+		}
171
+
172
+		/**
173
+		 * Reset the parameters
174
+		 */
175
+		$this->parameters = array();
176
+	}
177
+
178
+	/**
179
+	 * @param array $arr
180
+	 * @return bool
181
+	 */
182
+	public static function isArrayAssoc(array $arr)
183
+	{
184
+		if (array() === $arr)
185
+			return false;
186
+
187
+		return array_keys($arr) !== range(0, count($arr) - 1);
188
+	}
189
+
190
+	public function bindMore($parray)
191
+	{
192
+		if (!count($this->parameters) && is_array($parray)) {
193
+			$columns = array_keys($parray);
194
+			foreach ($columns as $i => &$column) {
195
+				$this->bind($column, $parray[ $column ]);
196
+			}
197
+		}
198
+	}
199
+
200
+	public function bind($para, $value)
201
+	{
202
+		$this->parameters[ sizeof($this->parameters) ] = [":" . $para, $value];
203
+	}
204
+
205
+	/**
206
+	 * @param $query
207
+	 * @param array $params
208
+	 * @return array|null
209
+	 */
210
+	public function column($query, $params = null)
211
+	{
212
+		$this->queryInit($query, $params);
213
+
214
+		$query = trim(str_replace("\r", " ", $query));
215
+		$statement = self::getQueryStatement($query);
216
+
217
+		if ($statement === self::QUERY_TYPE_EXPLAIN)
218
+			return $this->sQuery->fetchAll(\PDO::FETCH_ASSOC);
219
+
220
+		$Columns = $this->sQuery->fetchAll(\PDO::FETCH_NUM);
221
+
222
+		$column = null;
223
+
224
+		foreach ($Columns as $cells) {
225
+			$column[] = $cells[0];
226
+		}
227
+
228
+		return $column;
229
+	}
230
+
231
+	public function row($query, $params = null, $fetchmode = \PDO::FETCH_ASSOC)
232
+	{
233
+		$this->queryInit($query, $params);
234
+
235
+		$query = trim(str_replace("\r", " ", $query));
236
+		$statement = self::getQueryStatement($query);
237
+
238
+		if ($statement === self::QUERY_TYPE_EXPLAIN)
239
+			return $this->sQuery->fetchAll(\PDO::FETCH_ASSOC);
240
+
241
+		$result = $this->sQuery->fetch($fetchmode);
242
+		$this->sQuery->closeCursor(); // Frees up the connection to the server so that other SQL statements may be issued,
243
+
244
+		return $result;
245
+	}
246
+
247
+	public function single($query, $params = null)
248
+	{
249
+		$this->queryInit($query, $params);
250
+		$result = $this->sQuery->fetchColumn();
251
+		$this->sQuery->closeCursor(); // Frees up the connection to the server so that other SQL statements may be issued
252
+
253
+		return $result;
254
+	}
255
+
256
+	public function CloseConnection()
257
+	{
258
+		$this->pdo = null;
259
+	}
260 260
 
261 261
 }
262 262
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -43,14 +43,14 @@  discard block
 block discarded – undo
43 43
     /**
44 44
      * @var array
45 45
      */
46
-    private $parameters = [];
46
+    private $parameters = [ ];
47 47
 
48 48
     /**
49 49
      * @return DbService
50 50
      */
51 51
     public static function getInstance()
52 52
     {
53
-        if (null === self::$instance) {
53
+        if ( null === self::$instance ) {
54 54
             self::$instance = new self();
55 55
         }
56 56
 
@@ -63,17 +63,17 @@  discard block
 block discarded – undo
63 63
      * @param int $fetchMode
64 64
      * @return array|int|null
65 65
      */
66
-    public function query($query, $params = null, $fetchMode = \PDO::FETCH_ASSOC)
66
+    public function query( $query, $params = null, $fetchMode = \PDO::FETCH_ASSOC )
67 67
     {
68 68
 
69
-        $query = trim(str_replace("\r", " ", $query));
70
-        $statement = self::getQueryStatement($query);
69
+        $query = trim( str_replace( "\r", " ", $query ) );
70
+        $statement = self::getQueryStatement( $query );
71 71
 
72
-        $this->queryInit($query, $params);
72
+        $this->queryInit( $query, $params );
73 73
 
74
-        if ($statement === self::QUERY_TYPE_SELECT || $statement === self::QUERY_TYPE_SHOW || $statement === self::QUERY_TYPE_DESC || $statement === self::QUERY_TYPE_EXPLAIN) {
75
-            return $this->sQuery->fetchAll($fetchMode);
76
-        } elseif ($statement === self::QUERY_TYPE_INSERT || $statement === self::QUERY_TYPE_UPDATE || $statement === self::QUERY_TYPE_DELETE) {
74
+        if ( $statement === self::QUERY_TYPE_SELECT || $statement === self::QUERY_TYPE_SHOW || $statement === self::QUERY_TYPE_DESC || $statement === self::QUERY_TYPE_EXPLAIN ) {
75
+            return $this->sQuery->fetchAll( $fetchMode );
76
+        } elseif ( $statement === self::QUERY_TYPE_INSERT || $statement === self::QUERY_TYPE_UPDATE || $statement === self::QUERY_TYPE_DELETE ) {
77 77
             return $this->sQuery->rowCount();
78 78
         } else {
79 79
 
@@ -85,16 +85,16 @@  discard block
 block discarded – undo
85 85
      * @param $queryString
86 86
      * @return string
87 87
      */
88
-    public static function getQueryStatement($queryString)
88
+    public static function getQueryStatement( $queryString )
89 89
     {
90
-        $queryString = trim($queryString);
90
+        $queryString = trim( $queryString );
91 91
 
92
-        if ($queryString === '') {
92
+        if ( $queryString === '' ) {
93 93
             return self::QUERY_TYPE_EMPTY;
94 94
         }
95 95
 
96
-        if (preg_match('/^(select|insert|update|delete|replace|show|desc|explain)[\s]+/i', $queryString, $matches)) {
97
-            switch (strtolower($matches[1])) {
96
+        if ( preg_match( '/^(select|insert|update|delete|replace|show|desc|explain)[\s]+/i', $queryString, $matches ) ) {
97
+            switch ( strtolower( $matches[ 1 ] ) ) {
98 98
                 case 'select':
99 99
                     return self::QUERY_TYPE_SELECT;
100 100
                 case 'insert':
@@ -120,53 +120,53 @@  discard block
 block discarded – undo
120 120
      * @param array $parameters
121 121
      * @throws DbException
122 122
      */
123
-    private function queryInit($query, $parameters = [])
123
+    private function queryInit( $query, $parameters = [ ] )
124 124
     {
125
-        $this->pdo = DbConnect::getInstance()->getConnection(self::getQueryStatement($query));
126
-        $startQueryTime = microtime(true);
125
+        $this->pdo = DbConnect::getInstance()->getConnection( self::getQueryStatement( $query ) );
126
+        $startQueryTime = microtime( true );
127 127
 
128 128
         try {
129 129
 
130 130
             /**
131 131
              * Prepare query
132 132
              */
133
-            $this->sQuery = $this->pdo->prepare($query);
133
+            $this->sQuery = $this->pdo->prepare( $query );
134 134
 
135 135
             /**
136 136
              * Add parameters to the parameter array
137 137
              */
138
-            if (self::isArrayAssoc($parameters))
139
-                $this->bindMore($parameters); else
140
-                foreach ($parameters as $key => $val)
141
-                    $this->parameters[] = array($key + 1, $val);
142
-
143
-            if (count($this->parameters)) {
144
-                foreach ($this->parameters as $param => $value) {
145
-                    if (is_int($value[1])) {
138
+            if ( self::isArrayAssoc( $parameters ) )
139
+                $this->bindMore( $parameters ); else
140
+                foreach ( $parameters as $key => $val )
141
+                    $this->parameters[ ] = array( $key + 1, $val );
142
+
143
+            if ( count( $this->parameters ) ) {
144
+                foreach ( $this->parameters as $param => $value ) {
145
+                    if ( is_int( $value[ 1 ] ) ) {
146 146
                         $type = \PDO::PARAM_INT;
147
-                    } elseif (is_bool($value[1])) {
147
+                    } elseif ( is_bool( $value[ 1 ] ) ) {
148 148
                         $type = \PDO::PARAM_BOOL;
149
-                    } elseif (is_null($value[1])) {
149
+                    } elseif ( is_null( $value[ 1 ] ) ) {
150 150
                         $type = \PDO::PARAM_NULL;
151 151
                     } else {
152 152
                         $type = \PDO::PARAM_STR;
153 153
                     }
154
-                    $this->sQuery->bindValue($value[0], $value[1], $type);
154
+                    $this->sQuery->bindValue( $value[ 0 ], $value[ 1 ], $type );
155 155
                 }
156 156
             }
157 157
 
158 158
             $this->sQuery->execute();
159 159
 
160
-            if (DbConfig::getInstance()->isEnableLogQueryDuration()) {
161
-                $duration = microtime(true) - $startQueryTime;
162
-                DbLog::getInstance()->writeQueryDuration($query, $duration);
160
+            if ( DbConfig::getInstance()->isEnableLogQueryDuration() ) {
161
+                $duration = microtime( true ) - $startQueryTime;
162
+                DbLog::getInstance()->writeQueryDuration( $query, $duration );
163 163
             }
164 164
 
165
-        } catch (\PDOException $e) {
166
-            if (DbConfig::getInstance()->isEnableLogErrors()) {
167
-                DbLog::getInstance()->writeQueryErros($query, $e->getCode(), $e->getMessage());
165
+        } catch ( \PDOException $e ) {
166
+            if ( DbConfig::getInstance()->isEnableLogErrors() ) {
167
+                DbLog::getInstance()->writeQueryErros( $query, $e->getCode(), $e->getMessage() );
168 168
             }
169
-            throw new DbException('Database error!', DbException::DB_QUERY_ERROR);
169
+            throw new DbException( 'Database error!', DbException::DB_QUERY_ERROR );
170 170
         }
171 171
 
172 172
         /**
@@ -179,27 +179,27 @@  discard block
 block discarded – undo
179 179
      * @param array $arr
180 180
      * @return bool
181 181
      */
182
-    public static function isArrayAssoc(array $arr)
182
+    public static function isArrayAssoc( array $arr )
183 183
     {
184
-        if (array() === $arr)
184
+        if ( array() === $arr )
185 185
             return false;
186 186
 
187
-        return array_keys($arr) !== range(0, count($arr) - 1);
187
+        return array_keys( $arr ) !== range( 0, count( $arr ) - 1 );
188 188
     }
189 189
 
190
-    public function bindMore($parray)
190
+    public function bindMore( $parray )
191 191
     {
192
-        if (!count($this->parameters) && is_array($parray)) {
193
-            $columns = array_keys($parray);
194
-            foreach ($columns as $i => &$column) {
195
-                $this->bind($column, $parray[ $column ]);
192
+        if ( !count( $this->parameters ) && is_array( $parray ) ) {
193
+            $columns = array_keys( $parray );
194
+            foreach ( $columns as $i => &$column ) {
195
+                $this->bind( $column, $parray[ $column ] );
196 196
             }
197 197
         }
198 198
     }
199 199
 
200
-    public function bind($para, $value)
200
+    public function bind( $para, $value )
201 201
     {
202
-        $this->parameters[ sizeof($this->parameters) ] = [":" . $para, $value];
202
+        $this->parameters[ sizeof( $this->parameters ) ] = [ ":" . $para, $value ];
203 203
     }
204 204
 
205 205
     /**
@@ -207,46 +207,46 @@  discard block
 block discarded – undo
207 207
      * @param array $params
208 208
      * @return array|null
209 209
      */
210
-    public function column($query, $params = null)
210
+    public function column( $query, $params = null )
211 211
     {
212
-        $this->queryInit($query, $params);
212
+        $this->queryInit( $query, $params );
213 213
 
214
-        $query = trim(str_replace("\r", " ", $query));
215
-        $statement = self::getQueryStatement($query);
214
+        $query = trim( str_replace( "\r", " ", $query ) );
215
+        $statement = self::getQueryStatement( $query );
216 216
 
217
-        if ($statement === self::QUERY_TYPE_EXPLAIN)
218
-            return $this->sQuery->fetchAll(\PDO::FETCH_ASSOC);
217
+        if ( $statement === self::QUERY_TYPE_EXPLAIN )
218
+            return $this->sQuery->fetchAll( \PDO::FETCH_ASSOC );
219 219
 
220
-        $Columns = $this->sQuery->fetchAll(\PDO::FETCH_NUM);
220
+        $Columns = $this->sQuery->fetchAll( \PDO::FETCH_NUM );
221 221
 
222 222
         $column = null;
223 223
 
224
-        foreach ($Columns as $cells) {
225
-            $column[] = $cells[0];
224
+        foreach ( $Columns as $cells ) {
225
+            $column[ ] = $cells[ 0 ];
226 226
         }
227 227
 
228 228
         return $column;
229 229
     }
230 230
 
231
-    public function row($query, $params = null, $fetchmode = \PDO::FETCH_ASSOC)
231
+    public function row( $query, $params = null, $fetchmode = \PDO::FETCH_ASSOC )
232 232
     {
233
-        $this->queryInit($query, $params);
233
+        $this->queryInit( $query, $params );
234 234
 
235
-        $query = trim(str_replace("\r", " ", $query));
236
-        $statement = self::getQueryStatement($query);
235
+        $query = trim( str_replace( "\r", " ", $query ) );
236
+        $statement = self::getQueryStatement( $query );
237 237
 
238
-        if ($statement === self::QUERY_TYPE_EXPLAIN)
239
-            return $this->sQuery->fetchAll(\PDO::FETCH_ASSOC);
238
+        if ( $statement === self::QUERY_TYPE_EXPLAIN )
239
+            return $this->sQuery->fetchAll( \PDO::FETCH_ASSOC );
240 240
 
241
-        $result = $this->sQuery->fetch($fetchmode);
241
+        $result = $this->sQuery->fetch( $fetchmode );
242 242
         $this->sQuery->closeCursor(); // Frees up the connection to the server so that other SQL statements may be issued,
243 243
 
244 244
         return $result;
245 245
     }
246 246
 
247
-    public function single($query, $params = null)
247
+    public function single( $query, $params = null )
248 248
     {
249
-        $this->queryInit($query, $params);
249
+        $this->queryInit( $query, $params );
250 250
         $result = $this->sQuery->fetchColumn();
251 251
         $this->sQuery->closeCursor(); // Frees up the connection to the server so that other SQL statements may be issued
252 252
 
Please login to merge, or discard this patch.
Braces   +14 added lines, -9 removed lines patch added patch discarded remove patch
@@ -135,10 +135,12 @@  discard block
 block discarded – undo
135 135
             /**
136 136
              * Add parameters to the parameter array
137 137
              */
138
-            if (self::isArrayAssoc($parameters))
139
-                $this->bindMore($parameters); else
140
-                foreach ($parameters as $key => $val)
138
+            if (self::isArrayAssoc($parameters)) {
139
+                            $this->bindMore($parameters);
140
+            } else {
141
+                                foreach ($parameters as $key => $val)
141 142
                     $this->parameters[] = array($key + 1, $val);
143
+                }
142 144
 
143 145
             if (count($this->parameters)) {
144 146
                 foreach ($this->parameters as $param => $value) {
@@ -181,8 +183,9 @@  discard block
 block discarded – undo
181 183
      */
182 184
     public static function isArrayAssoc(array $arr)
183 185
     {
184
-        if (array() === $arr)
185
-            return false;
186
+        if (array() === $arr) {
187
+                    return false;
188
+        }
186 189
 
187 190
         return array_keys($arr) !== range(0, count($arr) - 1);
188 191
     }
@@ -214,8 +217,9 @@  discard block
 block discarded – undo
214 217
         $query = trim(str_replace("\r", " ", $query));
215 218
         $statement = self::getQueryStatement($query);
216 219
 
217
-        if ($statement === self::QUERY_TYPE_EXPLAIN)
218
-            return $this->sQuery->fetchAll(\PDO::FETCH_ASSOC);
220
+        if ($statement === self::QUERY_TYPE_EXPLAIN) {
221
+                    return $this->sQuery->fetchAll(\PDO::FETCH_ASSOC);
222
+        }
219 223
 
220 224
         $Columns = $this->sQuery->fetchAll(\PDO::FETCH_NUM);
221 225
 
@@ -235,8 +239,9 @@  discard block
 block discarded – undo
235 239
         $query = trim(str_replace("\r", " ", $query));
236 240
         $statement = self::getQueryStatement($query);
237 241
 
238
-        if ($statement === self::QUERY_TYPE_EXPLAIN)
239
-            return $this->sQuery->fetchAll(\PDO::FETCH_ASSOC);
242
+        if ($statement === self::QUERY_TYPE_EXPLAIN) {
243
+                    return $this->sQuery->fetchAll(\PDO::FETCH_ASSOC);
244
+        }
240 245
 
241 246
         $result = $this->sQuery->fetch($fetchmode);
242 247
         $this->sQuery->closeCursor(); // Frees up the connection to the server so that other SQL statements may be issued,
Please login to merge, or discard this patch.
src/DB/DbException.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -11,9 +11,9 @@
 block discarded – undo
11 11
 class DbException extends \Exception
12 12
 {
13 13
 
14
-    const DB_CONNECTION_ERROR = 1;
15
-    const DB_QUERY_ERROR = 2;
16
-    const DB_ERROR_MASTER_DATA_CONNECTION_MISSING = 3;
14
+	const DB_CONNECTION_ERROR = 1;
15
+	const DB_QUERY_ERROR = 2;
16
+	const DB_ERROR_MASTER_DATA_CONNECTION_MISSING = 3;
17 17
 
18 18
 
19 19
 }
20 20
\ No newline at end of file
Please login to merge, or discard this patch.
src/DB/DbConnect.php 3 patches
Indentation   +117 added lines, -117 removed lines patch added patch discarded remove patch
@@ -11,122 +11,122 @@
 block discarded – undo
11 11
 class DbConnect
12 12
 {
13 13
 
14
-    private static $instance;
15
-
16
-    /**
17
-     * @var \PDO
18
-     */
19
-    private $pdoMaster;
20
-
21
-    /**
22
-     * @var \PDO
23
-     */
24
-    private $pdoSlave;
25
-
26
-    /**
27
-     * @var DbConfig
28
-     */
29
-    private $config;
30
-
31
-
32
-    /**
33
-     * DbConnect constructor.
34
-     */
35
-    private function __construct()
36
-    {
37
-        $this->config = DbConfig::getInstance();
38
-    }
39
-
40
-    /**
41
-     * @return \PDO
42
-     */
43
-    public function getMasterConnection()
44
-    {
45
-        if (!is_a($this->pdoMaster, \PDO::class))
46
-            $this->pdoMaster = $this->connect($this->config->getMasterDataConnect());
47
-
48
-        return $this->pdoMaster;
49
-    }
50
-
51
-    /**
52
-     * @return \PDO
53
-     */
54
-    public function getSlaveConnection()
55
-    {
56
-        if (!$this->config->getReplicationEnable())
57
-            return $this->getMasterConnection();
58
-
59
-        if (!is_a($this->pdoSlave, \PDO::class))
60
-            $this->pdoSlave = $this->connect($this->config->getSlaveDataConnect());
61
-
62
-        return $this->pdoSlave;
63
-    }
64
-
65
-    /**
66
-     * @param $statement
67
-     * @return \PDO
68
-     */
69
-    public function getConnection($statement)
70
-    {
71
-        $statement = trim(strtolower($statement));
72
-
73
-        if ($statement === DbService::QUERY_TYPE_SELECT)
74
-            return $this->getSlaveConnection();
75
-
76
-        return $this->getMasterConnection();
77
-    }
78
-
79
-    /**
80
-     * @param $string
81
-     * @return string
82
-     */
83
-    public function quote($string)
84
-    {
85
-        return $this->getMasterConnection()->quote($string);
86
-    }
87
-
88
-    /**
89
-     * @return string
90
-     */
91
-    public function lastInsertId()
92
-    {
93
-        return $this->getMasterConnection()->lastInsertId();
94
-    }
95
-
96
-    /**
97
-     * @param $dataConnect
98
-     * @return \PDO
99
-     */
100
-    private function connect($dataConnect)
101
-    {
102
-        $dsn = 'mysql:dbname=' . $dataConnect["dbname"] . ';host=' . $dataConnect["host"] . '';
103
-        try {
104
-
105
-            $pdo = new \PDO($dsn, $dataConnect["user"], $dataConnect["password"], array(\PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
106
-
107
-            $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
108
-            $pdo->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
109
-        } catch (\PDOException $e) {
110
-            if (DbConfig::getInstance()->isEnableLogErrors()) {
111
-                DbLog::getInstance()->writeQueryErros('Connection fail!', $e->getCode(), $e->getMessage());
112
-            }
113
-            throw new DbException('Database connection error!', DbException::DB_CONNECTION_ERROR);
114
-        }
115
-
116
-        return $pdo;
117
-    }
118
-
119
-
120
-    /**
121
-     * @return DbConnect
122
-     */
123
-    public static function getInstance()
124
-    {
125
-        if (null === self::$instance) {
126
-            self::$instance = new self();
127
-        }
128
-
129
-        return self::$instance;
130
-    }
14
+	private static $instance;
15
+
16
+	/**
17
+	 * @var \PDO
18
+	 */
19
+	private $pdoMaster;
20
+
21
+	/**
22
+	 * @var \PDO
23
+	 */
24
+	private $pdoSlave;
25
+
26
+	/**
27
+	 * @var DbConfig
28
+	 */
29
+	private $config;
30
+
31
+
32
+	/**
33
+	 * DbConnect constructor.
34
+	 */
35
+	private function __construct()
36
+	{
37
+		$this->config = DbConfig::getInstance();
38
+	}
39
+
40
+	/**
41
+	 * @return \PDO
42
+	 */
43
+	public function getMasterConnection()
44
+	{
45
+		if (!is_a($this->pdoMaster, \PDO::class))
46
+			$this->pdoMaster = $this->connect($this->config->getMasterDataConnect());
47
+
48
+		return $this->pdoMaster;
49
+	}
50
+
51
+	/**
52
+	 * @return \PDO
53
+	 */
54
+	public function getSlaveConnection()
55
+	{
56
+		if (!$this->config->getReplicationEnable())
57
+			return $this->getMasterConnection();
58
+
59
+		if (!is_a($this->pdoSlave, \PDO::class))
60
+			$this->pdoSlave = $this->connect($this->config->getSlaveDataConnect());
61
+
62
+		return $this->pdoSlave;
63
+	}
64
+
65
+	/**
66
+	 * @param $statement
67
+	 * @return \PDO
68
+	 */
69
+	public function getConnection($statement)
70
+	{
71
+		$statement = trim(strtolower($statement));
72
+
73
+		if ($statement === DbService::QUERY_TYPE_SELECT)
74
+			return $this->getSlaveConnection();
75
+
76
+		return $this->getMasterConnection();
77
+	}
78
+
79
+	/**
80
+	 * @param $string
81
+	 * @return string
82
+	 */
83
+	public function quote($string)
84
+	{
85
+		return $this->getMasterConnection()->quote($string);
86
+	}
87
+
88
+	/**
89
+	 * @return string
90
+	 */
91
+	public function lastInsertId()
92
+	{
93
+		return $this->getMasterConnection()->lastInsertId();
94
+	}
95
+
96
+	/**
97
+	 * @param $dataConnect
98
+	 * @return \PDO
99
+	 */
100
+	private function connect($dataConnect)
101
+	{
102
+		$dsn = 'mysql:dbname=' . $dataConnect["dbname"] . ';host=' . $dataConnect["host"] . '';
103
+		try {
104
+
105
+			$pdo = new \PDO($dsn, $dataConnect["user"], $dataConnect["password"], array(\PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
106
+
107
+			$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
108
+			$pdo->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
109
+		} catch (\PDOException $e) {
110
+			if (DbConfig::getInstance()->isEnableLogErrors()) {
111
+				DbLog::getInstance()->writeQueryErros('Connection fail!', $e->getCode(), $e->getMessage());
112
+			}
113
+			throw new DbException('Database connection error!', DbException::DB_CONNECTION_ERROR);
114
+		}
115
+
116
+		return $pdo;
117
+	}
118
+
119
+
120
+	/**
121
+	 * @return DbConnect
122
+	 */
123
+	public static function getInstance()
124
+	{
125
+		if (null === self::$instance) {
126
+			self::$instance = new self();
127
+		}
128
+
129
+		return self::$instance;
130
+	}
131 131
 
132 132
 }
133 133
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -42,8 +42,8 @@  discard block
 block discarded – undo
42 42
      */
43 43
     public function getMasterConnection()
44 44
     {
45
-        if (!is_a($this->pdoMaster, \PDO::class))
46
-            $this->pdoMaster = $this->connect($this->config->getMasterDataConnect());
45
+        if ( !is_a( $this->pdoMaster, \PDO::class ) )
46
+            $this->pdoMaster = $this->connect( $this->config->getMasterDataConnect() );
47 47
 
48 48
         return $this->pdoMaster;
49 49
     }
@@ -53,11 +53,11 @@  discard block
 block discarded – undo
53 53
      */
54 54
     public function getSlaveConnection()
55 55
     {
56
-        if (!$this->config->getReplicationEnable())
56
+        if ( !$this->config->getReplicationEnable() )
57 57
             return $this->getMasterConnection();
58 58
 
59
-        if (!is_a($this->pdoSlave, \PDO::class))
60
-            $this->pdoSlave = $this->connect($this->config->getSlaveDataConnect());
59
+        if ( !is_a( $this->pdoSlave, \PDO::class ) )
60
+            $this->pdoSlave = $this->connect( $this->config->getSlaveDataConnect() );
61 61
 
62 62
         return $this->pdoSlave;
63 63
     }
@@ -66,11 +66,11 @@  discard block
 block discarded – undo
66 66
      * @param $statement
67 67
      * @return \PDO
68 68
      */
69
-    public function getConnection($statement)
69
+    public function getConnection( $statement )
70 70
     {
71
-        $statement = trim(strtolower($statement));
71
+        $statement = trim( strtolower( $statement ) );
72 72
 
73
-        if ($statement === DbService::QUERY_TYPE_SELECT)
73
+        if ( $statement === DbService::QUERY_TYPE_SELECT )
74 74
             return $this->getSlaveConnection();
75 75
 
76 76
         return $this->getMasterConnection();
@@ -80,9 +80,9 @@  discard block
 block discarded – undo
80 80
      * @param $string
81 81
      * @return string
82 82
      */
83
-    public function quote($string)
83
+    public function quote( $string )
84 84
     {
85
-        return $this->getMasterConnection()->quote($string);
85
+        return $this->getMasterConnection()->quote( $string );
86 86
     }
87 87
 
88 88
     /**
@@ -97,20 +97,20 @@  discard block
 block discarded – undo
97 97
      * @param $dataConnect
98 98
      * @return \PDO
99 99
      */
100
-    private function connect($dataConnect)
100
+    private function connect( $dataConnect )
101 101
     {
102
-        $dsn = 'mysql:dbname=' . $dataConnect["dbname"] . ';host=' . $dataConnect["host"] . '';
102
+        $dsn = 'mysql:dbname=' . $dataConnect[ "dbname" ] . ';host=' . $dataConnect[ "host" ] . '';
103 103
         try {
104 104
 
105
-            $pdo = new \PDO($dsn, $dataConnect["user"], $dataConnect["password"], array(\PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
105
+            $pdo = new \PDO( $dsn, $dataConnect[ "user" ], $dataConnect[ "password" ], array( \PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8" ) );
106 106
 
107
-            $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
108
-            $pdo->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
109
-        } catch (\PDOException $e) {
110
-            if (DbConfig::getInstance()->isEnableLogErrors()) {
111
-                DbLog::getInstance()->writeQueryErros('Connection fail!', $e->getCode(), $e->getMessage());
107
+            $pdo->setAttribute( \PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION );
108
+            $pdo->setAttribute( \PDO::ATTR_EMULATE_PREPARES, false );
109
+        } catch ( \PDOException $e ) {
110
+            if ( DbConfig::getInstance()->isEnableLogErrors() ) {
111
+                DbLog::getInstance()->writeQueryErros( 'Connection fail!', $e->getCode(), $e->getMessage() );
112 112
             }
113
-            throw new DbException('Database connection error!', DbException::DB_CONNECTION_ERROR);
113
+            throw new DbException( 'Database connection error!', DbException::DB_CONNECTION_ERROR );
114 114
         }
115 115
 
116 116
         return $pdo;
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
      */
123 123
     public static function getInstance()
124 124
     {
125
-        if (null === self::$instance) {
125
+        if ( null === self::$instance ) {
126 126
             self::$instance = new self();
127 127
         }
128 128
 
Please login to merge, or discard this patch.
Braces   +12 added lines, -8 removed lines patch added patch discarded remove patch
@@ -42,8 +42,9 @@  discard block
 block discarded – undo
42 42
      */
43 43
     public function getMasterConnection()
44 44
     {
45
-        if (!is_a($this->pdoMaster, \PDO::class))
46
-            $this->pdoMaster = $this->connect($this->config->getMasterDataConnect());
45
+        if (!is_a($this->pdoMaster, \PDO::class)) {
46
+                    $this->pdoMaster = $this->connect($this->config->getMasterDataConnect());
47
+        }
47 48
 
48 49
         return $this->pdoMaster;
49 50
     }
@@ -53,11 +54,13 @@  discard block
 block discarded – undo
53 54
      */
54 55
     public function getSlaveConnection()
55 56
     {
56
-        if (!$this->config->getReplicationEnable())
57
-            return $this->getMasterConnection();
57
+        if (!$this->config->getReplicationEnable()) {
58
+                    return $this->getMasterConnection();
59
+        }
58 60
 
59
-        if (!is_a($this->pdoSlave, \PDO::class))
60
-            $this->pdoSlave = $this->connect($this->config->getSlaveDataConnect());
61
+        if (!is_a($this->pdoSlave, \PDO::class)) {
62
+                    $this->pdoSlave = $this->connect($this->config->getSlaveDataConnect());
63
+        }
61 64
 
62 65
         return $this->pdoSlave;
63 66
     }
@@ -70,8 +73,9 @@  discard block
 block discarded – undo
70 73
     {
71 74
         $statement = trim(strtolower($statement));
72 75
 
73
-        if ($statement === DbService::QUERY_TYPE_SELECT)
74
-            return $this->getSlaveConnection();
76
+        if ($statement === DbService::QUERY_TYPE_SELECT) {
77
+                    return $this->getSlaveConnection();
78
+        }
75 79
 
76 80
         return $this->getMasterConnection();
77 81
     }
Please login to merge, or discard this patch.