From 6ce87261bceac076a8e9a448a5f338f4908fa6f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Sat, 26 Dec 2020 23:08:34 +0100 Subject: [PATCH] Improve PHPStan level to 5 (#814) * Improve PHPStan level to 3 * Improve PHPStan level to 4 * Improve PHPStan level to 5 * fix stan --- docs/expressions.rst | 4 ++-- phpstan.neon.dist | 9 +++++---- src-schema/Migration.php | 6 ++++-- src-schema/PhpunitTestCase.php | 2 +- src/Action/Iterator.php | 4 ++-- src/Field.php | 4 +--- src/Model.php | 31 ++++++++++++++++++------------- src/Model/Join.php | 10 +++++----- src/Model/JoinsTrait.php | 6 +++--- src/Model/ReferencesTrait.php | 10 +++++----- src/Model/Scope.php | 8 ++------ src/Model/Scope/Condition.php | 28 ++++++---------------------- src/Model/Scope/RootScope.php | 4 +--- src/Model/UserAction.php | 4 ++-- src/Persistence/Array_/Join.php | 3 +-- src/Persistence/Csv.php | 4 ++-- src/Persistence/Sql.php | 16 ++++++++-------- src/Persistence/Sql/Join.php | 2 +- src/Persistence/Static_.php | 2 +- src/Reference.php | 16 +++++----------- tests-schema/ModelTest.php | 4 +++- tests/BusinessModelTest.php | 18 +----------------- tests/ExpressionSqlTest.php | 4 ++-- tests/LimitOrderTest.php | 2 +- tests/RandomTest.php | 2 +- tests/ValidationTest.php | 2 +- 26 files changed, 84 insertions(+), 121 deletions(-) diff --git a/docs/expressions.rst b/docs/expressions.rst index 829ba5591..85a7294be 100644 --- a/docs/expressions.rst +++ b/docs/expressions.rst @@ -63,7 +63,7 @@ no purpose initially, it does come in handy in some cases, when you need to unite a few statistical queries. Let's start by looking a at a very basic example:: - $m = new Model($db, false); + $m = new Model($db, ['table' => false]); $m->addExpression('now', 'now()'); $m->loadAny(); echo $m->get('now'); @@ -79,7 +79,7 @@ actually use consistently throughout the system. The real benefit from this can be gained when you need to pull various statistical values from your database at once:: - $m = new Model($db, false); + $m = new Model($db, ['table' => false]); $m->addExpression('total_orders', (new Model_Order($db))->action('count')); $m->addExpression('total_payments', (new Model_Payment($db))->action('count')); $m->addExpression('total_received', (new Model_Payment($db))->action('fx0', ['sum', 'amount'])); diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 8d3fcc29a..e29292fb5 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -2,7 +2,7 @@ includes: - vendor/mahalux/atk4-hintable/phpstan-ext.neon parameters: - level: 2 + level: 5 paths: - ./ excludes_analyse: @@ -19,13 +19,14 @@ parameters: # TODO remove once https://github.com/atk4/ui/issues/1548 is resolved - '~^Class Atk4\\Ui\\(Button|Icon) not found\.$~' + # TODO do we want to allow to pass an Model instance? + - '~^Parameter #2 \$defaults of method Atk4\\Data\\Model::(hasOne|hasMany)\(\) expects array, .+ given\.$~' + - '~^Parameter #2 \$defaults of method Atk4\\Data\\Model\\Join::(hasOne|hasMany)\(\) expects array, .+ given\.$~' + # TODO these rules are generated, this ignores should be fixed in the code - # for level = 2 # for src-schema/PhpunitTestCase.php - '~^Access to an undefined property Atk4\\Data\\Persistence\:\:\$connection\.$~' - '~^Call to an undefined method Atk4\\Data\\Persistence\:\:dsql\(\)\.$~' - # for src/Action/Iterator.php - - '~^Access to an undefined property CallbackFilterIterator\:\:\$filterFx\.$~' # for src/FieldSqlExpression.php - '~^Call to an undefined method Atk4\\Data\\Model\:\:expr\(\)\.$~' # for src/Model.php diff --git a/src-schema/Migration.php b/src-schema/Migration.php index cd7229a1d..b33635979 100644 --- a/src-schema/Migration.php +++ b/src-schema/Migration.php @@ -239,8 +239,10 @@ protected function getReferenceField(Field $field): ?Field $referenceField = $referenceTheirField ?? $field->reference->getOwner()->id_field; - $referenceModelClass = $field->reference->model; - $referenceModel = new $referenceModelClass(new Persistence\Sql($this->connection)); + $modelSeed = is_array($field->reference->model) + ? $field->reference->model + : [get_class($field->reference->model)]; + $referenceModel = Model::fromSeed($modelSeed, [new Persistence\Sql($this->connection)]); return $referenceModel->getField($referenceField); } diff --git a/src-schema/PhpunitTestCase.php b/src-schema/PhpunitTestCase.php index 3b5f2337d..4ecf39db2 100644 --- a/src-schema/PhpunitTestCase.php +++ b/src-schema/PhpunitTestCase.php @@ -73,7 +73,7 @@ public function stopQuery(): void protected function tearDown(): void { - $this->db = null; + $this->db = null; // @phpstan-ignore-line parent::tearDown(); // TODO: Change the autogenerated stub } diff --git a/src/Action/Iterator.php b/src/Action/Iterator.php index 9dd0d12f3..0246635ec 100644 --- a/src/Action/Iterator.php +++ b/src/Action/Iterator.php @@ -15,7 +15,7 @@ class Iterator { /** - * @var \ArrayIterator + * @var \Iterator */ public $generator; @@ -50,7 +50,7 @@ public function filter(Model\Scope\AbstractScope $condition) $this->generator = new \CallbackFilterIterator($this->generator, static function (array $row) use ($filterFxWeakRef) { return $filterFxWeakRef->get()($row); }); - $this->generator->filterFx = $filterFx; // prevent filter function to be GCed + $this->generator->filterFx = $filterFx; // @phpstan-ignore-line prevent filter function to be GCed } else { $this->generator = new \CallbackFilterIterator($this->generator, $filterFx); } diff --git a/src/Field.php b/src/Field.php index 7ffe05b8e..14fd1a345 100644 --- a/src/Field.php +++ b/src/Field.php @@ -157,7 +157,7 @@ class Field implements Expressionable * * Value can be array [$encode_callback, $decode_callback]. * - * @var bool|array|null + * @var bool|array|string|null */ public $serialize; @@ -400,8 +400,6 @@ public function normalize($value) case 'bool': throw (new Exception('Use of obsolete field type abbreviation. Use "integer", "string", "boolean" etc.')) ->addMoreInfo('type', $f->type); - - break; } return $value; diff --git a/src/Model.php b/src/Model.php index 539c499af..28bebbf05 100644 --- a/src/Model.php +++ b/src/Model.php @@ -114,7 +114,7 @@ class Model implements \IteratorAggregate * * $table = ['user', 'mysql'=>'tbl_user']; * - * @var string|array + * @var string|array|false */ public $table; @@ -135,7 +135,7 @@ class Model implements \IteratorAggregate /** * Persistence driver inherited from Atk4\Data\Persistence. * - * @var Persistence|Persistence\Sql + * @var Persistence|Persistence\Sql|null */ public $persistence; @@ -331,12 +331,12 @@ public function __construct($persistence = null, $defaults = []) return new Model\Scope\RootScope(); }, null, Model\Scope\RootScope::class)(); - if ((is_string($persistence) || is_array($persistence)) && func_num_args() === 1) { + if (is_array($persistence) && func_num_args() === 1) { $defaults = $persistence; $persistence = null; } - if (is_string($defaults) || $defaults === false) { + if (is_string($defaults)) { $defaults = ['table' => $defaults]; } @@ -1152,7 +1152,7 @@ public function load($id) if ($ret === false) { return $this->unload(); } elseif (is_object($ret)) { - return $ret; + return $ret; // @phpstan-ignore-line } return $this; @@ -1265,7 +1265,7 @@ public function newInstance(string $class = null, array $options = []) $model = (self::class)::fromSeed([$class ?? static::class], $options); if ($this->persistence) { - return $this->persistence->add($model); + return $this->persistence->add($model); // @phpstan-ignore-line } return $model; @@ -1337,7 +1337,7 @@ public function tryLoad($id) if ($ret === false) { return $this->unload(); } elseif (is_object($ret)) { - return $ret; + return $ret; // @phpstan-ignore-line } } else { $this->unload(); @@ -1369,7 +1369,7 @@ public function loadAny() if ($ret === false) { return $this->unload(); } elseif (is_object($ret)) { - return $ret; + return $ret; // @phpstan-ignore-line } return $this; @@ -1401,7 +1401,7 @@ public function tryLoadAny() if ($ret === false) { return $this->unload(); } elseif (is_object($ret)) { - return $ret; + return $ret; // @phpstan-ignore-line } } else { $this->unload(); @@ -1800,9 +1800,9 @@ public function getIterator(): \Traversable if (is_object($ret)) { if ($ret->id_field) { - yield $ret->getId() => $ret; + yield $ret->getId() => $ret; // @phpstan-ignore-line } else { - yield $ret; + yield $ret; // @phpstan-ignore-line } } else { if ($this->id_field) { @@ -1926,7 +1926,7 @@ public function action($mode, $args = []) /** * Add expression field. * - * @param string|array|\Closure $expression + * @param string|array|\Atk4\Dsql\Expression|\Closure $expression * * @return Field\Callback */ @@ -1939,6 +1939,7 @@ public function addExpression(string $name, $expression) unset($expression[0]); } + /** @var Field\Callback */ $field = Field::fromSeed($this->_default_seed_addExpression, $expression); $this->addField($name, $field); @@ -1962,7 +1963,11 @@ public function addCalculatedField(string $name, $expression) unset($expression[0]); } - return $this->addField($name, new Field\Callback($expression)); + $field = new Field\Callback($expression); + + $this->addField($name, $field); + + return $field; } // }}} diff --git a/src/Model/Join.php b/src/Model/Join.php index 4b84bf461..0b32a2f0c 100644 --- a/src/Model/Join.php +++ b/src/Model/Join.php @@ -38,7 +38,7 @@ class Join * If $persistence is set, then it's used for loading * and storing the values, instead $owner->persistence. * - * @var Persistence|Persistence\Sql + * @var Persistence|Persistence\Sql|null */ protected $persistence; @@ -259,7 +259,7 @@ public function addFields($fields = []) * * @param array $defaults * - * @return static + * @return self */ public function join(string $foreign_table, $defaults = []) { @@ -276,7 +276,7 @@ public function join(string $foreign_table, $defaults = []) * * @param array $defaults * - * @return static + * @return self */ public function leftJoin(string $foreign_table, $defaults = []) { @@ -316,7 +316,7 @@ public function weakJoin($defaults = []) public function hasOne(string $link, $defaults = []) { if (!is_array($defaults)) { - $defaults = ['model' => $defaults ?: 'Model_' . $link]; + $defaults = ['model' => $defaults]; } $defaults['joinName'] = $this->short_name; @@ -334,7 +334,7 @@ public function hasOne(string $link, $defaults = []) public function hasMany(string $link, $defaults = []) { if (!is_array($defaults)) { - $defaults = ['model' => $defaults ?: 'Model_' . $link]; + $defaults = ['model' => $defaults]; } $defaults = array_merge([ diff --git a/src/Model/JoinsTrait.php b/src/Model/JoinsTrait.php index f9cabc0e2..8d8210b30 100644 --- a/src/Model/JoinsTrait.php +++ b/src/Model/JoinsTrait.php @@ -12,7 +12,7 @@ trait JoinsTrait /** * The class used by join() method. * - * @var string|array + * @var array */ public $_default_seed_join = [Join::class]; @@ -23,7 +23,7 @@ trait JoinsTrait * join will also query $foreignTable in order to find additional fields. When inserting * the record will be also added inside $foreignTable and relationship will be maintained. * - * @param array $defaults + * @param array|string $defaults */ public function join(string $foreignTable, $defaults = []): Join { @@ -44,7 +44,7 @@ public function join(string $foreignTable, $defaults = []): Join * * @see join() * - * @param array $defaults + * @param array|string $defaults */ public function leftJoin(string $foreignTable, $defaults = []): Join { diff --git a/src/Model/ReferencesTrait.php b/src/Model/ReferencesTrait.php index 330f37e9e..3b4964523 100644 --- a/src/Model/ReferencesTrait.php +++ b/src/Model/ReferencesTrait.php @@ -53,7 +53,7 @@ trait ReferencesTrait protected function _hasReference(array $seed, string $link, $defaults = []): Reference { if (!is_array($defaults)) { - $defaults = ['model' => $defaults ?: 'Model_' . $link]; + $defaults = ['model' => $defaults]; } elseif (isset($defaults[0])) { $defaults['model'] = $defaults[0]; unset($defaults[0]); @@ -93,7 +93,7 @@ public function addRef(string $link, $fx): Reference */ public function hasOne(string $link, $defaults = []): Reference { - return $this->_hasReference($this->_default_seed_hasOne, $link, $defaults); + return $this->_hasReference($this->_default_seed_hasOne, $link, $defaults); // @phpstan-ignore-line } /** @@ -105,7 +105,7 @@ public function hasOne(string $link, $defaults = []): Reference */ public function hasMany(string $link, $defaults = []): Reference { - return $this->_hasReference($this->_default_seed_hasMany, $link, $defaults); + return $this->_hasReference($this->_default_seed_hasMany, $link, $defaults); // @phpstan-ignore-line } /** @@ -117,7 +117,7 @@ public function hasMany(string $link, $defaults = []): Reference */ public function containsOne(string $link, $defaults = []): Reference { - return $this->_hasReference($this->_default_seed_containsOne, $link, $defaults); + return $this->_hasReference($this->_default_seed_containsOne, $link, $defaults); // @phpstan-ignore-line } /** @@ -129,7 +129,7 @@ public function containsOne(string $link, $defaults = []): Reference */ public function containsMany(string $link, $defaults = []): Reference { - return $this->_hasReference($this->_default_seed_containsMany, $link, $defaults); + return $this->_hasReference($this->_default_seed_containsMany, $link, $defaults); // @phpstan-ignore-line } /** diff --git a/src/Model/Scope.php b/src/Model/Scope.php index c0c703ff7..fdc66fc6a 100644 --- a/src/Model/Scope.php +++ b/src/Model/Scope.php @@ -19,11 +19,7 @@ class Scope extends Scope\AbstractScope public const OR = 'OR'; public const AND = 'AND'; - /** - * Junction to use in case more than one element. - * - * @var self::AND|self::OR - */ + /** @var self::AND|self::OR Junction to use in case more than one element. */ protected $junction = self::AND; /** @@ -67,7 +63,7 @@ public function __clone() if ($this->issetOwner()) { $this->unsetOwner(); } - $this->short_name = null; + $this->short_name = null; // @phpstan-ignore-line } /** diff --git a/src/Model/Scope/Condition.php b/src/Model/Scope/Condition.php index 4e053e25f..c69763688 100644 --- a/src/Model/Scope/Condition.php +++ b/src/Model/Scope/Condition.php @@ -15,23 +15,13 @@ class Condition extends AbstractScope { use ReadableCaptionTrait; - /** - * Stores the condition key. - * - * @var string|Field|Expression - */ + /** @var string|Field|Expression */ public $key; - /** - * Stores the condition operator. - * - * @var string - */ + /** @var string */ public $operator; - /** - * Stores the condition value. - */ + /** @var mixed */ public $value; public const OPERATOR_EQUALS = '='; @@ -108,14 +98,6 @@ public function __construct($key, $operator = null, $value = null) throw new Exception('Field must be a string or an instance of Expression'); } - if (func_num_args() === 1 && is_bool($key)) { - if ($key) { - return; - } - - $key = new Expression('false'); - } - if (func_num_args() === 2) { $value = $operator; $operator = self::OPERATOR_EQUALS; @@ -245,7 +227,9 @@ public function isEmpty(): bool public function clear() { - $this->key = $this->operator = $this->value = null; + $this->key = null; // @phpstan-ignore-line + $this->operator = null; // @phpstan-ignore-line + $this->value = null; return $this; } diff --git a/src/Model/Scope/RootScope.php b/src/Model/Scope/RootScope.php index fef266cce..3317f2e09 100644 --- a/src/Model/Scope/RootScope.php +++ b/src/Model/Scope/RootScope.php @@ -14,9 +14,7 @@ */ class RootScope extends Model\Scope { - /** - * @var Model - */ + /** @var Model */ protected $model; protected function __construct(array $nestedConditions = []) diff --git a/src/Model/UserAction.php b/src/Model/UserAction.php index 354df4857..e93194490 100644 --- a/src/Model/UserAction.php +++ b/src/Model/UserAction.php @@ -45,10 +45,10 @@ class UserAction /** @var string How this action interact with record. default = 'read' */ public $modifier = self::MODIFIER_READ; - /** @var \Closure code to execute. By default will call method with same name */ + /** @var \Closure|string code to execute. By default will call method with same name */ public $callback; - /** @var \Closure code, identical to callback, but would generate preview of action without permanent effect */ + /** @var \Closure|string code, identical to callback, but would generate preview of action without permanent effect */ public $preview; /** @var string caption to put on the button */ diff --git a/src/Persistence/Array_/Join.php b/src/Persistence/Array_/Join.php index 3beaa0c15..164fbcb89 100644 --- a/src/Persistence/Array_/Join.php +++ b/src/Persistence/Array_/Join.php @@ -76,8 +76,7 @@ public function beforeInsert(array &$data): void } // Figure out where are we going to save data - $persistence = $this->persistence ?: - $this->getOwner()->persistence; + $persistence = $this->persistence ?: $this->getOwner()->persistence; $this->id = $persistence->insert( $this->getOwner(), diff --git a/src/Persistence/Csv.php b/src/Persistence/Csv.php index 97119835c..eeefa60a8 100644 --- a/src/Persistence/Csv.php +++ b/src/Persistence/Csv.php @@ -44,7 +44,7 @@ class Csv extends Persistence /** * File handle, when the $file is opened. * - * @var resource + * @var resource|null */ public $handle; @@ -81,7 +81,7 @@ class Csv extends Persistence /** * Array of field names. * - * @var array + * @var array|null */ public $header; diff --git a/src/Persistence/Sql.php b/src/Persistence/Sql.php index 03792f12f..e4bcbdfad 100644 --- a/src/Persistence/Sql.php +++ b/src/Persistence/Sql.php @@ -40,35 +40,35 @@ class Sql extends Persistence /** * Default class when adding new field. * - * @var string + * @var array */ public $_default_seed_addField = [\Atk4\Data\FieldSql::class]; /** * Default class when adding hasOne field. * - * @var string + * @var array */ public $_default_seed_hasOne = [\Atk4\Data\Reference\HasOneSql::class]; /** * Default class when adding hasMany field. * - * @var string + * @var array */ public $_default_seed_hasMany; // [\Atk4\Data\Reference\HasMany::class]; /** * Default class when adding Expression field. * - * @var string + * @var array */ public $_default_seed_addExpression = [FieldSqlExpression::class]; /** * Default class when adding join. * - * @var string + * @var array */ public $_default_seed_join = [Sql\Join::class]; @@ -109,7 +109,7 @@ public function disconnect(): void { parent::disconnect(); - $this->connection = null; + $this->connection = null; // @phpstan-ignore-line } /** @@ -693,7 +693,7 @@ public function tryLoad(Model $model, $id): ?array ->addMoreInfo('scope', $model->scope()->toWords()); } - if (!isset($data[$model->id_field]) || $data[$model->id_field] === null) { + if (!isset($data[$model->id_field])) { throw (new Exception('Model uses "id_field" but it wasn\'t available in the database')) ->addMoreInfo('model', $model) ->addMoreInfo('id_field', $model->id_field) @@ -968,7 +968,7 @@ public function lastInsertId(Model $model): string // TODO: Oracle does not support lastInsertId(), only for testing // as this does not support concurrent inserts if ($this->connection instanceof \Atk4\Dsql\Oracle\Connection) { - if ($model->id_field === false) { + if (!$model->id_field) { return ''; // TODO code should never call lastInsertId() if id field is not defined } diff --git a/src/Persistence/Sql/Join.php b/src/Persistence/Sql/Join.php index e23498a2a..1c7347b25 100644 --- a/src/Persistence/Sql/Join.php +++ b/src/Persistence/Sql/Join.php @@ -21,7 +21,7 @@ class Join extends Model\Join implements \Atk4\Dsql\Expressionable * By default we create ON expression ourselves, but if you want to specify * it, use the 'on' property. * - * @var \Atk4\Dsql\Expression + * @var \Atk4\Dsql\Expression|string|null */ protected $on; diff --git a/src/Persistence/Static_.php b/src/Persistence/Static_.php index 4e8fa000b..cc9216abd 100644 --- a/src/Persistence/Static_.php +++ b/src/Persistence/Static_.php @@ -26,7 +26,7 @@ class Static_ extends Array_ /** * Populate the following fields for the model. * - * @var string[] + * @var array */ public $fieldsForModel = []; diff --git a/src/Reference.php b/src/Reference.php index f243bce00..11ad28dfd 100644 --- a/src/Reference.php +++ b/src/Reference.php @@ -47,7 +47,7 @@ class Reference * then used inside getModel() to fully populate and associate with * persistence. * - * @var Model|string|array + * @var Model|\Closure|array */ public $model; @@ -163,16 +163,10 @@ public function createTheirModel(array $defaults = []): Model } } else { // add model from seed - if (is_array($this->model)) { - $modelDefaults = $this->model; - $theirModelSeed = [$modelDefaults[0]]; - - unset($modelDefaults[0]); - - $defaults = array_merge($modelDefaults, $defaults); - } else { - $theirModelSeed = [$this->model]; - } + $modelDefaults = $this->model; + $theirModelSeed = [$modelDefaults[0]]; + unset($modelDefaults[0]); + $defaults = array_merge($modelDefaults, $defaults); $theirModel = Factory::factory($theirModelSeed, $defaults); } diff --git a/tests-schema/ModelTest.php b/tests-schema/ModelTest.php index 8cc7e0a66..085895d62 100644 --- a/tests-schema/ModelTest.php +++ b/tests-schema/ModelTest.php @@ -28,6 +28,7 @@ public function testImportTable() $this->assertTrue(true); return; // TODO enable once import to Model is supported using DBAL + // @phpstan-ignore-next-line $this->dropTableIfExists('user'); $migrator = $this->getMigrator(); @@ -100,6 +101,7 @@ public function testCreateModel() $this->assertTrue(true); return; // TODO enable once create from Model is supported using DBAL + // @phpstan-ignore-next-line $this->dropTableIfExists('user'); $this->getMigrator(new TestUser($this->db))->create(); @@ -162,7 +164,7 @@ protected function init(): void $this->addField('is_admin', ['type' => 'boolean']); $this->addField('notes', ['type' => 'text']); - $this->hasOne('role_id', [TestRole::class, 'our_field' => 'main_role_id', 'their_field' => 'id']); + $this->hasOne('role_id', ['model' => [TestRole::class], 'our_field' => 'main_role_id', 'their_field' => 'id']); } } diff --git a/tests/BusinessModelTest.php b/tests/BusinessModelTest.php index 1ab20758b..f5ec91cf2 100644 --- a/tests/BusinessModelTest.php +++ b/tests/BusinessModelTest.php @@ -189,12 +189,9 @@ public function testException2() { $m = new Model(); $this->expectException(\Error::class); - $m->set(0, 'foo'); + $m->set(0, 'foo'); // @phpstan-ignore-line } - /** - * Fields can't be numeric. - */ public function testException2a() { $m = new Model(); @@ -202,9 +199,6 @@ public function testException2a() $m->set('3', 'foo'); } - /** - * Fields can't be numeric. - */ public function testException2b() { $m = new Model(); @@ -212,9 +206,6 @@ public function testException2b() $m->set('3b', 'foo'); } - /** - * Fields can't be numeric. - */ public function testException2c() { $m = new Model(); @@ -222,13 +213,6 @@ public function testException2c() $m->set('', 'foo'); } - public function testException3() - { - $m = new Model(); - $this->expectException(\Error::class); - $m->set(4, 5); - } - public function testClass1() { $p = new Persistence(); diff --git a/tests/ExpressionSqlTest.php b/tests/ExpressionSqlTest.php index 1a1405873..e026874cf 100644 --- a/tests/ExpressionSqlTest.php +++ b/tests/ExpressionSqlTest.php @@ -18,7 +18,7 @@ class ExpressionSqlTest extends \Atk4\Schema\PhpunitTestCase public function testNakedExpression() { $db = new Persistence\Sql($this->db->connection); - $m = new Model($db, false); + $m = new Model($db, ['table' => false]); $m->addExpression('x', '2+3'); $m->tryLoadAny(); $this->assertEquals(5, $m->get('x')); @@ -215,7 +215,7 @@ public function testReloading() public function testExpressionActionAlias() { $db = new Persistence\Sql($this->db->connection); - $m = new Model($db, false); + $m = new Model($db, ['table' => false]); $m->addExpression('x', '2+3'); // use alias as array key if it is set diff --git a/tests/LimitOrderTest.php b/tests/LimitOrderTest.php index d1fc18670..1bd325eaa 100644 --- a/tests/LimitOrderTest.php +++ b/tests/LimitOrderTest.php @@ -206,7 +206,7 @@ public function testExceptionUnsupportedOrderParam() ]); $i = (new Model($this->db, 'invoice'))->addFields(['net']); - $i->setOrder(new \DateTime()); + $i->setOrder(new \DateTime()); // @phpstan-ignore-line $this->expectException(Exception::class); $i->export(); // executes query and throws exception because of DateTime object } diff --git a/tests/RandomTest.php b/tests/RandomTest.php index bc81b04bc..1b77961f7 100644 --- a/tests/RandomTest.php +++ b/tests/RandomTest.php @@ -394,7 +394,7 @@ public function testGetTitle() $this->assertSame('John', $m->getTitle()); // returns parent record title_field // no title_field set - return id value - $m->title_field = null; + $m->title_field = null; // @phpstan-ignore-line $this->assertEquals(2, $m->getTitle()); // loaded returns id value // expression as title field diff --git a/tests/ValidationTest.php b/tests/ValidationTest.php index b38bf6bb9..2b6f81868 100644 --- a/tests/ValidationTest.php +++ b/tests/ValidationTest.php @@ -44,7 +44,7 @@ protected function init(): void public function validate($intent = null): array { - return 'This should be array'; + return 'This should be array'; // @phpstan-ignore-line } }