Query::queryFetch()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 12

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
cc 4
nc 4
nop 1
dl 12
loc 12
rs 9.8666
c 0
b 0
f 0
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 5 and the first side effect is on line 2.

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
  jRequire("../JException/JException.php");
3
  jRequire("../JConfig/JConfig.php");
4
  jRequire("../Connection/Connection.php");
5
  trait Query {
0 ignored issues
show
Coding Style Compatibility introduced by
Each trait must be in a namespace of at least one level (a top-level vendor name)

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
6
    public $connection;
7
    public $currentConnection;
8
    public function __construct() {
9
      $this->connection = [];
10
      $this->currentConnection = null;
11
    }
12
    public function addConnection( $_path, $_name = "default" ) {
13
      if(!is_string($_path))
14
        throw new JException("Parameter must be a string.", 1);
15
      try {
16
        $jConfig = new JConfig($_path);
17
        if($jConfig->enable) {
0 ignored issues
show
Bug introduced by
The property enable does not seem to exist in JConfig.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
18
          $connection = new Connection($jConfig);
19
          $this->addConnectionMan($connection, $_name);
20
        }
21
      } catch (Exception $e) {
22
        throw new JException($e->getMessage(), 1);
23
      }
24
    }
25
    public function addConnectionMan( $_connection, $_name = "default") {
26
      if(!is_object($_connection) || !is_a($_connection, "Connection"))
27
        throw new JException("Parameter must be a Connection object.", 1);
28
      try {
29
        $this->connection["$_name"] = $_connection;
30
        $this->currentConnection = $_connection;
31
      } catch (Exception $e) {
32
        throw new JException($e->getMessage(), 1);
33
      }
34
    }
35
    public function setConnection( $_name = "default" ) {
36
      if(!is_string($_name))
37
        throw new JException("Parameter must be a string.", 1);
38
      if(!isset($this->connection["$_name"]))
39
        throw new JException("This connection name does not exist.", 1);
40
      $this->currentConnection = $this->connection["$_name"];
41
    }
42 View Code Duplication
    public function query( $_query ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
43
      if(!is_string($_query))
44
        throw new JException("Parameter must be a string.", 1);
45
      if($this->currentConnection == null)
46
        throw new JException("No connection selected.", 1);
47
      try {
48
        $temp = $this->currentConnection->database->query($_query);
49
      } catch (Exception $e) {
50
        throw new JException($e->getMessage(), 1);
51
      }
52
      return $temp;
53
    }
54 View Code Duplication
    public function queryInsert( $_query ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
55
      if(!is_string($_query))
56
        throw new JException("Parameter must be a string.", 1);
57
      if($this->currentConnection == null)
58
        throw new JException("No connection selected.", 1);
59
      try {
60
        $temp = $this->currentConnection->database->queryInsert($_query);
61
      } catch (Exception $e) {
62
        throw new JException($e->getMessage(), 1);
63
      }
64
      return $temp;
65
    }
66 View Code Duplication
    public function queryFetch( $_query ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
67
      if(!is_string($_query))
68
        throw new JException("Parameter must be a string.", 1);
69
      if($this->currentConnection == null)
70
        throw new JException("No connection selected.", 1);
71
      try {
72
        $temp = $this->currentConnection->database->queryFetch($_query);
73
      } catch (Exception $e) {
74
        throw new JException($e->getMessage(), 1);
75
      }
76
      return $temp;
77
    }
78 View Code Duplication
    public function queryArray( $_query ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
79
      if(!is_string($_query))
80
        throw new JException("Parameter must be a string.", 1);
81
      if($this->currentConnection == null)
82
        throw new JException("No connection selected.", 1);
83
      try {
84
        $temp = $this->currentConnection->database->queryArray($_query);
85
      } catch (Exception $e) {
86
        throw new JException($e->getMessage(), 1);
87
      }
88
      return $temp;
89
    }
90 View Code Duplication
    public function newTable( $_query ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
91
      if(!is_string($_query))
92
        throw new JException("Parameter must be a string.", 1);
93
      if($this->currentConnection == null)
94
        throw new JException("No connection selected.", 1);
95
      try {
96
        $temp = $this->currentConnection->database->newTable($_query);
97
      } catch (Exception $e) {
98
        throw new JException($e->getMessage(), 1);
99
      }
100
      return $temp;
101
    }
102
  }
103
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
104