@@ -27,7 +27,7 @@ |
||
| 27 | 27 | |
| 28 | 28 | public function get() : mixed |
| 29 | 29 | { |
| 30 | - if(!$this->isChanged()) |
|
| 30 | + if (!$this->isChanged()) |
|
| 31 | 31 | return null; |
| 32 | 32 | |
| 33 | 33 | return $this->value; |
@@ -27,8 +27,9 @@ |
||
| 27 | 27 | |
| 28 | 28 | public function get() : mixed |
| 29 | 29 | { |
| 30 | - if(!$this->isChanged()) |
|
| 31 | - return null; |
|
| 30 | + if(!$this->isChanged()) { |
|
| 31 | + return null; |
|
| 32 | + } |
|
| 32 | 33 | |
| 33 | 34 | return $this->value; |
| 34 | 35 | } |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | { |
| 33 | 33 | Connection::get([ |
| 34 | 34 | 'driver' => 'pdo_sqlite', |
| 35 | - 'path' => dirname(__DIR__, 2) . '/tests/large.sqlite' |
|
| 35 | + 'path' => dirname(__DIR__, 2).'/tests/large.sqlite' |
|
| 36 | 36 | ]); |
| 37 | 37 | $migrator = new Migrator(); |
| 38 | 38 | $migrator->rollback(); |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | $capsule = new Capsule; |
| 42 | 42 | $capsule->addConnection([ |
| 43 | 43 | 'driver' => 'sqlite', |
| 44 | - 'database' => dirname(__DIR__, 2) . '/tests/large.sqlite' |
|
| 44 | + 'database' => dirname(__DIR__, 2).'/tests/large.sqlite' |
|
| 45 | 45 | ]); |
| 46 | 46 | $capsule->setAsGlobal(); |
| 47 | 47 | $capsule->bootEloquent(); |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | |
| 54 | 54 | $iterations = 20000; |
| 55 | 55 | $this->io->progressStart($iterations); |
| 56 | - for($i=0; $i < $iterations; $i++) { |
|
| 56 | + for ($i = 0; $i < $iterations; $i++) { |
|
| 57 | 57 | $string = ATTR_TYPE::STRING->randomValue(); |
| 58 | 58 | $integer = ATTR_TYPE::INTEGER->randomValue(); |
| 59 | 59 | $decimal = ATTR_TYPE::DECIMAL->randomValue(); |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | $attributeRepo = $this->makeAttributeRepository(); |
| 30 | 30 | |
| 31 | 31 | $groupRepo = $this->makeGroupRepository(); |
| 32 | - foreach($fields as $field) { |
|
| 32 | + foreach ($fields as $field) { |
|
| 33 | 33 | if (!key_exists(ATTR_FACTORY::GROUP->field(), $field)) { |
| 34 | 34 | throw new EntityFactoryException("Group key must be provided!"); |
| 35 | 35 | } |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | ? $valueRepo->updateOrCreate($domainKey, $entityRecord->getKey(), $attrKey, $type, $field[ATTR_FACTORY::VALUE->field()]) |
| 58 | 58 | : null; |
| 59 | 59 | |
| 60 | - if(!is_null($valueRecord)) { |
|
| 60 | + if (!is_null($valueRecord)) { |
|
| 61 | 61 | $result->addValue($attributeRecord->getName(), $valueRecord); |
| 62 | 62 | } |
| 63 | 63 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | ->where(_VALUE::ATTRIBUTE_ID->column(), $attributeKey); |
| 38 | 38 | $record = $query->first(); |
| 39 | 39 | |
| 40 | - if(!is_null($record)) |
|
| 40 | + if (!is_null($record)) |
|
| 41 | 41 | { |
| 42 | 42 | $record->setValue($value); |
| 43 | 43 | $record->save(); |
@@ -63,11 +63,11 @@ discard block |
||
| 63 | 63 | $datetimeTable = ATTR_TYPE::DATETIME->valueTable(); |
| 64 | 64 | $textTable = ATTR_TYPE::TEXT->valueTable(); |
| 65 | 65 | |
| 66 | - $stringTemplate = sprintf($template, $stringTable) . " VALUES %s;"; |
|
| 67 | - $integerTemplate = sprintf($template, $integerTable) . " VALUES %s;"; |
|
| 68 | - $decimalTemplate = sprintf($template, $decimalTable) . " VALUES %s;"; |
|
| 69 | - $datetimeTemplate = sprintf($template, $datetimeTable) . " VALUES %s;"; |
|
| 70 | - $textTemplate = sprintf($template, $textTable) . " VALUES %s;"; |
|
| 66 | + $stringTemplate = sprintf($template, $stringTable)." VALUES %s;"; |
|
| 67 | + $integerTemplate = sprintf($template, $integerTable)." VALUES %s;"; |
|
| 68 | + $decimalTemplate = sprintf($template, $decimalTable)." VALUES %s;"; |
|
| 69 | + $datetimeTemplate = sprintf($template, $datetimeTable)." VALUES %s;"; |
|
| 70 | + $textTemplate = sprintf($template, $textTable)." VALUES %s;"; |
|
| 71 | 71 | |
| 72 | 72 | $stringBulk = []; |
| 73 | 73 | $integerBulk = []; |
@@ -90,19 +90,19 @@ discard block |
||
| 90 | 90 | }; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - if(count($stringBulk) > 0) { |
|
| 93 | + if (count($stringBulk) > 0) { |
|
| 94 | 94 | $pdo->exec(sprintf($stringTemplate, implode(',', $stringBulk))); |
| 95 | 95 | } |
| 96 | - if(count($integerBulk) > 0) { |
|
| 96 | + if (count($integerBulk) > 0) { |
|
| 97 | 97 | $pdo->exec(sprintf($integerTemplate, implode(',', $integerBulk))); |
| 98 | 98 | } |
| 99 | - if(count($decimalBulk) > 0) { |
|
| 99 | + if (count($decimalBulk) > 0) { |
|
| 100 | 100 | $pdo->exec(sprintf($decimalTemplate, implode(',', $decimalBulk))); |
| 101 | 101 | } |
| 102 | - if(count($datetimeBulk) > 0) { |
|
| 102 | + if (count($datetimeBulk) > 0) { |
|
| 103 | 103 | $pdo->exec(sprintf($datetimeTemplate, implode(',', $datetimeBulk))); |
| 104 | 104 | } |
| 105 | - if(count($textBulk) > 0) { |
|
| 105 | + if (count($textBulk) > 0) { |
|
| 106 | 106 | $pdo->exec(sprintf($textTemplate, implode(',', $textBulk))); |
| 107 | 107 | } |
| 108 | 108 | } |
@@ -41,8 +41,7 @@ |
||
| 41 | 41 | { |
| 42 | 42 | $record->setValue($value); |
| 43 | 43 | $record->save(); |
| 44 | - } |
|
| 45 | - else |
|
| 44 | + } else |
|
| 46 | 45 | { |
| 47 | 46 | $factory = $this->getFactory(); |
| 48 | 47 | $record = $factory->createValue($type, $domainKey, $entityKey, $attributeKey, $value); |
@@ -49,18 +49,18 @@ |
||
| 49 | 49 | */ |
| 50 | 50 | public function bulkCreate(int $amount, int $domainKey, int $setKey, int $serviceKey) : void |
| 51 | 51 | { |
| 52 | - if($amount < 1) |
|
| 52 | + if ($amount < 1) |
|
| 53 | 53 | { |
| 54 | 54 | EntityException::mustBePositiveAmount(); |
| 55 | 55 | } |
| 56 | 56 | $format = "($domainKey, $setKey, $serviceKey)"; |
| 57 | 57 | $bulk = []; |
| 58 | - for($i=0;$i<$amount;$i++) { |
|
| 58 | + for ($i = 0; $i < $amount; $i++) { |
|
| 59 | 59 | $bulk[] = $format; |
| 60 | 60 | } |
| 61 | 61 | $template = sprintf( |
| 62 | 62 | "INSERT INTO "._ENTITY::table()." ("._ENTITY::DOMAIN_ID->column().", "._ENTITY::ATTR_SET_ID->column().", "._ENTITY::SERVICE_KEY->column().") VALUES %s;", |
| 63 | - implode(',',$bulk) |
|
| 63 | + implode(',', $bulk) |
|
| 64 | 64 | ); |
| 65 | 65 | |
| 66 | 66 | Connection::pdo()->exec($template); |
@@ -61,8 +61,8 @@ |
||
| 61 | 61 | |
| 62 | 62 | return AttributeModel::query() |
| 63 | 63 | ->join($pt, $pt.'.'._PIVOT::ATTR_ID->column(), '=', $at.'.'._ATTR::ID->column()) |
| 64 | - ->where($pt. '.'._PIVOT::SET_ID->column(), '=', $setKey) |
|
| 65 | - ->where($pt. '.'._PIVOT::DOMAIN_ID->column(), '=', $domainKey) |
|
| 64 | + ->where($pt.'.'._PIVOT::SET_ID->column(), '=', $setKey) |
|
| 65 | + ->where($pt.'.'._PIVOT::DOMAIN_ID->column(), '=', $domainKey) |
|
| 66 | 66 | ->get(); |
| 67 | 67 | } |
| 68 | 68 | } |
| 69 | 69 | \ No newline at end of file |
@@ -48,8 +48,9 @@ |
||
| 48 | 48 | $query = AttributeModel::query() |
| 49 | 49 | ->where(_ATTR::DOMAIN_ID->column(), $domainKey); |
| 50 | 50 | |
| 51 | - if (!is_null($setKey)) |
|
| 52 | - $query->with(['pivot' => fn(Builder $q) => $q->where(_PIVOT::SET_ID->column(), $setKey)]); |
|
| 51 | + if (!is_null($setKey)) { |
|
| 52 | + $query->with(['pivot' => fn(Builder $q) => $q->where(_PIVOT::SET_ID->column(), $setKey)]); |
|
| 53 | + } |
|
| 53 | 54 | |
| 54 | 55 | return $query->get(); |
| 55 | 56 | } |
@@ -58,22 +58,22 @@ |
||
| 58 | 58 | { |
| 59 | 59 | return $query->whereNotIn($name, $value, $condition); |
| 60 | 60 | } |
| 61 | - else if($operator == QB_OPERATOR::BETWEEN) |
|
| 61 | + else if ($operator == QB_OPERATOR::BETWEEN) |
|
| 62 | 62 | { |
| 63 | 63 | return $query->whereBetween($name, $value, $condition); |
| 64 | 64 | } |
| 65 | - else if($operator == QB_OPERATOR::NOT_BETWEEN) |
|
| 65 | + else if ($operator == QB_OPERATOR::NOT_BETWEEN) |
|
| 66 | 66 | { |
| 67 | 67 | return $query->whereNotBetween($name, $value, $condition); |
| 68 | 68 | } |
| 69 | 69 | } |
| 70 | - else if($operator->isNull()) |
|
| 70 | + else if ($operator->isNull()) |
|
| 71 | 71 | { |
| 72 | 72 | if ($operator == QB_OPERATOR::IS_NULL) |
| 73 | 73 | { |
| 74 | 74 | return $query->whereNull($name, $condition); |
| 75 | 75 | } |
| 76 | - else if($operator == QB_OPERATOR::IS_NOT_NULL) |
|
| 76 | + else if ($operator == QB_OPERATOR::IS_NOT_NULL) |
|
| 77 | 77 | { |
| 78 | 78 | return $query->whereNotNull($name, $condition); |
| 79 | 79 | } |
@@ -53,27 +53,22 @@ |
||
| 53 | 53 | if ($operator == QB_OPERATOR::IN) |
| 54 | 54 | { |
| 55 | 55 | return $query->whereIn($name, $value, $condition); |
| 56 | - } |
|
| 57 | - else if ($operator == QB_OPERATOR::NOT_IN) |
|
| 56 | + } else if ($operator == QB_OPERATOR::NOT_IN) |
|
| 58 | 57 | { |
| 59 | 58 | return $query->whereNotIn($name, $value, $condition); |
| 60 | - } |
|
| 61 | - else if($operator == QB_OPERATOR::BETWEEN) |
|
| 59 | + } else if($operator == QB_OPERATOR::BETWEEN) |
|
| 62 | 60 | { |
| 63 | 61 | return $query->whereBetween($name, $value, $condition); |
| 64 | - } |
|
| 65 | - else if($operator == QB_OPERATOR::NOT_BETWEEN) |
|
| 62 | + } else if($operator == QB_OPERATOR::NOT_BETWEEN) |
|
| 66 | 63 | { |
| 67 | 64 | return $query->whereNotBetween($name, $value, $condition); |
| 68 | 65 | } |
| 69 | - } |
|
| 70 | - else if($operator->isNull()) |
|
| 66 | + } else if($operator->isNull()) |
|
| 71 | 67 | { |
| 72 | 68 | if ($operator == QB_OPERATOR::IS_NULL) |
| 73 | 69 | { |
| 74 | 70 | return $query->whereNull($name, $condition); |
| 75 | - } |
|
| 76 | - else if($operator == QB_OPERATOR::IS_NOT_NULL) |
|
| 71 | + } else if($operator == QB_OPERATOR::IS_NOT_NULL) |
|
| 77 | 72 | { |
| 78 | 73 | return $query->whereNotNull($name, $condition); |
| 79 | 74 | } |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | |
| 58 | 58 | public function resetCondition(): void |
| 59 | 59 | { |
| 60 | - $this->condition = QB_CONDITION::AND; |
|
| 60 | + $this->condition = QB_CONDITION:: AND ; |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | public function appendRule(QueryBuilderRule $rule): void |
@@ -78,10 +78,10 @@ discard block |
||
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | public function makeJoins(Builder $query) { |
| 81 | - foreach($this->getItems() as $item) { |
|
| 82 | - if($item instanceof QueryBuilderGroup) { |
|
| 81 | + foreach ($this->getItems() as $item) { |
|
| 82 | + if ($item instanceof QueryBuilderGroup) { |
|
| 83 | 83 | $query = $item->makeJoins($query); |
| 84 | - } else if($item instanceof QueryBuilderRule) { |
|
| 84 | + } else if ($item instanceof QueryBuilderRule) { |
|
| 85 | 85 | $query = $item->join($query); |
| 86 | 86 | } |
| 87 | 87 | } |
@@ -90,10 +90,10 @@ discard block |
||
| 90 | 90 | |
| 91 | 91 | public function makeConditions(Builder $query) : Builder |
| 92 | 92 | { |
| 93 | - foreach($this->getItems() as $item) { |
|
| 94 | - if($item instanceof QueryBuilderGroup) { |
|
| 93 | + foreach ($this->getItems() as $item) { |
|
| 94 | + if ($item instanceof QueryBuilderGroup) { |
|
| 95 | 95 | $query = $query->whereNested(fn($q) => $item->makeConditions($q), $item->getParent()->getCondition()->sql()); |
| 96 | - } else if($item instanceof QueryBuilderRule) { |
|
| 96 | + } else if ($item instanceof QueryBuilderRule) { |
|
| 97 | 97 | $query = $item->condition($query); |
| 98 | 98 | } |
| 99 | 99 | } |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | |
| 68 | 68 | public function isColumn(string $column) : bool |
| 69 | 69 | { |
| 70 | - if(!$this->isColumns()) return false; |
|
| 70 | + if (!$this->isColumns()) return false; |
|
| 71 | 71 | return in_array($column, $this->getColumns()); |
| 72 | 72 | } |
| 73 | 73 | |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | public function setupAttribute(AttributeModel $attribute, Builder $query) : Builder |
| 137 | 137 | { |
| 138 | 138 | $name = $attribute->getName(); |
| 139 | - if(!$this->isManualColumn($name)) |
|
| 139 | + if (!$this->isManualColumn($name)) |
|
| 140 | 140 | { |
| 141 | 141 | return $query; |
| 142 | 142 | } |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | |
| 147 | 147 | public function makeAttributes(Builder $query) : Builder |
| 148 | 148 | { |
| 149 | - foreach($this->getAttributesPivot()->getAttributes() as $attribute) |
|
| 149 | + foreach ($this->getAttributesPivot()->getAttributes() as $attribute) |
|
| 150 | 150 | { |
| 151 | 151 | $query = $this->setupAttribute($attribute, $query); |
| 152 | 152 | } |
@@ -67,7 +67,9 @@ |
||
| 67 | 67 | |
| 68 | 68 | public function isColumn(string $column) : bool |
| 69 | 69 | { |
| 70 | - if(!$this->isColumns()) return false; |
|
| 70 | + if(!$this->isColumns()) { |
|
| 71 | + return false; |
|
| 72 | + } |
|
| 71 | 73 | return in_array($column, $this->getColumns()); |
| 72 | 74 | } |
| 73 | 75 | |