| @@ -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 @@ discard block | ||
| 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 |      { | 
| @@ -206,7 +206,7 @@ discard block | ||
| 206 | 206 | /** | 
| 207 | 207 | * Sets the model's connection. | 
| 208 | 208 | * | 
| 209 | - * @param Opeyemiabiodun\PotatoORM\Connections\Connection $connection An instance of Opeyemiabiodun\PotatoORM\Connections\Connection. | |
| 209 | + * @param Connection $connection An instance of Opeyemiabiodun\PotatoORM\Connections\Connection. | |
| 210 | 210 | */ | 
| 211 | 211 | protected function setConnection(Connection $connection) | 
| 212 | 212 |      { | 
| @@ -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 | } | 
| @@ -75,7 +75,7 @@ discard block | ||
| 75 | 75 |          if (array_key_exists($property, $this->_attributes)) { | 
| 76 | 76 | return $this->_attributes[$property]; | 
| 77 | 77 |          } else { | 
| 78 | -            throw new PropertyNotFoundException('The '.get_class($this)." instance has no {$property} property."); | |
| 78 | +            throw new PropertyNotFoundException('The ' . get_class($this) . " instance has no {$property} property."); | |
| 79 | 79 | } | 
| 80 | 80 | } | 
| 81 | 81 | |
| @@ -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("Only scalar values can be assigned to the {$property} property."); | 
| 92 | 92 | } | 
| 93 | 93 | |
| 94 | 94 |          if (array_key_exists($property, $this->_attributes)) { | 
| 95 | 95 | $this->_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 | |
| @@ -173,7 +173,7 @@ discard block | ||
| 173 | 173 | $hasAttributes = false; | 
| 174 | 174 | |
| 175 | 175 |          foreach ($this->_attributes as $key => $value) { | 
| 176 | -            if (! is_null($value)) { | |
| 176 | +            if (!is_null($value)) { | |
| 177 | 177 | $hasAttributes = true; | 
| 178 | 178 | } | 
| 179 | 179 | } | 
| @@ -188,11 +188,11 @@ discard block | ||
| 188 | 188 | */ | 
| 189 | 189 | public function save() | 
| 190 | 190 |      { | 
| 191 | -        if (! $this->hasAttributes()) { | |
| 192 | - throw new RuntimeException(get_class($this).' model has nothing to persist to the database.'); | |
| 191 | +        if (!$this->hasAttributes()) { | |
| 192 | + throw new RuntimeException(get_class($this) . ' model has nothing to persist to the database.'); | |
| 193 | 193 | } | 
| 194 | 194 | |
| 195 | - $pk = (empty($this->_attributes[self::$_primaryKey])) ? 'NULL' : $this->_attributes[self::$_primaryKey]; | |
| 195 | + $pk = (empty($this->_attributes[self::$_primaryKey])) ? 'NULL' : $this->_attributes[self::$_primaryKey]; | |
| 196 | 196 | |
| 197 | 197 | #$record = self::$_connection->findRecord(self::$_table, (string) $pk); | 
| 198 | 198 | |
| @@ -221,7 +221,7 @@ discard block | ||
| 221 | 221 | public function setProperties($array) | 
| 222 | 222 |      { | 
| 223 | 223 |          foreach ($this->_attributes as $key => $value) { | 
| 224 | -            if (! empty($array[$key])) { | |
| 224 | +            if (!empty($array[$key])) { | |
| 225 | 225 | $this->_attributes[$key] = $array[$key]; | 
| 226 | 226 | } | 
| 227 | 227 | } | 
| @@ -95,6 +95,9 @@ | ||
| 95 | 95 | return $this->keys[$table][0]; | 
| 96 | 96 | } | 
| 97 | 97 | |
| 98 | + /** | |
| 99 | + * @param string $table | |
| 100 | + */ | |
| 98 | 101 | private function loadColumnInfo($table) | 
| 99 | 102 |      { | 
| 100 | 103 |          $query     = "PRAGMA table_info('{$table}')"; | 
| @@ -2,9 +2,9 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace Opeyemiabiodun\PotatoORM\Connections; | 
| 4 | 4 | |
| 5 | +use InvalidArgumentException; | |
| 5 | 6 | use PDO; | 
| 6 | 7 | use PDOException; | 
| 7 | -use InvalidArgumentException; | |
| 8 | 8 | |
| 9 | 9 | final class SqliteConnection implements Connection | 
| 10 | 10 |  { | 
| @@ -16,6 +16,9 @@ | ||
| 16 | 16 |      { | 
| 17 | 17 | } | 
| 18 | 18 | |
| 19 | + /** | |
| 20 | + * @return Connection | |
| 21 | + */ | |
| 19 | 22 | public static function load() | 
| 20 | 23 |      { | 
| 21 | 24 | $dotenv = new Dotenv(__DIR__.'/../..'); | 
| @@ -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(); | 
| @@ -35,9 +35,9 @@ discard block | ||
| 35 | 35 | } | 
| 36 | 36 | |
| 37 | 37 |              if ($count > 0) { | 
| 38 | -                $sql = $sql."{$key}, "; | |
| 38 | +                $sql = $sql . "{$key}, "; | |
| 39 | 39 |              } else { | 
| 40 | -                $sql = $sql."{$key}) "; | |
| 40 | +                $sql = $sql . "{$key}) "; | |
| 41 | 41 | } | 
| 42 | 42 | } | 
| 43 | 43 | |
| @@ -52,9 +52,9 @@ discard block | ||
| 52 | 52 | } | 
| 53 | 53 | |
| 54 | 54 |              if ($count > 0) { | 
| 55 | -                $sql = (empty($value)) ? $sql.'NULL, ' : $sql."'{$value}', "; | |
| 55 | +                $sql = (empty($value)) ? $sql . 'NULL, ' : $sql . "'{$value}', "; | |
| 56 | 56 |              } else { | 
| 57 | -                $sql = (empty($value)) ? $sql.'NULL ' : $sql."'{$value}') "; | |
| 57 | +                $sql = (empty($value)) ? $sql . 'NULL ' : $sql . "'{$value}') "; | |
| 58 | 58 | } | 
| 59 | 59 | } | 
| 60 | 60 | |
| @@ -147,9 +147,9 @@ discard block | ||
| 147 | 147 | } | 
| 148 | 148 | |
| 149 | 149 |              if ($count > 0) { | 
| 150 | -                $sql = $sql."{$key}='{$value}', "; | |
| 150 | +                $sql = $sql . "{$key}='{$value}', "; | |
| 151 | 151 |              } else { | 
| 152 | -                $sql = $sql."{$key}='{$value}' "; | |
| 152 | +                $sql = $sql . "{$key}='{$value}' "; | |
| 153 | 153 | } | 
| 154 | 154 | } | 
| 155 | 155 |          $sql .= "WHERE {$this->getPrimaryKey($table)}='{$pk}'"; |