@@ -12,9 +12,9 @@ |
||
| 12 | 12 | { |
| 13 | 13 | $this->useDbEnv(); |
| 14 | 14 | |
| 15 | - $dsn = 'mysql:host='.$this->_host |
|
| 16 | - .';port='.$this->_port |
|
| 17 | - .';dbname='.$this->_database; |
|
| 15 | + $dsn = 'mysql:host=' . $this->_host |
|
| 16 | + .';port=' . $this->_port |
|
| 17 | + .';dbname=' . $this->_database; |
|
| 18 | 18 | |
| 19 | 19 | try { |
| 20 | 20 | $this->_pdo = new PDO($dsn, $this->_username, $this->_password); |
@@ -2,12 +2,12 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace Opeyemiabiodun\PotatoORM\Connections; |
| 4 | 4 | |
| 5 | -use PDO; |
|
| 6 | -use PDOException; |
|
| 7 | 5 | use InvalidArgumentException; |
| 8 | 6 | use Opeyemiabiodun\PotatoORM\Connections\Connection; |
| 9 | -use Opeyemiabiodun\PotatoORM\Connections\LoadEnvVariablesTrait; |
|
| 10 | 7 | use Opeyemiabiodun\PotatoORM\Connections\DatabaseTransactionsTrait; |
| 8 | +use Opeyemiabiodun\PotatoORM\Connections\LoadEnvVariablesTrait; |
|
| 9 | +use PDO; |
|
| 10 | +use PDOException; |
|
| 11 | 11 | |
| 12 | 12 | final class MySqlConnection implements Connection |
| 13 | 13 | { |
@@ -2,12 +2,12 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace Opeyemiabiodun\PotatoORM\Models; |
| 4 | 4 | |
| 5 | -use RuntimeException; |
|
| 6 | 5 | use InvalidArgumentException; |
| 7 | 6 | use Opeyemiabiodun\PotatoORM\Connections\Connection; |
| 8 | 7 | use Opeyemiabiodun\PotatoORM\Connections\PgSqlConnection; |
| 9 | 8 | use Opeyemiabiodun\PotatoORM\Exceptions\AssignmentException; |
| 10 | 9 | use Opeyemiabiodun\PotatoORM\Exceptions\PropertyNotFoundException; |
| 10 | +use RuntimeException; |
|
| 11 | 11 | |
| 12 | 12 | trait Model |
| 13 | 13 | { |
@@ -123,7 +123,7 @@ |
||
| 123 | 123 | * |
| 124 | 124 | * @param int $number Specifies which model instance to find; the 1st, 2nd, 3rd, ..... |
| 125 | 125 | * |
| 126 | - * @return array Returns the particular instance of the model. |
|
| 126 | + * @return Model Returns the particular instance of the model. |
|
| 127 | 127 | */ |
| 128 | 128 | public static function find($number) |
| 129 | 129 | { |
@@ -52,13 +52,13 @@ discard block |
||
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | if (null === $table) { |
| 55 | - $table = strtolower(substr(get_class($this),strripos(get_class($this), "\\") + 1))."_table"; |
|
| 55 | + $table = strtolower(substr(get_class($this), strripos(get_class($this), "\\") + 1)) . "_table"; |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | $this->setConnection($connection); |
| 59 | 59 | $this->setTable($table); |
| 60 | 60 | |
| 61 | - if (! empty($array)) { |
|
| 61 | + if (!empty($array)) { |
|
| 62 | 62 | $this->setProperties($array); |
| 63 | 63 | } |
| 64 | 64 | } |
@@ -87,14 +87,14 @@ discard block |
||
| 87 | 87 | */ |
| 88 | 88 | public function __set($property, $value) |
| 89 | 89 | { |
| 90 | - if (! is_scalar($value)) { |
|
| 90 | + if (!is_scalar($value)) { |
|
| 91 | 91 | throw new AssignmentException("{$value} is not a scalar value. Only scalar values can be assigned to the {$property} property."); |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | if (array_key_exists($property, self::$_attributes)) { |
| 95 | 95 | self::$_attributes[$property] = $value; |
| 96 | 96 | } else { |
| 97 | - throw new PropertyNotFoundException("The ".get_class($this)." instance has no {$property} property."); |
|
| 97 | + throw new PropertyNotFoundException("The " . get_class($this) . " instance has no {$property} property."); |
|
| 98 | 98 | } |
| 99 | 99 | } |
| 100 | 100 | |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | */ |
| 108 | 108 | public static function destroy($number) |
| 109 | 109 | { |
| 110 | - if (! is_int($number)) { |
|
| 110 | + if (!is_int($number)) { |
|
| 111 | 111 | throw new InvalidArgumentException("The parameter {$number} is not an integer. An integer is required instead."); |
| 112 | 112 | } |
| 113 | 113 | |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | */ |
| 128 | 128 | public static function find($number) |
| 129 | 129 | { |
| 130 | - if (! is_int($number)) { |
|
| 130 | + if (!is_int($number)) { |
|
| 131 | 131 | throw new InvalidArgumentException("The parameter {$number} is not an integer. An integer is required instead."); |
| 132 | 132 | } |
| 133 | 133 | |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | $hasAttributes = false; |
| 161 | 161 | |
| 162 | 162 | foreach (self::$_attributes as $key => $value) { |
| 163 | - if (! is_null($value)) { |
|
| 163 | + if (!is_null($value)) { |
|
| 164 | 164 | $hasAttributes = true; |
| 165 | 165 | } |
| 166 | 166 | } |
@@ -175,11 +175,11 @@ discard block |
||
| 175 | 175 | */ |
| 176 | 176 | public function save() |
| 177 | 177 | { |
| 178 | - if (! $this->hasAttributes()) { |
|
| 178 | + if (!$this->hasAttributes()) { |
|
| 179 | 179 | throw new RuntimeException("{get_class($this)} model has nothing to persist to the database."); |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | - $pk = (empty(self::$_attributes[self::$_primaryKey])) ? "NULL" : self::$_attributes[self::$_primaryKey]; |
|
| 182 | + $pk = (empty(self::$_attributes[self::$_primaryKey])) ? "NULL" : self::$_attributes[self::$_primaryKey]; |
|
| 183 | 183 | |
| 184 | 184 | $record = self::$_connection->findRecord(self::$_table, (string) $pk); |
| 185 | 185 | |
@@ -6,5 +6,5 @@ |
||
| 6 | 6 | |
| 7 | 7 | class User |
| 8 | 8 | { |
| 9 | - use Model; |
|
| 9 | + use Model; |
|
| 10 | 10 | } |
| 11 | 11 | \ No newline at end of file |
@@ -2,8 +2,8 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace Opeyemiabiodun\PotatoORM\Connections; |
| 4 | 4 | |
| 5 | -use Exception; |
|
| 6 | 5 | use Dotenv\Dotenv; |
| 6 | +use Exception; |
|
| 7 | 7 | use RuntimeException; |
| 8 | 8 | |
| 9 | 9 | trait LoadEnvVariablesTrait |
@@ -57,7 +57,7 @@ |
||
| 57 | 57 | */ |
| 58 | 58 | private function loadDbEnv() |
| 59 | 59 | { |
| 60 | - $dotenv = new Dotenv(__DIR__.'/../..'); |
|
| 60 | + $dotenv = new Dotenv(__DIR__ . '/../..'); |
|
| 61 | 61 | $dotenv->load(); |
| 62 | 62 | |
| 63 | 63 | $dotenv->required(['DB_HOST', 'DB_DATABASE', 'DB_USERNAME', 'DB_PASSWORD', 'DB_PORT'])->notEmpty(); |
@@ -2,13 +2,13 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace Opeyemiabiodun\PotatoORM\Connections; |
| 4 | 4 | |
| 5 | -use PDO; |
|
| 6 | -use PDOException; |
|
| 7 | -use RuntimeException; |
|
| 8 | 5 | use InvalidArgumentException; |
| 9 | 6 | use Opeyemiabiodun\PotatoORM\Connections\Connection; |
| 10 | -use Opeyemiabiodun\PotatoORM\Connections\LoadEnvVariablesTrait; |
|
| 11 | 7 | use Opeyemiabiodun\PotatoORM\Connections\DatabaseTransactionsTrait; |
| 8 | +use Opeyemiabiodun\PotatoORM\Connections\LoadEnvVariablesTrait; |
|
| 9 | +use PDO; |
|
| 10 | +use PDOException; |
|
| 11 | +use RuntimeException; |
|
| 12 | 12 | |
| 13 | 13 | final class PgSqlConnection implements Connection |
| 14 | 14 | { |
@@ -36,9 +36,9 @@ discard block |
||
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | if ($count > 0) { |
| 39 | - $sql = $sql."{$key}, "; |
|
| 39 | + $sql = $sql . "{$key}, "; |
|
| 40 | 40 | } else { |
| 41 | - $sql = $sql."{$key}) "; |
|
| 41 | + $sql = $sql . "{$key}) "; |
|
| 42 | 42 | } |
| 43 | 43 | } |
| 44 | 44 | |
@@ -54,9 +54,9 @@ discard block |
||
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | if ($count > 0) { |
| 57 | - $sql = (empty($value)) ? $sql."NULL, " : $sql."'{$value}', "; |
|
| 57 | + $sql = (empty($value)) ? $sql . "NULL, " : $sql . "'{$value}', "; |
|
| 58 | 58 | } else { |
| 59 | - $sql = (empty($value)) ? $sql."NULL " : $sql."'{$value}') "; |
|
| 59 | + $sql = (empty($value)) ? $sql . "NULL " : $sql . "'{$value}') "; |
|
| 60 | 60 | } |
| 61 | 61 | } |
| 62 | 62 | |
@@ -143,9 +143,9 @@ discard block |
||
| 143 | 143 | $sql = "UPDATE {$table} SET "; |
| 144 | 144 | foreach ($record as $key => $value) { |
| 145 | 145 | if ($count > 1) { |
| 146 | - $sql = $sql."{$key}={$value}, "; |
|
| 146 | + $sql = $sql . "{$key}={$value}, "; |
|
| 147 | 147 | } else { |
| 148 | - $sql = $sql."{$key}={$value} "; |
|
| 148 | + $sql = $sql . "{$key}={$value} "; |
|
| 149 | 149 | } |
| 150 | 150 | $count--; |
| 151 | 151 | } |