@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | */ |
30 | 30 | public function __construct(DatabaseConnectionInterface $databaseConnection = null) |
31 | 31 | { |
32 | - if($databaseConnection == null){ |
|
32 | + if ($databaseConnection == null) { |
|
33 | 33 | $this->databaseConnection = DatabaseConnection::getInstance()->databaseConnection; |
34 | 34 | } |
35 | 35 | $this->databaseConnection = $databaseConnection; |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | public function getTableName() |
81 | 81 | { |
82 | 82 | $className = explode('\\', get_called_class()); |
83 | - $table = strtolower(end($className) .'s'); |
|
83 | + $table = strtolower(end($className) . 's'); |
|
84 | 84 | return $table; |
85 | 85 | } |
86 | 86 | /** |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | $sqlStatement = $this->databaseConnection->prepare($sql); |
110 | 110 | $sqlStatement->setFetchMode(PDO::FETCH_CLASS, get_called_class()); |
111 | 111 | $sqlStatement->execute(); |
112 | - if($sqlStatement->rowCount() < 1){ |
|
112 | + if ($sqlStatement->rowCount() < 1) { |
|
113 | 113 | throw new ModelNotFoundException($id); |
114 | 114 | } |
115 | 115 | return $sqlStatement->fetch(); |
@@ -149,15 +149,15 @@ discard block |
||
149 | 149 | { |
150 | 150 | |
151 | 151 | $bindNameParameters = []; |
152 | - $sqlUpdate = "UPDATE " . $this->getTableName() . " SET " ; |
|
152 | + $sqlUpdate = "UPDATE " . $this->getTableName() . " SET "; |
|
153 | 153 | foreach ($this->properties as $columnName => $columnValue) { |
154 | - if($columnName == 'id') continue; |
|
154 | + if ($columnName == 'id') continue; |
|
155 | 155 | $bindColumnName = ':' . $columnName; |
156 | 156 | $sqlUpdate .= "$columnName = $bindColumnName,"; |
157 | 157 | $bindNameParameters[$bindColumnName] = $columnValue; |
158 | 158 | } |
159 | 159 | //Remove the last comma in sql command then join it to the other query part. |
160 | - $sqlUpdate = substr($sqlUpdate, 0, -1)." WHERE id = :id"; |
|
160 | + $sqlUpdate = substr($sqlUpdate, 0, -1) . " WHERE id = :id"; |
|
161 | 161 | $sqlStatement = $this->databaseConnection->prepare($sqlUpdate); |
162 | 162 | $bindNameParameters[":id"] = $this->properties['id']; |
163 | 163 | $sqlStatement->execute($bindNameParameters); |
@@ -175,19 +175,19 @@ discard block |
||
175 | 175 | $columnNames = ""; |
176 | 176 | $columnValues = ""; |
177 | 177 | $bindNameParameters = []; |
178 | - $sqlCreate = "INSERT" . " INTO " . $this->getTableName()." ("; |
|
178 | + $sqlCreate = "INSERT" . " INTO " . $this->getTableName() . " ("; |
|
179 | 179 | foreach ($this->properties as $columnName => $columnValue) { |
180 | 180 | |
181 | 181 | $bindColumnName = ':' . $columnName; |
182 | - $columnNames .= $columnName.","; |
|
183 | - $columnValues .= $bindColumnName.","; |
|
182 | + $columnNames .= $columnName . ","; |
|
183 | + $columnValues .= $bindColumnName . ","; |
|
184 | 184 | $bindNameParameters[$bindColumnName] = $columnValue; |
185 | 185 | } |
186 | 186 | // Remove ending comma and whitespace. |
187 | 187 | $columnNames = substr($columnNames, 0, -1); |
188 | 188 | $columnValues = substr($columnValues, 0, -1); |
189 | 189 | |
190 | - $sqlCreate .= $columnNames.') VALUES (' .$columnValues.')'; |
|
190 | + $sqlCreate .= $columnNames . ') VALUES (' . $columnValues . ')'; |
|
191 | 191 | $sqlStatement = $this->databaseConnection->prepare($sqlCreate); |
192 | 192 | $sqlStatement->execute($bindNameParameters); |
193 | 193 | return $sqlStatement->rowCount(); |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | */ |
223 | 223 | public function delete($id) |
224 | 224 | { |
225 | - $sql = "DELETE" . " FROM " . self::getTableName()." WHERE id = ". $id; |
|
225 | + $sql = "DELETE" . " FROM " . self::getTableName() . " WHERE id = " . $id; |
|
226 | 226 | $sqlStatment = $this->databaseConnection->prepare($sql); |
227 | 227 | $sqlStatment->execute(); |
228 | 228 | return ($sqlStatment->rowCount() > 0) ? true : false; |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | |
15 | 15 | protected $sqlStatement; |
16 | 16 | |
17 | - public function setUp(){ |
|
17 | + public function setUp() { |
|
18 | 18 | |
19 | 19 | |
20 | 20 | $databaseConnectionStringFactory = |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | $this->sqlStatement = m::mock('\PDOStatement'); |
29 | 29 | |
30 | 30 | /*$this->databaseConnection = m::mock('Pyjac\ORM\DatabaseConnection[getInstance,createConnection]',array($databaseConnectionStringFactory));*/ |
31 | - $this->model = $this->getMockForAbstractClass('Pyjac\ORM\Model',[$this->databaseConnection]); |
|
31 | + $this->model = $this->getMockForAbstractClass('Pyjac\ORM\Model', [$this->databaseConnection]); |
|
32 | 32 | //= new DatabaseConnection($databaseConnectionStringFactory); |
33 | 33 | } |
34 | 34 | |
@@ -37,9 +37,9 @@ discard block |
||
37 | 37 | $this->databaseConnection->shouldReceive('createConnection')->with('sqlite::memory:')->once()->andReturn(""); |
38 | 38 | $this->model->expects($this->any()) |
39 | 39 | ->method('getTableName') |
40 | - ->will($this->returnValue(strtolower(get_class($this->model).'s'))); |
|
40 | + ->will($this->returnValue(strtolower(get_class($this->model) . 's'))); |
|
41 | 41 | |
42 | - $this->assertEquals($this->model->getTableName(), strtolower(get_class($this->model).'s')); |
|
42 | + $this->assertEquals($this->model->getTableName(), strtolower(get_class($this->model) . 's')); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | public function testGetReturnsAnObjectWhenIdIsFoundInDatabase() |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | { |
70 | 70 | $this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement); |
71 | 71 | $this->sqlStatement->shouldReceive('execute'); |
72 | - $this->sqlStatement->shouldReceive('fetchAll')->once()->andReturn([new stdClass,new stdClass]); |
|
72 | + $this->sqlStatement->shouldReceive('fetchAll')->once()->andReturn([new stdClass, new stdClass]); |
|
73 | 73 | $this->assertContainsOnlyInstancesOf('stdClass', $this->model->all()); |
74 | 74 | } |
75 | 75 | |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | $this->model->setProperties(['id' => 2, 'name' => 'pyjac', 'age' => '419']); |
79 | 79 | $this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement); |
80 | 80 | $this->sqlStatement->shouldReceive('execute'); |
81 | - $this->sqlStatement->shouldReceive('fetchAll')->once()->andReturn([new stdClass,new stdClass]); |
|
81 | + $this->sqlStatement->shouldReceive('fetchAll')->once()->andReturn([new stdClass, new stdClass]); |
|
82 | 82 | $this->sqlStatement->shouldReceive('rowCount')->once()->andReturn(1); |
83 | 83 | |
84 | 84 | $this->assertEquals(1, $this->model->update()); |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | $this->model->setProperties(['id' => 2, 'name' => 'pyjac', 'age' => '419']); |
90 | 90 | $this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement); |
91 | 91 | $this->sqlStatement->shouldReceive('execute'); |
92 | - $this->sqlStatement->shouldReceive('fetchAll')->once()->andReturn([new stdClass,new stdClass]); |
|
92 | + $this->sqlStatement->shouldReceive('fetchAll')->once()->andReturn([new stdClass, new stdClass]); |
|
93 | 93 | $this->sqlStatement->shouldReceive('rowCount')->once()->andReturn(1); |
94 | 94 | |
95 | 95 | $this->assertEquals(1, $this->model->create()); |