@@ -18,13 +18,13 @@ |
||
18 | 18 | |
19 | 19 | switch ($driver) { |
20 | 20 | case 'sqlite': |
21 | - $dsn = $driver.'::memory:'; |
|
21 | + $dsn = $driver . '::memory:'; |
|
22 | 22 | break; |
23 | 23 | case 'mysql': |
24 | 24 | case 'postgres': |
25 | - if(strcasecmp($driver, 'postgres') == 0) $driver="pgsql"; |
|
26 | - $dsn = $driver.':host='.$config['HOSTNAME'].';dbname='.$config['DBNAME']; |
|
27 | - if(isset($config['PORT'])) $dsn .= ';port='.$config['PORT']; |
|
25 | + if (strcasecmp($driver, 'postgres') == 0) $driver = "pgsql"; |
|
26 | + $dsn = $driver . ':host=' . $config['HOSTNAME'] . ';dbname=' . $config['DBNAME']; |
|
27 | + if (isset($config['PORT'])) $dsn .= ';port=' . $config['PORT']; |
|
28 | 28 | break; |
29 | 29 | default: |
30 | 30 | throw new DatabaseDriverNotSupportedException; |
@@ -22,9 +22,13 @@ |
||
22 | 22 | break; |
23 | 23 | case 'mysql': |
24 | 24 | case 'postgres': |
25 | - if(strcasecmp($driver, 'postgres') == 0) $driver="pgsql"; |
|
25 | + if(strcasecmp($driver, 'postgres') == 0) { |
|
26 | + $driver="pgsql"; |
|
27 | + } |
|
26 | 28 | $dsn = $driver.':host='.$config['HOSTNAME'].';dbname='.$config['DBNAME']; |
27 | - if(isset($config['PORT'])) $dsn .= ';port='.$config['PORT']; |
|
29 | + if(isset($config['PORT'])) { |
|
30 | + $dsn .= ';port='.$config['PORT']; |
|
31 | + } |
|
28 | 32 | break; |
29 | 33 | default: |
30 | 34 | throw new DatabaseDriverNotSupportedException; |
@@ -4,11 +4,11 @@ |
||
4 | 4 | |
5 | 5 | class DatabaseConnectionStringFactoryTest extends PHPUnit_Framework_TestCase |
6 | 6 | { |
7 | - /** |
|
8 | - * The instance of DatabaseConnectionStringFactory used in the test. |
|
9 | - * |
|
10 | - * @var Pyjac\ORM\DatabaseConnectionStringFactory |
|
11 | - */ |
|
7 | + /** |
|
8 | + * The instance of DatabaseConnectionStringFactory used in the test. |
|
9 | + * |
|
10 | + * @var Pyjac\ORM\DatabaseConnectionStringFactory |
|
11 | + */ |
|
12 | 12 | protected $openSourceEvangelistFactory; |
13 | 13 | |
14 | 14 | /** |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | public function getTableName() |
56 | 56 | { |
57 | 57 | $className = explode('\\', get_called_class()); |
58 | - $table = strtolower(end($className) .'s'); |
|
58 | + $table = strtolower(end($className) . 's'); |
|
59 | 59 | return $table; |
60 | 60 | } |
61 | 61 | /** |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | $sqlStatement = $this->databaseConnection->prepare($sql); |
83 | 83 | $sqlStatement->setFetchMode($this->databaseConnection::FETCH_CLASS, get_called_class()); |
84 | 84 | $sqlStatement->execute(); |
85 | - if($sqlStatement->rowCount() < 1){ |
|
85 | + if ($sqlStatement->rowCount() < 1) { |
|
86 | 86 | throw new ModelNotFoundException($id); |
87 | 87 | } |
88 | 88 | return $sqlStatement->fetch(); |
@@ -114,15 +114,15 @@ discard block |
||
114 | 114 | $columnNames = ""; |
115 | 115 | $columnValues = ""; |
116 | 116 | $bindNameParameters = []; |
117 | - $sqlUpdate = "UPDATE " . $this->getTableName() . " SET " ; |
|
117 | + $sqlUpdate = "UPDATE " . $this->getTableName() . " SET "; |
|
118 | 118 | foreach ($this->properties as $columnName => $columnValue) { |
119 | - if($key == 'id') continue; |
|
119 | + if ($key == 'id') continue; |
|
120 | 120 | $bindColumnName = ':' . $columnName; |
121 | 121 | $sqlUpdate .= "$columnName = $bindColumnName,"; |
122 | 122 | $bindNameParameters[$bindColumnName] = $columnValue |
123 | 123 | } |
124 | 124 | //Remove the last comma in sql command then join it to the other query part. |
125 | - $sqlUpdate = substr($sqlUpdate, 0, -1)." WHERE id = :id"; |
|
125 | + $sqlUpdate = substr($sqlUpdate, 0, -1) . " WHERE id = :id"; |
|
126 | 126 | $sqlStatement = $this->databaseConnection->prepare($sqlUpdate); |
127 | 127 | $sqlStatement->bindValue(":id", $this->properties['id']); |
128 | 128 | $sqlStatement->execute($bindNameParameters); |
@@ -140,19 +140,19 @@ discard block |
||
140 | 140 | $columnNames = ""; |
141 | 141 | $columnValues = ""; |
142 | 142 | $bindNameParameters = []; |
143 | - $sqlCreate = "INSERT" . " INTO " . $this->getTableName()." ("; |
|
143 | + $sqlCreate = "INSERT" . " INTO " . $this->getTableName() . " ("; |
|
144 | 144 | foreach ($this->properties as $columnName => $columnValue) { |
145 | 145 | |
146 | 146 | $bindColumnName = ':' . $columnName; |
147 | - $columnNames .= $columnName.","; |
|
148 | - $columnValues .= $bindColumnName.","; |
|
147 | + $columnNames .= $columnName . ","; |
|
148 | + $columnValues .= $bindColumnName . ","; |
|
149 | 149 | $bindNameParameters[$bindColumnName] = $columnValue |
150 | 150 | } |
151 | 151 | // Remove ending comma and whitespace. |
152 | 152 | $columnNames = substr($columnNames, 0, -1); |
153 | 153 | $columnValues = substr($columnValues, 0, -1); |
154 | 154 | |
155 | - $sqlCreate .= $columnNames.') VALUES (' .$columnValues.')'; |
|
155 | + $sqlCreate .= $columnNames . ') VALUES (' . $columnValues . ')'; |
|
156 | 156 | $sqlStatement = $this->databaseConnection->prepare($sqlCreate); |
157 | 157 | $sqlStatement->execute($bindNameParameters); |
158 | 158 | return $sqlStatement->rowCount(); |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | */ |
188 | 188 | public function delete($id) |
189 | 189 | { |
190 | - $sql = "DELETE" . " FROM " . self::getTableName()." WHERE id = ". $id; |
|
190 | + $sql = "DELETE" . " FROM " . self::getTableName() . " WHERE id = " . $id; |
|
191 | 191 | $sqlStatment = $this->databaseConnection->prepare($sql); |
192 | 192 | $sqlStatment->execute(); |
193 | 193 | return ($sqlStatment->rowCount() > 0) ? true : false; |
@@ -116,7 +116,9 @@ |
||
116 | 116 | $bindNameParameters = []; |
117 | 117 | $sqlUpdate = "UPDATE " . $this->getTableName() . " SET " ; |
118 | 118 | foreach ($this->properties as $columnName => $columnValue) { |
119 | - if($key == 'id') continue; |
|
119 | + if($key == 'id') { |
|
120 | + continue; |
|
121 | + } |
|
120 | 122 | $bindColumnName = ':' . $columnName; |
121 | 123 | $sqlUpdate .= "$columnName = $bindColumnName,"; |
122 | 124 | $bindNameParameters[$bindColumnName] = $columnValue |
@@ -10,15 +10,15 @@ discard block |
||
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Store instance of database connection used. |
13 | - * @var [type] |
|
14 | - */ |
|
13 | + * @var [type] |
|
14 | + */ |
|
15 | 15 | protected $databaseConnection; |
16 | 16 | |
17 | 17 | /** |
18 | 18 | * Create a model instance. |
19 | 19 | * |
20 | 20 | */ |
21 | - public function __construct() |
|
21 | + public function __construct() |
|
22 | 22 | { |
23 | 23 | $this->databaseConnection = DatabaseConnection::getInstance()->databaseConnection; |
24 | 24 | |
@@ -26,19 +26,19 @@ discard block |
||
26 | 26 | /** |
27 | 27 | * Sets into $properties the $key => $value pairs |
28 | 28 | * |
29 | - * @param string $key |
|
30 | - * @param string $val |
|
31 | - * |
|
32 | - */ |
|
29 | + * @param string $key |
|
30 | + * @param string $val |
|
31 | + * |
|
32 | + */ |
|
33 | 33 | public function __set($key, $val) |
34 | 34 | { |
35 | 35 | $this->properties[$key] = $val; |
36 | 36 | } |
37 | 37 | /** |
38 | - * @param string $key |
|
39 | - * |
|
40 | - * @return array |
|
41 | - */ |
|
38 | + * @param string $key |
|
39 | + * |
|
40 | + * @return array |
|
41 | + */ |
|
42 | 42 | public function __get($key) |
43 | 43 | { |
44 | 44 | return $this->properties[$key]; |
@@ -48,15 +48,15 @@ discard block |
||
48 | 48 | * |
49 | 49 | * @return array |
50 | 50 | */ |
51 | - public function getProperties() |
|
52 | - { |
|
53 | - return $this->properties; |
|
54 | - } |
|
51 | + public function getProperties() |
|
52 | + { |
|
53 | + return $this->properties; |
|
54 | + } |
|
55 | 55 | /** |
56 | - * Gets the name of the child class with a 's'. |
|
57 | - * |
|
58 | - * @return string |
|
59 | - */ |
|
56 | + * Gets the name of the child class with a 's'. |
|
57 | + * |
|
58 | + * @return string |
|
59 | + */ |
|
60 | 60 | public function getTableName() |
61 | 61 | { |
62 | 62 | $className = explode('\\', get_called_class()); |
@@ -64,12 +64,12 @@ discard block |
||
64 | 64 | return $table; |
65 | 65 | } |
66 | 66 | /** |
67 | - * Find the particular model with the passed id. |
|
68 | - * |
|
69 | - * @param int $id |
|
70 | - * |
|
71 | - * @return object |
|
72 | - */ |
|
67 | + * Find the particular model with the passed id. |
|
68 | + * |
|
69 | + * @param int $id |
|
70 | + * |
|
71 | + * @return object |
|
72 | + */ |
|
73 | 73 | public static function find($id) |
74 | 74 | { |
75 | 75 | $model = new static; |
@@ -77,12 +77,12 @@ discard block |
||
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
80 | - * Get the particular model with the passed id. |
|
81 | - * |
|
82 | - * @param int $id |
|
83 | - * |
|
84 | - * @return object |
|
85 | - */ |
|
80 | + * Get the particular model with the passed id. |
|
81 | + * |
|
82 | + * @param int $id |
|
83 | + * |
|
84 | + * @return object |
|
85 | + */ |
|
86 | 86 | public function get($id) |
87 | 87 | { |
88 | 88 | $sql = "SELECT * FROM {$this->getTableName()} WHERE id={$id}"; |
@@ -96,10 +96,10 @@ discard block |
||
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
99 | - * Get all the models from the database. |
|
100 | - * |
|
101 | - * @return array |
|
102 | - */ |
|
99 | + * Get all the models from the database. |
|
100 | + * |
|
101 | + * @return array |
|
102 | + */ |
|
103 | 103 | public static function getAll() |
104 | 104 | { |
105 | 105 | $model = new static; |
@@ -107,10 +107,10 @@ discard block |
||
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
110 | - * Returns all the models from the database. |
|
111 | - * |
|
112 | - * @return array |
|
113 | - */ |
|
110 | + * Returns all the models from the database. |
|
111 | + * |
|
112 | + * @return array |
|
113 | + */ |
|
114 | 114 | public function all() |
115 | 115 | { |
116 | 116 | $sql = "SELECT * FROM {$this->getTableName()}"; |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | * Update the model in the database. |
125 | 125 | * |
126 | 126 | * @return int |
127 | - */ |
|
127 | + */ |
|
128 | 128 | private function update() |
129 | 129 | { |
130 | 130 | |
@@ -147,10 +147,10 @@ discard block |
||
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
150 | - * Insert the model values into the database. |
|
151 | - * |
|
152 | - * @return int |
|
153 | - */ |
|
150 | + * Insert the model values into the database. |
|
151 | + * |
|
152 | + * @return int |
|
153 | + */ |
|
154 | 154 | private function create() |
155 | 155 | { |
156 | 156 | |
@@ -185,11 +185,11 @@ discard block |
||
185 | 185 | return $this->id ? $this->update() : $this->create(); |
186 | 186 | } |
187 | 187 | |
188 | - /** |
|
189 | - * Delete a model from the database. |
|
190 | - * @param int $id |
|
191 | - * @return boolean |
|
192 | - */ |
|
188 | + /** |
|
189 | + * Delete a model from the database. |
|
190 | + * @param int $id |
|
191 | + * @return boolean |
|
192 | + */ |
|
193 | 193 | public static function destroy($id) |
194 | 194 | { |
195 | 195 | $model = new static; |
@@ -178,7 +178,7 @@ |
||
178 | 178 | /** |
179 | 179 | * Save the model data to the database. |
180 | 180 | * |
181 | - * @return boolean |
|
181 | + * @return integer |
|
182 | 182 | */ |
183 | 183 | public function save() |
184 | 184 | { |