@@ -203,7 +203,7 @@ |
||
203 | 203 | /** |
204 | 204 | * Save the model data to the database. |
205 | 205 | * |
206 | - * @return bool |
|
206 | + * @return integer |
|
207 | 207 | */ |
208 | 208 | public function save() |
209 | 209 | { |
@@ -24,23 +24,23 @@ discard block |
||
24 | 24 | */ |
25 | 25 | protected $databaseConnection; |
26 | 26 | |
27 | - /** |
|
28 | - * The id of the model. |
|
29 | - * |
|
30 | - * @property string $id |
|
31 | - */ |
|
32 | - |
|
33 | - /** |
|
34 | - * Create a model instance. |
|
35 | - */ |
|
36 | - public function __construct(DatabaseConnectionInterface $databaseConnection = null) |
|
37 | - { |
|
27 | + /** |
|
28 | + * The id of the model. |
|
29 | + * |
|
30 | + * @property string $id |
|
31 | + */ |
|
32 | + |
|
33 | + /** |
|
34 | + * Create a model instance. |
|
35 | + */ |
|
36 | + public function __construct(DatabaseConnectionInterface $databaseConnection = null) |
|
37 | + { |
|
38 | 38 | if ($databaseConnection == null) { |
39 | 39 | $this->databaseConnection = DatabaseConnection::getInstance()->databaseConnection; |
40 | 40 | } else { |
41 | 41 | $this->databaseConnection = $databaseConnection; |
42 | 42 | } |
43 | - } |
|
43 | + } |
|
44 | 44 | |
45 | 45 | /** |
46 | 46 | * Sets into $properties the $key => $value pairs. |
@@ -65,23 +65,23 @@ discard block |
||
65 | 65 | } |
66 | 66 | } |
67 | 67 | |
68 | - /** |
|
69 | - * Get all the model properties. |
|
70 | - * |
|
71 | - * @return array |
|
72 | - */ |
|
73 | - public function getProperties() |
|
74 | - { |
|
75 | - return $this->properties; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Set model properties. |
|
80 | - */ |
|
81 | - public function setProperties(array $properties) |
|
82 | - { |
|
83 | - $this->properties = $properties; |
|
84 | - } |
|
68 | + /** |
|
69 | + * Get all the model properties. |
|
70 | + * |
|
71 | + * @return array |
|
72 | + */ |
|
73 | + public function getProperties() |
|
74 | + { |
|
75 | + return $this->properties; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Set model properties. |
|
80 | + */ |
|
81 | + public function setProperties(array $properties) |
|
82 | + { |
|
83 | + $this->properties = $properties; |
|
84 | + } |
|
85 | 85 | |
86 | 86 | /** |
87 | 87 | * Pluralize the name of the child class. |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | */ |
61 | 61 | public function __get($key) |
62 | 62 | { |
63 | - if(isset($this->properties[$key])){ |
|
63 | + if (isset($this->properties[$key])) { |
|
64 | 64 | return $this->properties[$key]; |
65 | 65 | } |
66 | 66 | } |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | */ |
91 | 91 | public function getTableName() |
92 | 92 | { |
93 | - if(isset($this->table) && !empty($this->table)) { |
|
93 | + if (isset($this->table) && !empty($this->table)) { |
|
94 | 94 | |
95 | 95 | return $this->table; |
96 | 96 | } |
@@ -167,17 +167,17 @@ discard block |
||
167 | 167 | public function update() |
168 | 168 | { |
169 | 169 | $bindNameParameters = []; |
170 | - $sqlUpdate = 'UPDATE '.$this->getTableName().' SET '; |
|
170 | + $sqlUpdate = 'UPDATE ' . $this->getTableName() . ' SET '; |
|
171 | 171 | foreach ($this->properties as $columnName => $columnValue) { |
172 | 172 | if ($columnName == 'id') { |
173 | 173 | continue; |
174 | 174 | } |
175 | - $bindColumnName = ':'.$columnName; |
|
175 | + $bindColumnName = ':' . $columnName; |
|
176 | 176 | $sqlUpdate .= "$columnName = $bindColumnName,"; |
177 | 177 | $bindNameParameters[$bindColumnName] = $columnValue; |
178 | 178 | } |
179 | 179 | //Remove the last comma in sql command then join it to the other query part. |
180 | - $sqlUpdate = substr($sqlUpdate, 0, -1).' WHERE id = :id'; |
|
180 | + $sqlUpdate = substr($sqlUpdate, 0, -1) . ' WHERE id = :id'; |
|
181 | 181 | $sqlStatement = $this->databaseConnection->prepare($sqlUpdate); |
182 | 182 | $bindNameParameters[':id'] = $this->properties['id']; |
183 | 183 | $sqlStatement->execute($bindNameParameters); |
@@ -195,18 +195,18 @@ discard block |
||
195 | 195 | $columnNames = ''; |
196 | 196 | $columnValues = ''; |
197 | 197 | $bindNameParameters = []; |
198 | - $sqlCreate = 'INSERT'.' INTO '.$this->getTableName().' ('; |
|
198 | + $sqlCreate = 'INSERT' . ' INTO ' . $this->getTableName() . ' ('; |
|
199 | 199 | foreach ($this->properties as $columnName => $columnValue) { |
200 | - $bindColumnName = ':'.$columnName; |
|
201 | - $columnNames .= $columnName.','; |
|
202 | - $columnValues .= $bindColumnName.','; |
|
200 | + $bindColumnName = ':' . $columnName; |
|
201 | + $columnNames .= $columnName . ','; |
|
202 | + $columnValues .= $bindColumnName . ','; |
|
203 | 203 | $bindNameParameters[$bindColumnName] = $columnValue; |
204 | 204 | } |
205 | 205 | // Remove ending comma and whitespace. |
206 | 206 | $columnNames = substr($columnNames, 0, -1); |
207 | 207 | $columnValues = substr($columnValues, 0, -1); |
208 | 208 | |
209 | - $sqlCreate .= $columnNames.') VALUES ('.$columnValues.')'; |
|
209 | + $sqlCreate .= $columnNames . ') VALUES (' . $columnValues . ')'; |
|
210 | 210 | $sqlStatement = $this->databaseConnection->prepare($sqlCreate); |
211 | 211 | $sqlStatement->execute($bindNameParameters); |
212 | 212 | |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | */ |
247 | 247 | public function delete($id) |
248 | 248 | { |
249 | - $sql = 'DELETE'.' FROM '.self::getTableName().' WHERE id = '.$id; |
|
249 | + $sql = 'DELETE' . ' FROM ' . self::getTableName() . ' WHERE id = ' . $id; |
|
250 | 250 | $sqlStatment = $this->databaseConnection->prepare($sql); |
251 | 251 | $sqlStatment->execute(); |
252 | 252 |
@@ -22,16 +22,16 @@ |
||
22 | 22 | |
23 | 23 | switch ($driver) { |
24 | 24 | case 'sqlite': |
25 | - $dsn = $driver.'::memory:'; |
|
25 | + $dsn = $driver . '::memory:'; |
|
26 | 26 | break; |
27 | 27 | case 'mysql': |
28 | 28 | case 'postgres': |
29 | 29 | if (strcasecmp($driver, 'postgres') == 0) { |
30 | 30 | $driver = 'pgsql'; |
31 | 31 | } |
32 | - $dsn = $driver.':host='.$config['HOSTNAME'].';dbname='.$config['DBNAME']; |
|
32 | + $dsn = $driver . ':host=' . $config['HOSTNAME'] . ';dbname=' . $config['DBNAME']; |
|
33 | 33 | if (isset($config['PORT'])) { |
34 | - $dsn .= ';port='.$config['PORT']; |
|
34 | + $dsn .= ';port=' . $config['PORT']; |
|
35 | 35 | } |
36 | 36 | break; |
37 | 37 | default: |
@@ -7,6 +7,6 @@ |
||
7 | 7 | { |
8 | 8 | public function __construct($id) |
9 | 9 | { |
10 | - parent::__construct('The requested Model with '.$id.' does not exist'); |
|
10 | + parent::__construct('The requested Model with ' . $id . ' does not exist'); |
|
11 | 11 | } |
12 | 12 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | m::mock('Pyjac\ORM\DatabaseConnectionStringFactoryInterface'); |
22 | 22 | |
23 | 23 | $databaseConnectionStringFactory->shouldReceive('createDatabaseSourceString') |
24 | - ->with(['DRIVER' => 'sqlite', 'HOSTNAME' => '127.0.0.1', 'USERNAME' => '', 'PASSWORD' => '', 'DBNAME' => 'potatoORM', 'PORT' => '54320'])->once()->andReturn('sqlite::memory:'); |
|
24 | + ->with(['DRIVER' => 'sqlite', 'HOSTNAME' => '127.0.0.1', 'USERNAME' => '', 'PASSWORD' => '', 'DBNAME' => 'potatoORM', 'PORT' => '54320'])->once()->andReturn('sqlite::memory:'); |
|
25 | 25 | |
26 | 26 | $this->databaseConnection = m::mock('Pyjac\ORM\DatabaseConnection'); |
27 | 27 | |
@@ -36,8 +36,8 @@ discard block |
||
36 | 36 | { |
37 | 37 | $this->databaseConnection->shouldReceive('createConnection')->with('sqlite::memory:')->once()->andReturn(''); |
38 | 38 | $this->model->expects($this->any()) |
39 | - ->method('getTableName') |
|
40 | - ->will($this->returnValue(strtolower(get_class($this->model).'s'))); |
|
39 | + ->method('getTableName') |
|
40 | + ->will($this->returnValue(strtolower(get_class($this->model).'s'))); |
|
41 | 41 | |
42 | 42 | $this->assertEquals($this->model->getTableName(), strtolower(get_class($this->model).'s')); |
43 | 43 | } |
@@ -37,9 +37,9 @@ |
||
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() |
@@ -15,7 +15,7 @@ |
||
15 | 15 | $databaseConnectionStringFactory = |
16 | 16 | m::mock('Pyjac\ORM\DatabaseConnectionStringFactoryInterface'); |
17 | 17 | $databaseConnectionStringFactory->shouldReceive('createDatabaseSourceString') |
18 | - ->with(['DRIVER' => 'sqlite', 'HOSTNAME' => '127.0.0.1', 'USERNAME' => '', 'PASSWORD' => '', 'DBNAME' => 'potatoORM', 'PORT' => '54320'])->once()->andReturn('sqlite::memory:'); |
|
18 | + ->with(['DRIVER' => 'sqlite', 'HOSTNAME' => '127.0.0.1', 'USERNAME' => '', 'PASSWORD' => '', 'DBNAME' => 'potatoORM', 'PORT' => '54320'])->once()->andReturn('sqlite::memory:'); |
|
19 | 19 | |
20 | 20 | $this->databaseConnection = new DatabaseConnection($databaseConnectionStringFactory); |
21 | 21 | } |
@@ -160,16 +160,16 @@ |
||
160 | 160 | ]); |
161 | 161 | } |
162 | 162 | |
163 | - /** |
|
164 | - * Load needed configuration values from the .env file using Dotenv. |
|
165 | - * |
|
166 | - * @return void |
|
167 | - */ |
|
168 | - public function loadEnv() |
|
169 | - { |
|
170 | - if (!getenv('APP_ENV')) { |
|
171 | - $dotenv = new \Dotenv\Dotenv(__DIR__.'/../../../'); |
|
172 | - $dotenv->overload(); |
|
173 | - } |
|
174 | - } |
|
163 | + /** |
|
164 | + * Load needed configuration values from the .env file using Dotenv. |
|
165 | + * |
|
166 | + * @return void |
|
167 | + */ |
|
168 | + public function loadEnv() |
|
169 | + { |
|
170 | + if (!getenv('APP_ENV')) { |
|
171 | + $dotenv = new \Dotenv\Dotenv(__DIR__.'/../../../'); |
|
172 | + $dotenv->overload(); |
|
173 | + } |
|
174 | + } |
|
175 | 175 | } |
@@ -168,7 +168,7 @@ |
||
168 | 168 | public function loadEnv() |
169 | 169 | { |
170 | 170 | if (!getenv('APP_ENV')) { |
171 | - $dotenv = new \Dotenv\Dotenv(__DIR__.'/../../../'); |
|
171 | + $dotenv = new \Dotenv\Dotenv(__DIR__ . '/../../../'); |
|
172 | 172 | $dotenv->overload(); |
173 | 173 | } |
174 | 174 | } |
@@ -6,7 +6,7 @@ |
||
6 | 6 | |
7 | 7 | class User extends Model |
8 | 8 | { |
9 | - //protected $table = 'users'; |
|
9 | + //protected $table = 'users'; |
|
10 | 10 | } |
11 | 11 | |
12 | 12 |