Skip to content

Commit

Permalink
Fix phpstan v1.9.3
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Dec 13, 2022
1 parent 3a13e7f commit 0a88e37
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 27 deletions.
1 change: 0 additions & 1 deletion docs/design.rst
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ Here is the code::
$order = new Model_Order();
// $order is not linked with persistence


$order = new Model_Order();
$order->setPersistence($db); // same as $order = new Model_Order($db)
// $order is associated with specific persistence layer $db
Expand Down
2 changes: 1 addition & 1 deletion docs/persistence/sql/connection.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Here is how you can use all of this together::

$connection = Atk4\Data\Persistence\Sql\Connection::connect($dsn, 'root', 'root');

echo "Time now is : ". $connection->expr('select now()');
echo 'Time now is: ' . $connection->expr('select now()');

:php:meth:`connect` will determine appropriate class that can be used for this
DSN string. This can be a PDO class or it may try to use a 3rd party connection
Expand Down
8 changes: 3 additions & 5 deletions src/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,13 @@ public function normalize($value)
}

if ($this->enum) {
if ($value === null || $value === '') {
if ($value === '') {
$value = null;
} elseif (!in_array($value, $this->enum, true)) {
throw new Exception('Value is not one of the allowed values: ' . implode(', ', $this->enum));
}
}

if ($this->values) {
if ($value === null || $value === '') {
} elseif ($this->values) {
if ($value === '') {
$value = null;
} elseif ((!is_string($value) && !is_int($value)) || !array_key_exists($value, $this->values)) {
throw new Exception('Value is not one of the allowed values: ' . implode(', ', array_keys($this->values)));
Expand Down
14 changes: 6 additions & 8 deletions src/Persistence/Sql.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,15 +281,13 @@ protected function setLimitOrder(Model $model, Query $query): void
}

// set order
if (count($model->order) > 0) {
foreach ($model->order as $order) {
$isDesc = strtolower($order[1]) === 'desc';
foreach ($model->order as $order) {
$isDesc = strtolower($order[1]) === 'desc';

if ($order[0] instanceof Expressionable) {
$query->order($order[0], $isDesc);
} else {
$query->order($model->getField($order[0]), $isDesc);
}
if ($order[0] instanceof Expressionable) {
$query->order($order[0], $isDesc);
} else {
$query->order($model->getField($order[0]), $isDesc);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Persistence/Sql/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ protected function _subrenderCondition(array $row): string

// if no condition defined - use default
if (count($row) === 2) {
$value = $cond; // @phpstan-ignore-line see https://github.com/phpstan/phpstan/issues/4173
$value = $cond;

if ($value instanceof Expressionable) {
$value = $value->getDsqlExpression($this);
Expand All @@ -542,7 +542,7 @@ protected function _subrenderCondition(array $row): string
$cond = '=';
}
} else {
$cond = strtolower($cond); // @phpstan-ignore-line see https://github.com/phpstan/phpstan/issues/4173
$cond = strtolower($cond);
}

// below we can be sure that all 3 arguments has been passed
Expand Down
2 changes: 1 addition & 1 deletion src/Schema/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function __construct(object $source)
->addMoreInfo('source', $source);
}

if ($source instanceof Model && $source->getPersistence() instanceof Persistence\Sql) {
if ($source instanceof Model) {
$this->setModel($source);
}
}
Expand Down
10 changes: 5 additions & 5 deletions tests/Persistence/ArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public function testConditionLike(): void
$m->addField('country');
$m->addField('active', ['type' => 'boolean']);

// case : str%
// case str%
$m->addCondition('country', 'LIKE', 'La%');
$result = $m->action('select')->getRows();
static::assertCount(3, $result);
Expand All @@ -310,7 +310,7 @@ public function testConditionLike(): void
static::assertSame($dbDataCountries[9], $result[9]);
unset($result);

// case : str% NOT LIKE
// case str% NOT LIKE
$m->scope()->clear();
$m->addCondition('country', 'NOT LIKE', 'La%');
$result = $m->action('select')->getRows();
Expand All @@ -323,7 +323,7 @@ public function testConditionLike(): void
static::assertSame($dbDataCountries[8], $result[8]);
unset($result);

// case : %str
// case %str
$m->scope()->clear();
$m->addCondition('country', 'LIKE', '%ia');
$result = $m->action('select')->getRows();
Expand All @@ -334,7 +334,7 @@ public function testConditionLike(): void
static::assertSame($dbDataCountries[9], $result[9]);
unset($result);

// case : %str%
// case %str%
$m->scope()->clear();
$m->addCondition('country', 'LIKE', '%a%');
$result = $m->action('select')->getRows();
Expand All @@ -348,7 +348,7 @@ public function testConditionLike(): void
static::assertSame($dbDataCountries[9], $result[9]);
unset($result);

// case : boolean field
// case boolean field
$m->scope()->clear();
$m->addCondition('active', 'LIKE', '0');
static::assertCount(4, $m->export());
Expand Down
2 changes: 1 addition & 1 deletion tests/Persistence/Sql/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function testDsnNormalize(): void
// no password
$dsn = Connection::normalizeDsn('mysql://root@localhost/db');
static::assertSame(['driver' => 'mysqli', 'host' => 'localhost', 'user' => 'root', 'dbname' => 'db'], $dsn);
$dsn = Connection::normalizeDsn('mysql://root:@localhost/db'); // see : after root
$dsn = Connection::normalizeDsn('mysql://root:@localhost/db');
static::assertSame(['driver' => 'mysqli', 'host' => 'localhost', 'user' => 'root', 'dbname' => 'db'], $dsn);

$dsn = Connection::normalizeDsn('sqlite::memory');
Expand Down
6 changes: 3 additions & 3 deletions tests/ReferenceSqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -769,12 +769,12 @@ public function testHasOneReferenceCaption(): void
$u->addField('name');
$u->addField('last_name');

// Test : Now the caption is null and is generated from field name
// now the caption is null and is generated from field name
static::assertSame('Last Name', $u->getField('last_name')->getCaption());

$u->getField('last_name')->caption = 'Surname';

// Test : Now the caption is not null and the value is returned
// now the caption is not null and the value is returned
static::assertSame('Surname', $u->getField('last_name')->getCaption());

$o = (new Model($this->db, ['table' => 'order']));
Expand All @@ -783,7 +783,7 @@ public function testHasOneReferenceCaption(): void

$referencedCaption = $o->getField('user_last_name')->getCaption();

// Test : $field->caption for the field 'last_name' is defined in referenced model (User)
// Test: $field->caption for the field 'last_name' is defined in referenced model (User)
// When Order add field from Referenced model User
// caption will be passed to Order field user_last_name
static::assertSame('Surname', $referencedCaption);
Expand Down

0 comments on commit 0a88e37

Please sign in to comment.