@@ -35,8 +35,7 @@ |
||
| 35 | 35 | $this->interface = $interface; |
| 36 | 36 | try { |
| 37 | 37 | $interface = new ReflectionClass($interface); |
| 38 | - } |
|
| 39 | - catch (ReflectionException $exception) { |
|
| 38 | + } catch (ReflectionException $exception) { |
|
| 40 | 39 | throw new LogicException('Unexpected ReflectionException', 0, $exception); |
| 41 | 40 | } |
| 42 | 41 | $doc = $interface->getDocComment(); |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | * @param DB $db |
| 33 | 33 | * @param string $interface |
| 34 | 34 | */ |
| 35 | - public function __construct (DB $db, string $interface) { |
|
| 35 | + public function __construct(DB $db, string $interface) { |
|
| 36 | 36 | $this->interface = $interface; |
| 37 | 37 | try { |
| 38 | 38 | $interface = new ReflectionClass($interface); |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | * @param EntityInterface $entity |
| 59 | 59 | * @return int |
| 60 | 60 | */ |
| 61 | - public function count (EntityInterface $entity): int { |
|
| 61 | + public function count(EntityInterface $entity): int { |
|
| 62 | 62 | $key = $this->getKey($entity); |
| 63 | 63 | $count = $this->cache("count.{$key}", function() use ($key) { |
| 64 | 64 | return $this->select(['COUNT(*)'])->where("{$key} = ?")->prepare(); |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | * @param string $class |
| 76 | 76 | * @return Select |
| 77 | 77 | */ |
| 78 | - public function getCollection (EntityInterface $owner, string $class): Select { |
|
| 78 | + public function getCollection(EntityInterface $owner, string $class): Select { |
|
| 79 | 79 | $record = $this->db->getRecord($class); |
| 80 | 80 | $select = $record->select(); |
| 81 | 81 | $select->join($this, $this[$class]->isEqual($record['id'])); |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | /** |
| 87 | 87 | * @return string |
| 88 | 88 | */ |
| 89 | - final public function getInterface (): string { |
|
| 89 | + final public function getInterface(): string { |
|
| 90 | 90 | return $this->interface; |
| 91 | 91 | } |
| 92 | 92 | |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | * @param EntityInterface|string $class |
| 97 | 97 | * @return string |
| 98 | 98 | */ |
| 99 | - public function getKey ($class): string { |
|
| 99 | + public function getKey($class): string { |
|
| 100 | 100 | if (is_object($class)) { |
| 101 | 101 | $class = get_class($class); |
| 102 | 102 | } |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | * @param EntityInterface[] $entities |
| 115 | 115 | * @return int Rows affected. |
| 116 | 116 | */ |
| 117 | - public function link (array $entities): int { |
|
| 117 | + public function link(array $entities): int { |
|
| 118 | 118 | $link = $this->cache(__FUNCTION__, function() { |
| 119 | 119 | $slots = implode(',', SQL::slots($this->keys)); |
| 120 | 120 | $columns = implode(',', $this->keys); |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | * @param string $name |
| 137 | 137 | * @return bool |
| 138 | 138 | */ |
| 139 | - public function offsetExists ($name): bool { |
|
| 139 | + public function offsetExists($name): bool { |
|
| 140 | 140 | return isset($this->columns[$name]) or isset($this->keys[$name]); |
| 141 | 141 | } |
| 142 | 142 | |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | * @param string $name |
| 147 | 147 | * @return Column |
| 148 | 148 | */ |
| 149 | - public function offsetGet ($name): Column { |
|
| 149 | + public function offsetGet($name): Column { |
|
| 150 | 150 | return $this->columns[$name] ?? $this->columns[$this->keys[$name]]; |
| 151 | 151 | } |
| 152 | 152 | |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | * @param EntityInterface[] $entities |
| 160 | 160 | * @return int Rows affected. |
| 161 | 161 | */ |
| 162 | - public function unlink (array $entities): int { |
|
| 162 | + public function unlink(array $entities): int { |
|
| 163 | 163 | $unlink = $this->cache(__FUNCTION__, function() { |
| 164 | 164 | $slots = Predicate::all(SQL::slotsEqual($this->keys)); |
| 165 | 165 | return $this->db->prepare("DELETE FROM {$this} WHERE {$slots}"); |
@@ -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 |
@@ -66,8 +66,7 @@ discard block |
||
| 66 | 66 | $this->class = $class; |
| 67 | 67 | try { |
| 68 | 68 | $class = new ReflectionClass($class); |
| 69 | - } |
|
| 70 | - catch (ReflectionException $exception) { |
|
| 69 | + } catch (ReflectionException $exception) { |
|
| 71 | 70 | throw new LogicException('Unexpected ReflectionException', 0, $exception); |
| 72 | 71 | } |
| 73 | 72 | $this->proto = $class->newInstanceWithoutConstructor(); |
@@ -84,8 +83,7 @@ discard block |
||
| 84 | 83 | if (preg_match('/@var\s+(?<type>[a-z]+)[\s$]/', $doc, $match)) { |
| 85 | 84 | $types[$name] = $match['type']; |
| 86 | 85 | } |
| 87 | - } |
|
| 88 | - elseif (preg_match('/@eav\s+(?<table>\S+)/', $doc, $match)) { |
|
| 86 | + } elseif (preg_match('/@eav\s+(?<table>\S+)/', $doc, $match)) { |
|
| 89 | 87 | $eav[$name] = $match['table']; |
| 90 | 88 | $this->properties[$name] = $property; |
| 91 | 89 | } |
@@ -213,8 +211,7 @@ discard block |
||
| 213 | 211 | public function save (EntityInterface $entity): int { |
| 214 | 212 | if (!$entity->getId()) { |
| 215 | 213 | $this->saveInsert($entity); |
| 216 | - } |
|
| 217 | - else { |
|
| 214 | + } else { |
|
| 218 | 215 | $this->saveUpdate($entity); |
| 219 | 216 | } |
| 220 | 217 | $this->saveEav($entity); |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | * @param DB $db |
| 63 | 63 | * @param string $class |
| 64 | 64 | */ |
| 65 | - public function __construct (DB $db, string $class) { |
|
| 65 | + public function __construct(DB $db, string $class) { |
|
| 66 | 66 | $this->class = $class; |
| 67 | 67 | try { |
| 68 | 68 | $class = new ReflectionClass($class); |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | * @param Statement $statement |
| 106 | 106 | * @return EntityInterface[] Enumerated |
| 107 | 107 | */ |
| 108 | - public function fetchAll (Statement $statement): array { |
|
| 108 | + public function fetchAll(Statement $statement): array { |
|
| 109 | 109 | $entities = []; |
| 110 | 110 | foreach ($statement->fetchAll() as $row) { |
| 111 | 111 | $clone = clone $this->proto; |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | * @param array[] $eavMatch Additional `[eav property => attribute => mixed]` |
| 126 | 126 | * @return Select |
| 127 | 127 | */ |
| 128 | - public function find (array $match, array $eavMatch = []): Select { |
|
| 128 | + public function find(array $match, array $eavMatch = []): Select { |
|
| 129 | 129 | $select = $this->select(); |
| 130 | 130 | foreach ($match as $column => $value) { |
| 131 | 131 | $select->where($this->db->match($column, $value)); |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | /** |
| 141 | 141 | * @return string |
| 142 | 142 | */ |
| 143 | - final public function getClass (): string { |
|
| 143 | + final public function getClass(): string { |
|
| 144 | 144 | return $this->class; |
| 145 | 145 | } |
| 146 | 146 | |
@@ -148,14 +148,14 @@ discard block |
||
| 148 | 148 | * @param string $property |
| 149 | 149 | * @return EAV |
| 150 | 150 | */ |
| 151 | - final public function getEav (string $property): EAV { |
|
| 151 | + final public function getEav(string $property): EAV { |
|
| 152 | 152 | return $this->eav[$property]; |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | /** |
| 156 | 156 | * @return EntityInterface |
| 157 | 157 | */ |
| 158 | - public function getProto (): EntityInterface { |
|
| 158 | + public function getProto(): EntityInterface { |
|
| 159 | 159 | return $this->proto; |
| 160 | 160 | } |
| 161 | 161 | |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | * @param EntityInterface $entity |
| 164 | 164 | * @return array |
| 165 | 165 | */ |
| 166 | - protected function getValues (EntityInterface $entity): array { |
|
| 166 | + protected function getValues(EntityInterface $entity): array { |
|
| 167 | 167 | $values = []; |
| 168 | 168 | foreach (array_keys($this->columns) as $name) { |
| 169 | 169 | $values[$name] = $this->properties[$name]->getValue($entity); |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | * @param int $id |
| 178 | 178 | * @return null|EntityInterface |
| 179 | 179 | */ |
| 180 | - public function load (int $id): ?EntityInterface { |
|
| 180 | + public function load(int $id): ?EntityInterface { |
|
| 181 | 181 | $load = $this->cache(__FUNCTION__, function() { |
| 182 | 182 | return $this->select(array_keys($this->columns))->where('id = ?')->prepare(); |
| 183 | 183 | }); |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | * |
| 196 | 196 | * @param EntityInterface[] $entities |
| 197 | 197 | */ |
| 198 | - protected function loadEav (array $entities): void { |
|
| 198 | + protected function loadEav(array $entities): void { |
|
| 199 | 199 | $ids = array_keys($entities); |
| 200 | 200 | foreach ($this->eav as $name => $eav) { |
| 201 | 201 | foreach ($eav->loadAll($ids) as $id => $values) { |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | * @param EntityInterface $entity |
| 211 | 211 | * @return int ID |
| 212 | 212 | */ |
| 213 | - public function save (EntityInterface $entity): int { |
|
| 213 | + public function save(EntityInterface $entity): int { |
|
| 214 | 214 | if (!$entity->getId()) { |
| 215 | 215 | $this->saveInsert($entity); |
| 216 | 216 | } |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | /** |
| 225 | 225 | * @param EntityInterface $entity |
| 226 | 226 | */ |
| 227 | - protected function saveEav (EntityInterface $entity): void { |
|
| 227 | + protected function saveEav(EntityInterface $entity): void { |
|
| 228 | 228 | $id = $entity->getId(); |
| 229 | 229 | foreach ($this->eav as $name => $eav) { |
| 230 | 230 | $values = $this->properties[$name]->getValue($entity); |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | * |
| 240 | 240 | * @param EntityInterface $entity |
| 241 | 241 | */ |
| 242 | - protected function saveInsert (EntityInterface $entity): void { |
|
| 242 | + protected function saveInsert(EntityInterface $entity): void { |
|
| 243 | 243 | $insert = $this->cache(__FUNCTION__, function() { |
| 244 | 244 | $slots = SQL::slots(array_keys($this->columns)); |
| 245 | 245 | unset($slots['id']); |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | * |
| 258 | 258 | * @param EntityInterface $entity |
| 259 | 259 | */ |
| 260 | - protected function saveUpdate (EntityInterface $entity): void { |
|
| 260 | + protected function saveUpdate(EntityInterface $entity): void { |
|
| 261 | 261 | $this->cache(__FUNCTION__, function() { |
| 262 | 262 | $slots = SQL::slotsEqual(array_keys($this->columns)); |
| 263 | 263 | unset($slots['id']); |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | * @param array $columns Defaults to all columns. |
| 273 | 273 | * @return Select |
| 274 | 274 | */ |
| 275 | - public function select (array $columns = []): Select { |
|
| 275 | + public function select(array $columns = []): Select { |
|
| 276 | 276 | return parent::select($columns)->setFetcher(function(Statement $statement) { |
| 277 | 277 | return $this->fetchAll($statement); |
| 278 | 278 | }); |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | * @param EntityInterface $proto |
| 283 | 283 | * @return $this |
| 284 | 284 | */ |
| 285 | - public function setProto (EntityInterface $proto) { |
|
| 285 | + public function setProto(EntityInterface $proto) { |
|
| 286 | 286 | $this->proto = $proto; |
| 287 | 287 | return $this; |
| 288 | 288 | } |
@@ -291,7 +291,7 @@ discard block |
||
| 291 | 291 | * @param EntityInterface $entity |
| 292 | 292 | * @param array $values |
| 293 | 293 | */ |
| 294 | - protected function setValues (EntityInterface $entity, array $values): void { |
|
| 294 | + protected function setValues(EntityInterface $entity, array $values): void { |
|
| 295 | 295 | foreach ($values as $name => $value) { |
| 296 | 296 | settype($value, $this->types[$name]); |
| 297 | 297 | $this->properties[$name]->setValue($entity, $value); |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | * |
| 22 | 22 | * @param DB $db |
| 23 | 23 | */ |
| 24 | - protected function __construct (DB $db) { |
|
| 24 | + protected function __construct(DB $db) { |
|
| 25 | 25 | $this->db = $db; |
| 26 | 26 | } |
| 27 | 27 | |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * @param array $args |
| 32 | 32 | * @return $this |
| 33 | 33 | */ |
| 34 | - public function __invoke (array $args = null) { |
|
| 34 | + public function __invoke(array $args = null) { |
|
| 35 | 35 | $this->execute($args); |
| 36 | 36 | return $this; |
| 37 | 37 | } |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | * |
| 42 | 42 | * @return string |
| 43 | 43 | */ |
| 44 | - public function __toString () { |
|
| 44 | + public function __toString() { |
|
| 45 | 45 | return $this->queryString; |
| 46 | 46 | } |
| 47 | 47 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | * @return bool |
| 55 | 55 | * @throws ArgumentCountError |
| 56 | 56 | */ |
| 57 | - public function execute ($args = null) { |
|
| 57 | + public function execute($args = null) { |
|
| 58 | 58 | $this->db->getLogger()->__invoke($this->queryString); |
| 59 | 59 | if ($result = !parent::execute($args)) { |
| 60 | 60 | $info = $this->errorInfo(); |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | * |
| 72 | 72 | * @return int |
| 73 | 73 | */ |
| 74 | - public function getId (): int { |
|
| 74 | + public function getId(): int { |
|
| 75 | 75 | return (int)$this->db->lastInsertId(); |
| 76 | 76 | } |
| 77 | 77 | } |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | * @param string $passwd |
| 54 | 54 | * @param array $options |
| 55 | 55 | */ |
| 56 | - public function __construct ($dsn, $username = null, $passwd = null, $options = null) { |
|
| 56 | + public function __construct($dsn, $username = null, $passwd = null, $options = null) { |
|
| 57 | 57 | parent::__construct($dsn, $username, $passwd, $options); |
| 58 | 58 | $this->driver = $this->getAttribute(self::ATTR_DRIVER_NAME); |
| 59 | 59 | $this->setAttribute(self::ATTR_DEFAULT_FETCH_MODE, self::FETCH_ASSOC); |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | * @param string $sql |
| 75 | 75 | * @return int |
| 76 | 76 | */ |
| 77 | - public function exec ($sql): int { |
|
| 77 | + public function exec($sql): int { |
|
| 78 | 78 | $this->logger->__invoke($sql); |
| 79 | 79 | return parent::exec($sql); |
| 80 | 80 | } |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | /** |
| 83 | 83 | * @return string |
| 84 | 84 | */ |
| 85 | - final public function getDriver (): string { |
|
| 85 | + final public function getDriver(): string { |
|
| 86 | 86 | return $this->driver; |
| 87 | 87 | } |
| 88 | 88 | |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | * @param string $interface |
| 93 | 93 | * @return Junction |
| 94 | 94 | */ |
| 95 | - public function getJunction ($interface): Junction { |
|
| 95 | + public function getJunction($interface): Junction { |
|
| 96 | 96 | if (!isset($this->junctions[$interface])) { |
| 97 | 97 | $this->junctions[$interface] = new Junction($this, $interface); |
| 98 | 98 | } |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | /** |
| 103 | 103 | * @return Closure |
| 104 | 104 | */ |
| 105 | - public function getLogger (): Closure { |
|
| 105 | + public function getLogger(): Closure { |
|
| 106 | 106 | return $this->logger; |
| 107 | 107 | } |
| 108 | 108 | |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | * @param string|EntityInterface $class |
| 113 | 113 | * @return Record |
| 114 | 114 | */ |
| 115 | - public function getRecord ($class): Record { |
|
| 115 | + public function getRecord($class): Record { |
|
| 116 | 116 | if (is_object($class)) { |
| 117 | 117 | $class = get_class($class); |
| 118 | 118 | } |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | * @param mixed $b |
| 137 | 137 | * @return string |
| 138 | 138 | */ |
| 139 | - public function match ($a, $b) { |
|
| 139 | + public function match($a, $b) { |
|
| 140 | 140 | if ($b instanceof Closure) { |
| 141 | 141 | if (!$a instanceof Column) { |
| 142 | 142 | $a = new Column($this, $a); |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | * @param array $match |
| 163 | 163 | * @return string[] |
| 164 | 164 | */ |
| 165 | - public function matchArray (array $match) { |
|
| 165 | + public function matchArray(array $match) { |
|
| 166 | 166 | return array_map([$this, 'match'], array_keys($match), $match); |
| 167 | 167 | } |
| 168 | 168 | |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | * @param string $access Class or interface name. |
| 171 | 171 | * @return bool |
| 172 | 172 | */ |
| 173 | - public function offsetExists ($access): bool { |
|
| 173 | + public function offsetExists($access): bool { |
|
| 174 | 174 | return (bool)$this->offsetGet($access); |
| 175 | 175 | } |
| 176 | 176 | |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | * @param string $access Class or interface name. |
| 179 | 179 | * @return null|Record|Junction |
| 180 | 180 | */ |
| 181 | - public function offsetGet ($access) { |
|
| 181 | + public function offsetGet($access) { |
|
| 182 | 182 | if (class_exists($access)) { |
| 183 | 183 | return $this->getRecord($access); |
| 184 | 184 | } |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | * @param void $value |
| 196 | 196 | * @throws Exception |
| 197 | 197 | */ |
| 198 | - final public function offsetSet ($access, $value): void { |
|
| 198 | + final public function offsetSet($access, $value): void { |
|
| 199 | 199 | throw new Exception('The schema is immutable.'); |
| 200 | 200 | } |
| 201 | 201 | |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | * @param void $access |
| 206 | 206 | * @throws Exception |
| 207 | 207 | */ |
| 208 | - final public function offsetUnset ($access): void { |
|
| 208 | + final public function offsetUnset($access): void { |
|
| 209 | 209 | $this->offsetSet($access, null); |
| 210 | 210 | } |
| 211 | 211 | |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | * @param array $options |
| 217 | 217 | * @return Statement |
| 218 | 218 | */ |
| 219 | - public function prepare ($sql, $options = []): Statement { |
|
| 219 | + public function prepare($sql, $options = []): Statement { |
|
| 220 | 220 | $this->logger->__invoke($sql); |
| 221 | 221 | /** @var Statement $statement */ |
| 222 | 222 | $statement = parent::prepare($sql, $options); |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | * @param array $ctorargs |
| 233 | 233 | * @return Statement |
| 234 | 234 | */ |
| 235 | - public function query ($sql, $mode = PDO::ATTR_DEFAULT_FETCH_MODE, $arg3 = null, array $ctorargs = []): Statement { |
|
| 235 | + public function query($sql, $mode = PDO::ATTR_DEFAULT_FETCH_MODE, $arg3 = null, array $ctorargs = []): Statement { |
|
| 236 | 236 | $this->logger->__invoke($sql); |
| 237 | 237 | /** @var Statement $statement */ |
| 238 | 238 | $statement = parent::query(...func_get_args()); |
@@ -251,7 +251,7 @@ discard block |
||
| 251 | 251 | * @param int $type Ignored. |
| 252 | 252 | * @return string |
| 253 | 253 | */ |
| 254 | - public function quote ($value, $type = null) { |
|
| 254 | + public function quote($value, $type = null) { |
|
| 255 | 255 | if ($value instanceof ExpressionInterface) { |
| 256 | 256 | return $value; |
| 257 | 257 | } |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | * @param array $values |
| 272 | 272 | * @return array |
| 273 | 273 | */ |
| 274 | - public function quoteArray (array $values): array { |
|
| 274 | + public function quoteArray(array $values): array { |
|
| 275 | 275 | return array_map([$this, 'quote'], $values); |
| 276 | 276 | } |
| 277 | 277 | |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | * @param mixed $value |
| 282 | 282 | * @return array|string |
| 283 | 283 | */ |
| 284 | - public function quoteMixed ($value) { |
|
| 284 | + public function quoteMixed($value) { |
|
| 285 | 285 | if (is_array($value)) { |
| 286 | 286 | return $this->quoteArray($value); |
| 287 | 287 | } |
@@ -294,7 +294,7 @@ discard block |
||
| 294 | 294 | * @param EntityInterface $entity |
| 295 | 295 | * @return int ID |
| 296 | 296 | */ |
| 297 | - public function save (EntityInterface $entity): int { |
|
| 297 | + public function save(EntityInterface $entity): int { |
|
| 298 | 298 | return $this->getRecord($entity)->save($entity); |
| 299 | 299 | } |
| 300 | 300 | |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | * @param Closure $logger |
| 303 | 303 | * @return $this |
| 304 | 304 | */ |
| 305 | - public function setLogger (Closure $logger) { |
|
| 305 | + public function setLogger(Closure $logger) { |
|
| 306 | 306 | $this->logger = $logger; |
| 307 | 307 | return $this; |
| 308 | 308 | } |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * @param string $name |
| 32 | 32 | * @param string[] $columns |
| 33 | 33 | */ |
| 34 | - public function __construct (DB $db, $name, array $columns) { |
|
| 34 | + public function __construct(DB $db, $name, array $columns) { |
|
| 35 | 35 | parent::__construct($db); |
| 36 | 36 | $this->name = $name; |
| 37 | 37 | foreach ($columns as $column) { |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | * |
| 45 | 45 | * @return string |
| 46 | 46 | */ |
| 47 | - final public function __toString () { |
|
| 47 | + final public function __toString() { |
|
| 48 | 48 | return $this->name; |
| 49 | 49 | } |
| 50 | 50 | |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | * @param array $match |
| 57 | 57 | * @return int Rows affected. |
| 58 | 58 | */ |
| 59 | - public function delete (array $match): int { |
|
| 59 | + public function delete(array $match): int { |
|
| 60 | 60 | $match = Predicate::all($this->db->matchArray($match)); |
| 61 | 61 | return $this->db->exec("DELETE FROM {$this} WHERE {$match}"); |
| 62 | 62 | } |
@@ -64,14 +64,14 @@ discard block |
||
| 64 | 64 | /** |
| 65 | 65 | * @return Column[] |
| 66 | 66 | */ |
| 67 | - final public function getColumns (): array { |
|
| 67 | + final public function getColumns(): array { |
|
| 68 | 68 | return $this->columns; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
| 72 | 72 | * @return string |
| 73 | 73 | */ |
| 74 | - final public function getName (): string { |
|
| 74 | + final public function getName(): string { |
|
| 75 | 75 | return $this->name; |
| 76 | 76 | } |
| 77 | 77 | |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | * @param array $values |
| 82 | 82 | * @return Statement |
| 83 | 83 | */ |
| 84 | - public function insert (array $values): Statement { |
|
| 84 | + public function insert(array $values): Statement { |
|
| 85 | 85 | $columns = implode(',', array_keys($values)); |
| 86 | 86 | $values = implode(', ', $this->db->quoteArray($values)); |
| 87 | 87 | return $this->db->query("INSERT INTO {$this} ($columns) VALUES ($values)"); |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | * @param string $name |
| 92 | 92 | * @return bool |
| 93 | 93 | */ |
| 94 | - public function offsetExists ($name): bool { |
|
| 94 | + public function offsetExists($name): bool { |
|
| 95 | 95 | return isset($this->columns[$name]); |
| 96 | 96 | } |
| 97 | 97 | |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | * @param string $name |
| 100 | 100 | * @return Column |
| 101 | 101 | */ |
| 102 | - public function offsetGet ($name): Column { |
|
| 102 | + public function offsetGet($name): Column { |
|
| 103 | 103 | return $this->columns[$name]; |
| 104 | 104 | } |
| 105 | 105 | |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | * @param string[] $columns Defaults to all columns. |
| 110 | 110 | * @return Select |
| 111 | 111 | */ |
| 112 | - public function select (array $columns = []): Select { |
|
| 112 | + public function select(array $columns = []): Select { |
|
| 113 | 113 | if (!$columns) { |
| 114 | 114 | $columns = array_values($this->columns); |
| 115 | 115 | } |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | * @param string $name |
| 123 | 123 | * @return Table |
| 124 | 124 | */ |
| 125 | - public function setName (string $name) { |
|
| 125 | + public function setName(string $name) { |
|
| 126 | 126 | $clone = clone $this; |
| 127 | 127 | $clone->name = $name; |
| 128 | 128 | foreach ($this->columns as $name => $column) { |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | * @param array $match |
| 141 | 141 | * @return int Rows affected. |
| 142 | 142 | */ |
| 143 | - public function update (array $values, array $match): int { |
|
| 143 | + public function update(array $values, array $match): int { |
|
| 144 | 144 | $values = implode(', ', $this->db->matchArray($values)); |
| 145 | 145 | $match = Predicate::all($this->db->matchArray($match)); |
| 146 | 146 | return $this->db->exec("UPDATE {$this} SET {$values} WHERE {$match}"); |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | * @param string|Select $table |
| 82 | 82 | * @param string[] $columns |
| 83 | 83 | */ |
| 84 | - public function __construct (DB $db, $table, array $columns) { |
|
| 84 | + public function __construct(DB $db, $table, array $columns) { |
|
| 85 | 85 | parent::__construct($db); |
| 86 | 86 | if ($table instanceof Select) { |
| 87 | 87 | $table = $table->toSubquery(); |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | /** |
| 98 | 98 | * Gives the clone a new alias. |
| 99 | 99 | */ |
| 100 | - public function __clone () { |
|
| 100 | + public function __clone() { |
|
| 101 | 101 | $this->alias = uniqid('_') . "__{$this->table}"; |
| 102 | 102 | } |
| 103 | 103 | |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | * @param array $args |
| 106 | 106 | * @return Statement |
| 107 | 107 | */ |
| 108 | - public function __invoke (array $args = []): Statement { |
|
| 108 | + public function __invoke(array $args = []): Statement { |
|
| 109 | 109 | return $this->execute($args); |
| 110 | 110 | } |
| 111 | 111 | |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | * |
| 115 | 115 | * @return string |
| 116 | 116 | */ |
| 117 | - final public function __toString () { |
|
| 117 | + final public function __toString() { |
|
| 118 | 118 | return $this->alias; |
| 119 | 119 | } |
| 120 | 120 | |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | * @param array $args Execution arguments. |
| 125 | 125 | * @return int |
| 126 | 126 | */ |
| 127 | - public function count (array $args = []): int { |
|
| 127 | + public function count(array $args = []): int { |
|
| 128 | 128 | $clone = clone $this; |
| 129 | 129 | $clone->columns = ['COUNT(*)']; |
| 130 | 130 | return (int)$clone->execute($args)->fetchColumn(); |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | * @param array $args |
| 137 | 137 | * @return Statement |
| 138 | 138 | */ |
| 139 | - public function execute (array $args = []): Statement { |
|
| 139 | + public function execute(array $args = []): Statement { |
|
| 140 | 140 | if (!empty($args)) { |
| 141 | 141 | return $this->prepare()($args); |
| 142 | 142 | } |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | * @param array $args Execution arguments. |
| 152 | 152 | * @return array |
| 153 | 153 | */ |
| 154 | - public function fetchAll (array $args = []): array { |
|
| 154 | + public function fetchAll(array $args = []): array { |
|
| 155 | 155 | return $this->fetcher->__invoke($this->execute($args)); |
| 156 | 156 | } |
| 157 | 157 | |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | * |
| 163 | 163 | * @return ArrayIterator |
| 164 | 164 | */ |
| 165 | - public function getIterator () { |
|
| 165 | + public function getIterator() { |
|
| 166 | 166 | return new ArrayIterator($this->fetchAll()); |
| 167 | 167 | } |
| 168 | 168 | |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | * @param string $column |
| 173 | 173 | * @return $this |
| 174 | 174 | */ |
| 175 | - public function group (string $column) { |
|
| 175 | + public function group(string $column) { |
|
| 176 | 176 | $this->_group[] = $column; |
| 177 | 177 | return $this; |
| 178 | 178 | } |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | * @param string $condition |
| 184 | 184 | * @return $this |
| 185 | 185 | */ |
| 186 | - public function having (string $condition) { |
|
| 186 | + public function having(string $condition) { |
|
| 187 | 187 | $this->_having[] = $condition; |
| 188 | 188 | return $this; |
| 189 | 189 | } |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | * @param string $type |
| 197 | 197 | * @return $this |
| 198 | 198 | */ |
| 199 | - public function join ($table, string $condition, string $type = 'INNER') { |
|
| 199 | + public function join($table, string $condition, string $type = 'INNER') { |
|
| 200 | 200 | if ($table instanceof Select) { |
| 201 | 201 | $table = $table->toSubquery(); |
| 202 | 202 | } |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | * @param int $offset |
| 212 | 212 | * @return $this |
| 213 | 213 | */ |
| 214 | - public function limit (int $limit, int $offset = 0) { |
|
| 214 | + public function limit(int $limit, int $offset = 0) { |
|
| 215 | 215 | $this->_limit = $limit; |
| 216 | 216 | $this->_offset = $offset; |
| 217 | 217 | return $this; |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | * @param string $name Name or alias if used. |
| 224 | 224 | * @return bool |
| 225 | 225 | */ |
| 226 | - public function offsetExists ($name): bool { |
|
| 226 | + public function offsetExists($name): bool { |
|
| 227 | 227 | return true; |
| 228 | 228 | } |
| 229 | 229 | |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | * @param string $name Name, or alias if used. |
| 234 | 234 | * @return Column |
| 235 | 235 | */ |
| 236 | - public function offsetGet ($name): Column { |
|
| 236 | + public function offsetGet($name): Column { |
|
| 237 | 237 | return new Column($this->db, $name, $this->alias); |
| 238 | 238 | } |
| 239 | 239 | |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | * @param string $order |
| 244 | 244 | * @return $this |
| 245 | 245 | */ |
| 246 | - public function order (string $order) { |
|
| 246 | + public function order(string $order) { |
|
| 247 | 247 | $this->_order = $order; |
| 248 | 248 | return $this; |
| 249 | 249 | } |
@@ -251,7 +251,7 @@ discard block |
||
| 251 | 251 | /** |
| 252 | 252 | * @return Statement |
| 253 | 253 | */ |
| 254 | - public function prepare (): Statement { |
|
| 254 | + public function prepare(): Statement { |
|
| 255 | 255 | return $this->db->prepare($this->toSql()); |
| 256 | 256 | } |
| 257 | 257 | |
@@ -259,7 +259,7 @@ discard block |
||
| 259 | 259 | * @param Closure $fetcher |
| 260 | 260 | * @return $this |
| 261 | 261 | */ |
| 262 | - public function setFetcher (Closure $fetcher) { |
|
| 262 | + public function setFetcher(Closure $fetcher) { |
|
| 263 | 263 | $this->fetcher = $fetcher; |
| 264 | 264 | return $this; |
| 265 | 265 | } |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | /** |
| 268 | 268 | * @return string |
| 269 | 269 | */ |
| 270 | - public function toSql (): string { |
|
| 270 | + public function toSql(): string { |
|
| 271 | 271 | $columns = []; |
| 272 | 272 | foreach ($this->columns as $alias => $name) { |
| 273 | 273 | if (is_string($alias) and $name !== $alias) { |
@@ -307,7 +307,7 @@ discard block |
||
| 307 | 307 | * |
| 308 | 308 | * @return string |
| 309 | 309 | */ |
| 310 | - public function toSubquery (): string { |
|
| 310 | + public function toSubquery(): string { |
|
| 311 | 311 | return "({$this->toSql()}) AS {$this->alias}"; |
| 312 | 312 | } |
| 313 | 313 | |
@@ -317,7 +317,7 @@ discard block |
||
| 317 | 317 | * @param string $condition |
| 318 | 318 | * @return $this |
| 319 | 319 | */ |
| 320 | - public function where (string $condition) { |
|
| 320 | + public function where(string $condition) { |
|
| 321 | 321 | $this->_where[] = $condition; |
| 322 | 322 | return $this; |
| 323 | 323 | } |
@@ -272,8 +272,7 @@ |
||
| 272 | 272 | foreach ($this->columns as $alias => $name) { |
| 273 | 273 | if (is_string($alias) and $name !== $alias) { |
| 274 | 274 | $columns[] = "{$name} AS {$alias}"; |
| 275 | - } |
|
| 276 | - else { |
|
| 275 | + } else { |
|
| 277 | 276 | $columns[] = $name; |
| 278 | 277 | } |
| 279 | 278 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | * @param Record $record The entity's storage access. |
| 20 | 20 | * @param $name |
| 21 | 21 | */ |
| 22 | - public function __construct (Record $record, $name) { |
|
| 22 | + public function __construct(Record $record, $name) { |
|
| 23 | 23 | $this->record = $record; |
| 24 | 24 | parent::__construct($record->db, $name, ['entity', 'attribute', 'value']); |
| 25 | 25 | } |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | * @param int $id |
| 31 | 31 | * @return int |
| 32 | 32 | */ |
| 33 | - public function count (int $id): int { |
|
| 33 | + public function count(int $id): int { |
|
| 34 | 34 | $count = $this->cache(__FUNCTION__, function() { |
| 35 | 35 | return $this->select(['COUNT(*)'])->where('entity=?')->prepare(); |
| 36 | 36 | }); |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | * @param string $attribute |
| 45 | 45 | * @return bool |
| 46 | 46 | */ |
| 47 | - public function exists (int $id, string $attribute): bool { |
|
| 47 | + public function exists(int $id, string $attribute): bool { |
|
| 48 | 48 | $exists = $this->cache(__FUNCTION__, function() { |
| 49 | 49 | $select = $this->select(['COUNT(*) > 0']); |
| 50 | 50 | $select->where('entity = ? AND attribute = ?'); |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | * @param array $match `[attribute => value]`. If empty, selects all IDs for entities having at least one attribute. |
| 63 | 63 | * @return Select |
| 64 | 64 | */ |
| 65 | - public function find (array $match): Select { |
|
| 65 | + public function find(array $match): Select { |
|
| 66 | 66 | $select = $this->select([$this['entity']]); |
| 67 | 67 | $prior = $this; |
| 68 | 68 | foreach ($match as $attribute => $value) { |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | * @param int $id |
| 85 | 85 | * @return array `[attribute => value]` |
| 86 | 86 | */ |
| 87 | - public function load (int $id): array { |
|
| 87 | + public function load(int $id): array { |
|
| 88 | 88 | $load = $this->cache(__FUNCTION__, function() { |
| 89 | 89 | $select = $this->select(['attribute', 'value']); |
| 90 | 90 | $select->where('entity = ?'); |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | * @param int[] $ids |
| 101 | 101 | * @return array[] `[id => attribute => value] |
| 102 | 102 | */ |
| 103 | - public function loadAll (array $ids): array { |
|
| 103 | + public function loadAll(array $ids): array { |
|
| 104 | 104 | if (count($ids) === 1) { |
| 105 | 105 | return [current($ids) => $this->load(current($ids))]; |
| 106 | 106 | } |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | * @param array $values `[attribute => value]` |
| 123 | 123 | * @return $this |
| 124 | 124 | */ |
| 125 | - public function save (int $id, array $values) { |
|
| 125 | + public function save(int $id, array $values) { |
|
| 126 | 126 | $this->delete([ |
| 127 | 127 | $this['entity']->isEqual($id), |
| 128 | 128 | $this['attribute']->isNotEqual(array_keys($values)) |