diff --git a/composer.json b/composer.json index a4f807af1..9666059fc 100644 --- a/composer.json +++ b/composer.json @@ -55,6 +55,7 @@ "phpunit/phpunit": "^9.5.5" }, "conflict": { + "friendsofphp/php-cs-fixer": "^3.9", "jdorn/sql-formatter": "<1.2.9" }, "suggest": { diff --git a/src/Model.php b/src/Model.php index dc48e0a5a..2787d30c1 100644 --- a/src/Model.php +++ b/src/Model.php @@ -2040,7 +2040,7 @@ public function __debugInfo(): array if ($this->isEntity()) { return [ 'entityId' => $this->id_field && $this->hasField($this->id_field) - ? (($this->_entityId !== null ? $this->_entityId . ($this->getId() !== null ? '' : ' (unloaded)') : 'null')) + ? ($this->_entityId !== null ? $this->_entityId . ($this->getId() !== null ? '' : ' (unloaded)') : 'null') : 'no id field', 'model' => $this->getModel()->__debugInfo(), ]; diff --git a/src/Model/Scope/Condition.php b/src/Model/Scope/Condition.php index 9efdf38d6..1356e5c60 100644 --- a/src/Model/Scope/Condition.php +++ b/src/Model/Scope/Condition.php @@ -114,7 +114,7 @@ public function __construct($key, $operator = null, $value = null) if ($operator === null) { // at least MSSQL database always requires an operator - if (!($key instanceof Expressionable)) { + if (!$key instanceof Expressionable) { throw new Exception('Operator must be specified'); } } else { diff --git a/src/Persistence/Array_/Action.php b/src/Persistence/Array_/Action.php index 9080b7be4..0e0be6699 100644 --- a/src/Persistence/Array_/Action.php +++ b/src/Persistence/Array_/Action.php @@ -71,7 +71,7 @@ public function aggregate(string $fx, string $field, bool $coalesce = false) case 'SUM': $result = array_sum($column); - break; + break; case 'AVG': $column = $coalesce ? $column : array_filter($column, function ($value) { return $value !== null; @@ -79,15 +79,15 @@ public function aggregate(string $fx, string $field, bool $coalesce = false) $result = array_sum($column) / count($column); - break; + break; case 'MAX': $result = max($column); - break; + break; case 'MIN': $result = min($column); - break; + break; default: throw (new Exception('Array persistence driver action unsupported format')) ->addMoreInfo('action', $fx); @@ -161,37 +161,37 @@ protected function evaluateIf($v1, string $operator, $v2): bool case '=': $result = is_array($v2) ? $this->evaluateIf($v1, 'IN', $v2) : $v1 === $v2; - break; + break; case '>': $result = $v1 > $v2; - break; + break; case '>=': $result = $v1 >= $v2; - break; + break; case '<': $result = $v1 < $v2; - break; + break; case '<=': $result = $v1 <= $v2; - break; + break; case '!=': $result = !$this->evaluateIf($v1, '=', $v2); - break; + break; case 'LIKE': $pattern = str_ireplace('%', '(.*?)', preg_quote($v2)); $result = (bool) preg_match('/^' . $pattern . '$/', (string) $v1); - break; + break; case 'NOT LIKE': $result = !$this->evaluateIf($v1, 'LIKE', $v2); - break; + break; case 'IN': $result = false; foreach ($v2 as $v2Item) { // TODO flatten rows, this looses column names! @@ -202,19 +202,19 @@ protected function evaluateIf($v1, string $operator, $v2): bool } } - break; + break; case 'NOT IN': $result = !$this->evaluateIf($v1, 'IN', $v2); - break; + break; case 'REGEXP': $result = (bool) preg_match('/' . $v2 . '/', $v1); - break; + break; case 'NOT REGEXP': $result = !$this->evaluateIf($v1, 'REGEXP', $v2); - break; + break; default: throw (new Exception('Unsupported operator')) ->addMoreInfo('operator', $operator); diff --git a/src/Persistence/Sql.php b/src/Persistence/Sql.php index 23f4bf6fc..e3b65d0ae 100644 --- a/src/Persistence/Sql.php +++ b/src/Persistence/Sql.php @@ -321,8 +321,8 @@ public function initQueryConditions(Model $model, Query $query): void private function fixMssqlOracleMissingFieldsInGroup(Model $model, Query $query): void { - if (($this->getDatabasePlatform() instanceof SQLServerPlatform - || $this->getDatabasePlatform() instanceof OraclePlatform)) { + if ($this->getDatabasePlatform() instanceof SQLServerPlatform + || $this->getDatabasePlatform() instanceof OraclePlatform) { $isIdFieldInGroup = false; foreach ($query->args['group'] ?? [] as $v) { if ($model->id_field && $v === $model->getField($model->id_field)) { diff --git a/src/Persistence/Sql/Join.php b/src/Persistence/Sql/Join.php index a68d005d4..b19401253 100644 --- a/src/Persistence/Sql/Join.php +++ b/src/Persistence/Sql/Join.php @@ -77,7 +77,7 @@ public function initSelectQuery(Model $model, Query $query): void $query->join( $this->foreign_table, $this->getOwner()->expr('{{}}.{} = {}', [ - ($this->foreign_alias ?: $this->foreign_table), + $this->foreign_alias ?: $this->foreign_table, $this->foreign_field, $this->getOwner()->getField($this->master_field), ]), diff --git a/tests/ModelNestedSqlTest.php b/tests/ModelNestedSqlTest.php index 8213714bf..d86590c99 100644 --- a/tests/ModelNestedSqlTest.php +++ b/tests/ModelNestedSqlTest.php @@ -110,9 +110,9 @@ public function testSelectSql(): void $m->setOrder('birthday'); $this->assertSame( - ($this->db->getConnection()->dsql()) + $this->db->getConnection()->dsql() ->table( - ($this->db->getConnection()->dsql()) + $this->db->getConnection()->dsql() ->table('user') ->field('_id', 'uid') ->field('name') diff --git a/tests/Persistence/Sql/QueryTest.php b/tests/Persistence/Sql/QueryTest.php index 641d39135..a7bbe8b0e 100644 --- a/tests/Persistence/Sql/QueryTest.php +++ b/tests/Persistence/Sql/QueryTest.php @@ -471,9 +471,9 @@ public function testVarDump4(): void // should throw exception "Table cannot be Query in UPDATE, INSERT etc. query modes" $this->assertStringContainsString( 'Table cannot be Query', - ($this->q() + $this->q() ->mode('update') - ->table($this->q()->table('test'), 'foo'))->__debugInfo()['R'] + ->table($this->q()->table('test'), 'foo')->__debugInfo()['R'] ); } diff --git a/tests/SmboTransferTest.php b/tests/SmboTransferTest.php index 0999b2d85..f521fbda8 100644 --- a/tests/SmboTransferTest.php +++ b/tests/SmboTransferTest.php @@ -32,9 +32,8 @@ protected function setUp(): void ->field('document_id', ['type' => 'integer']) ->field('account_id', ['type' => 'integer']) ->field('cheque_no') - // ->field('misc_payment', ['type' => 'enum(\'N\',\'Y\')']) - ->field('misc_payment') - ->field('transfer_document_id') + ->field('misc_payment', ['type' => 'boolean']) + ->field('transfer_document_id', ['type' => 'integer']) ->create(); }