@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | * @param DB $db |
| 64 | 64 | * @param string $class |
| 65 | 65 | */ |
| 66 | - public function __construct (DB $db, string $class) { |
|
| 66 | + public function __construct(DB $db, string $class) { |
|
| 67 | 67 | $this->db = $db; |
| 68 | 68 | $this->class = $class; |
| 69 | 69 | try { |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | * @param PDOStatement $statement |
| 110 | 110 | * @return EntityInterface[] Enumerated |
| 111 | 111 | */ |
| 112 | - public function fetchAll (PDOStatement $statement): array { |
|
| 112 | + public function fetchAll(PDOStatement $statement): array { |
|
| 113 | 113 | $entities = []; |
| 114 | 114 | foreach ($statement->fetchAll() as $row) { |
| 115 | 115 | $clone = clone $this->proto; |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | * @param array[] $eavMatch Additional `[eav property => attribute => mixed]` |
| 130 | 130 | * @return Select |
| 131 | 131 | */ |
| 132 | - public function find (array $match, array $eavMatch = []): Select { |
|
| 132 | + public function find(array $match, array $eavMatch = []): Select { |
|
| 133 | 133 | $select = $this->select(); |
| 134 | 134 | foreach ($match as $column => $value) { |
| 135 | 135 | $select->where($this->db->match($column, $value)); |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | /** |
| 145 | 145 | * @return string |
| 146 | 146 | */ |
| 147 | - final public function getClass (): string { |
|
| 147 | + final public function getClass(): string { |
|
| 148 | 148 | return $this->class; |
| 149 | 149 | } |
| 150 | 150 | |
@@ -152,14 +152,14 @@ discard block |
||
| 152 | 152 | * @param string $property |
| 153 | 153 | * @return EAV |
| 154 | 154 | */ |
| 155 | - final public function getEav (string $property): EAV { |
|
| 155 | + final public function getEav(string $property): EAV { |
|
| 156 | 156 | return $this->eav[$property]; |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
| 160 | 160 | * @return EntityInterface |
| 161 | 161 | */ |
| 162 | - public function getProto (): EntityInterface { |
|
| 162 | + public function getProto(): EntityInterface { |
|
| 163 | 163 | return $this->proto; |
| 164 | 164 | } |
| 165 | 165 | |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | * @param EntityInterface $entity |
| 168 | 168 | * @return array |
| 169 | 169 | */ |
| 170 | - protected function getValues (EntityInterface $entity): array { |
|
| 170 | + protected function getValues(EntityInterface $entity): array { |
|
| 171 | 171 | $values = []; |
| 172 | 172 | foreach (array_keys($this->columns) as $name) { |
| 173 | 173 | $values[$name] = $this->properties[$name]->getValue($entity); |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | * @param int $id |
| 182 | 182 | * @return null|EntityInterface |
| 183 | 183 | */ |
| 184 | - public function load (int $id): ?EntityInterface { |
|
| 184 | + public function load(int $id): ?EntityInterface { |
|
| 185 | 185 | $load = $this->cache(__FUNCTION__, function() { |
| 186 | 186 | return $this->select()->where('id=:id')->prepare(); |
| 187 | 187 | }); |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | * |
| 201 | 201 | * @param EntityInterface[] $entities |
| 202 | 202 | */ |
| 203 | - protected function loadEav (array $entities): void { |
|
| 203 | + protected function loadEav(array $entities): void { |
|
| 204 | 204 | $ids = array_keys($entities); |
| 205 | 205 | foreach ($this->eav as $name => $eav) { |
| 206 | 206 | foreach ($eav->loadAll($ids) as $id => $values) { |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | * @param EntityInterface $entity |
| 216 | 216 | * @return int ID |
| 217 | 217 | */ |
| 218 | - public function save (EntityInterface $entity): int { |
|
| 218 | + public function save(EntityInterface $entity): int { |
|
| 219 | 219 | if (!$entity->getId()) { |
| 220 | 220 | $this->saveInsert($entity); |
| 221 | 221 | } |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | /** |
| 230 | 230 | * @param EntityInterface $entity |
| 231 | 231 | */ |
| 232 | - protected function saveEav (EntityInterface $entity): void { |
|
| 232 | + protected function saveEav(EntityInterface $entity): void { |
|
| 233 | 233 | $id = $entity->getId(); |
| 234 | 234 | foreach ($this->eav as $name => $eav) { |
| 235 | 235 | $values = $this->properties[$name]->getValue($entity); |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | * |
| 245 | 245 | * @param EntityInterface $entity |
| 246 | 246 | */ |
| 247 | - protected function saveInsert (EntityInterface $entity): void { |
|
| 247 | + protected function saveInsert(EntityInterface $entity): void { |
|
| 248 | 248 | $insert = $this->cache(__FUNCTION__, function() { |
| 249 | 249 | $slots = SQL::slots(array_keys($this->columns)); |
| 250 | 250 | unset($slots['id']); |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | * |
| 264 | 264 | * @param EntityInterface $entity |
| 265 | 265 | */ |
| 266 | - protected function saveUpdate (EntityInterface $entity): void { |
|
| 266 | + protected function saveUpdate(EntityInterface $entity): void { |
|
| 267 | 267 | $this->cache(__FUNCTION__, function() { |
| 268 | 268 | $slots = SQL::slots(array_keys($this->columns)); |
| 269 | 269 | unset($slots['id']); |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | * @param array $columns Defaults to all columns. |
| 279 | 279 | * @return Select |
| 280 | 280 | */ |
| 281 | - public function select (array $columns = []): Select { |
|
| 281 | + public function select(array $columns = []): Select { |
|
| 282 | 282 | $select = parent::select($columns); |
| 283 | 283 | $select->setFetcher(function(PDOStatement $statement) { |
| 284 | 284 | return $this->fetchAll($statement); |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | * @param EntityInterface $proto |
| 291 | 291 | * @return $this |
| 292 | 292 | */ |
| 293 | - public function setProto (EntityInterface $proto) { |
|
| 293 | + public function setProto(EntityInterface $proto) { |
|
| 294 | 294 | $this->proto = $proto; |
| 295 | 295 | return $this; |
| 296 | 296 | } |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | * @param EntityInterface $entity |
| 300 | 300 | * @param array $values |
| 301 | 301 | */ |
| 302 | - protected function setValues (EntityInterface $entity, array $values): void { |
|
| 302 | + protected function setValues(EntityInterface $entity, array $values): void { |
|
| 303 | 303 | foreach ($values as $name => $value) { |
| 304 | 304 | settype($value, $this->types[$name]); |
| 305 | 305 | $this->properties[$name]->setValue($entity, $value); |
@@ -70,8 +70,7 @@ |
||
| 70 | 70 | public function is ($arg): string { |
| 71 | 71 | if ($arg === null or is_bool($arg)) { |
| 72 | 72 | $arg = ['' => 'NULL', 1 => 'TRUE', 0 => 'FALSE'][$arg]; |
| 73 | - } |
|
| 74 | - else { |
|
| 73 | + } else { |
|
| 75 | 74 | $arg = $this->db->quote($arg); |
| 76 | 75 | } |
| 77 | 76 | $operator = ['mysql' => '<=>', 'sqlite' => 'IS'][$this->db->getDriver()]; |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | /** |
| 23 | 23 | * @return array |
| 24 | 24 | */ |
| 25 | - public function getAttributes (): array { |
|
| 25 | + public function getAttributes(): array { |
|
| 26 | 26 | return $this->attributes ?: []; |
| 27 | 27 | } |
| 28 | 28 | |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | * @param mixed $offset |
| 31 | 31 | * @return bool |
| 32 | 32 | */ |
| 33 | - public function offsetExists ($offset): bool { |
|
| 33 | + public function offsetExists($offset): bool { |
|
| 34 | 34 | return $this->attributes and array_key_exists($offset, $this->attributes); |
| 35 | 35 | } |
| 36 | 36 | |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | * @param mixed $offset |
| 39 | 39 | * @return mixed Returns `NULL` for nonexistent attributes. |
| 40 | 40 | */ |
| 41 | - public function offsetGet ($offset) { |
|
| 41 | + public function offsetGet($offset) { |
|
| 42 | 42 | return $this->attributes[$offset] ?? null; |
| 43 | 43 | } |
| 44 | 44 | |
@@ -46,14 +46,14 @@ discard block |
||
| 46 | 46 | * @param mixed $offset |
| 47 | 47 | * @param mixed $value |
| 48 | 48 | */ |
| 49 | - public function offsetSet ($offset, $value): void { |
|
| 49 | + public function offsetSet($offset, $value): void { |
|
| 50 | 50 | $this->attributes[$offset] = $value; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
| 54 | 54 | * @param mixed $offset |
| 55 | 55 | */ |
| 56 | - public function offsetUnset ($offset): void { |
|
| 56 | + public function offsetUnset($offset): void { |
|
| 57 | 57 | unset($this->attributes[$offset]); |
| 58 | 58 | } |
| 59 | 59 | |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | * @param array $attributes |
| 62 | 62 | * @return $this |
| 63 | 63 | */ |
| 64 | - public function setAttributes (array $attributes) { |
|
| 64 | + public function setAttributes(array $attributes) { |
|
| 65 | 65 | $this->attributes = $attributes; |
| 66 | 66 | return $this; |
| 67 | 67 | } |
@@ -10,5 +10,5 @@ |
||
| 10 | 10 | /** |
| 11 | 11 | * @return int |
| 12 | 12 | */ |
| 13 | - public function getId (); |
|
| 13 | + public function getId(); |
|
| 14 | 14 | } |
| 15 | 15 | \ No newline at end of file |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * @param string $passwd |
| 48 | 48 | * @param array $options |
| 49 | 49 | */ |
| 50 | - public function __construct ($dsn, $username = null, $passwd = null, $options = null) { |
|
| 50 | + public function __construct($dsn, $username = null, $passwd = null, $options = null) { |
|
| 51 | 51 | parent::__construct(...func_get_args()); |
| 52 | 52 | $this->setAttribute(self::ATTR_ERRMODE, self::ERRMODE_EXCEPTION); |
| 53 | 53 | $this->setAttribute(self::ATTR_DEFAULT_FETCH_MODE, self::FETCH_ASSOC); |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | * @param string $sql |
| 64 | 64 | * @return int |
| 65 | 65 | */ |
| 66 | - public function exec ($sql) { |
|
| 66 | + public function exec($sql) { |
|
| 67 | 67 | $this->logger->__invoke($sql); |
| 68 | 68 | return parent::exec($sql); |
| 69 | 69 | } |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | * |
| 74 | 74 | * @return string |
| 75 | 75 | */ |
| 76 | - final public function getDriver () { |
|
| 76 | + final public function getDriver() { |
|
| 77 | 77 | return $this->getAttribute(self::ATTR_DRIVER_NAME); |
| 78 | 78 | } |
| 79 | 79 | |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | * @param string $interface |
| 84 | 84 | * @return Junction |
| 85 | 85 | */ |
| 86 | - public function getJunction ($interface) { |
|
| 86 | + public function getJunction($interface) { |
|
| 87 | 87 | if (!isset($this->junctions[$interface])) { |
| 88 | 88 | $this->junctions[$interface] = new Junction($this, $interface); |
| 89 | 89 | } |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | * @param string|EntityInterface $class |
| 97 | 97 | * @return Record |
| 98 | 98 | */ |
| 99 | - public function getRecord ($class) { |
|
| 99 | + public function getRecord($class) { |
|
| 100 | 100 | if (is_object($class)) { |
| 101 | 101 | $class = get_class($class); |
| 102 | 102 | } |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | * @param string|array|Select|Closure $b |
| 129 | 129 | * @return string|string[] Same type as `$a`, keys are not preserved. |
| 130 | 130 | */ |
| 131 | - public function match ($a, $b = null) { |
|
| 131 | + public function match($a, $b = null) { |
|
| 132 | 132 | if (is_array($a)) { |
| 133 | 133 | return array_map([$this, __FUNCTION__], array_keys($a), $a); |
| 134 | 134 | } |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | * @param string $access Class or interface name. |
| 146 | 146 | * @return bool |
| 147 | 147 | */ |
| 148 | - public function offsetExists ($access) { |
|
| 148 | + public function offsetExists($access) { |
|
| 149 | 149 | return (bool)$this->offsetGet($access); |
| 150 | 150 | } |
| 151 | 151 | |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | * @param string $access Class or interface name. |
| 154 | 154 | * @return Record|Junction|null |
| 155 | 155 | */ |
| 156 | - public function offsetGet ($access) { |
|
| 156 | + public function offsetGet($access) { |
|
| 157 | 157 | if (class_exists($access)) { |
| 158 | 158 | return $this->getRecord($access); |
| 159 | 159 | } |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | * @param void $value |
| 171 | 171 | * @throws Exception |
| 172 | 172 | */ |
| 173 | - final public function offsetSet ($access, $value) { |
|
| 173 | + final public function offsetSet($access, $value) { |
|
| 174 | 174 | throw new Exception('The schema cannot be altered by ArrayAccess.'); |
| 175 | 175 | } |
| 176 | 176 | |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | * @param void $access |
| 181 | 181 | * @throws Exception |
| 182 | 182 | */ |
| 183 | - final public function offsetUnset ($access) { |
|
| 183 | + final public function offsetUnset($access) { |
|
| 184 | 184 | $this->offsetSet($access, null); |
| 185 | 185 | } |
| 186 | 186 | |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | * @param array $options |
| 192 | 192 | * @return PDOStatement |
| 193 | 193 | */ |
| 194 | - public function prepare ($sql, $options = null) { |
|
| 194 | + public function prepare($sql, $options = null) { |
|
| 195 | 195 | $this->logger->__invoke($sql); |
| 196 | 196 | return parent::prepare(...func_get_args()); |
| 197 | 197 | } |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | * @param array $ctorargs |
| 206 | 206 | * @return PDOStatement |
| 207 | 207 | */ |
| 208 | - public function query ($sql, $mode = PDO::ATTR_DEFAULT_FETCH_MODE, $arg3 = null, array $ctorargs = []) { |
|
| 208 | + public function query($sql, $mode = PDO::ATTR_DEFAULT_FETCH_MODE, $arg3 = null, array $ctorargs = []) { |
|
| 209 | 209 | $this->logger->__invoke($sql); |
| 210 | 210 | return parent::query(...func_get_args()); |
| 211 | 211 | } |
@@ -228,7 +228,7 @@ discard block |
||
| 228 | 228 | * @param int $type Ignored. |
| 229 | 229 | * @return mixed |
| 230 | 230 | */ |
| 231 | - public function quote ($value, $type = null) { |
|
| 231 | + public function quote($value, $type = null) { |
|
| 232 | 232 | if ($value instanceof Column) { |
| 233 | 233 | return (string)$value; |
| 234 | 234 | } |
@@ -253,14 +253,14 @@ discard block |
||
| 253 | 253 | * @param EntityInterface $entity |
| 254 | 254 | * @return int ID |
| 255 | 255 | */ |
| 256 | - public function save (EntityInterface $entity) { |
|
| 256 | + public function save(EntityInterface $entity) { |
|
| 257 | 257 | return $this->getRecord($entity)->save($entity); |
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | /** |
| 261 | 261 | * @param Closure $logger |
| 262 | 262 | */ |
| 263 | - public function setLogger (Closure $logger) { |
|
| 263 | + public function setLogger(Closure $logger) { |
|
| 264 | 264 | $this->logger = $logger; |
| 265 | 265 | } |
| 266 | 266 | } |
| 267 | 267 | \ No newline at end of file |