Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix phpstan v1.4.7 #972

Merged
merged 5 commits into from
Mar 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Persistence/Array_.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ public function action(Model $model, string $type, array $args = [])
return $action;
case 'fx':
case 'fx0':
if (!isset($args[0], $args[1])) {
if (!isset($args[0]) || !isset($args[1])) {
throw (new Exception('fx action needs 2 arguments, eg: ["sum", "amount"]'))
->addMoreInfo('action', $type);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Persistence/Sql.php
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ public function action(Model $model, string $type, array $args = [])
return $query;
case 'fx':
case 'fx0':
if (!isset($args[0], $args[1])) {
if (!isset($args[0]) || !isset($args[1])) {
throw (new Exception('fx action needs 2 arguments, eg: ["sum", "amount"]'))
->addMoreInfo('action', $type);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/ContainsMany/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @property string $ref_no @Atk4\Field()
* @property float $amount @Atk4\Field()
* @property Line $lines @Atk4\RefMany()
* @property string $total_gross @Atk4\Field()
* @property float $total_gross @Atk4\Field()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the field type must be declared as well, this is for hintable only

* @property float $discounts_total_sum @Atk4\Field()
*/
class Invoice extends Model
Expand All @@ -32,14 +32,14 @@ protected function init(): void
$this->containsMany($this->fieldName()->lines, ['model' => [Line::class], 'caption' => 'My Invoice Lines']);

// total_gross - calculated by php callback not by SQL expression
$this->addCalculatedField($this->fieldName()->total_gross, function (self $m) {
$this->addCalculatedField($this->fieldName()->total_gross, ['expr' => function (self $m) {
$total = 0;
foreach ($m->lines as $line) {
$total += $line->total_gross;
}

return $total;
});
}, 'type' => 'float']);

// discounts_total_sum - calculated by php callback not by SQL expression
$this->addCalculatedField($this->fieldName()->discounts_total_sum, function (self $m) {
Expand Down
6 changes: 3 additions & 3 deletions tests/ContainsMany/Line.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @property float $price @Atk4\Field()
* @property float $qty @Atk4\Field()
* @property \DateTime $add_date @Atk4\Field()
* @property string $total_gross @Atk4\Field()
* @property float $total_gross @Atk4\Field()
* @property Discount $discounts @Atk4\RefMany()
* @property float $discounts_percent @Atk4\Field()
*/
Expand All @@ -29,9 +29,9 @@ protected function init(): void
$this->addField($this->fieldName()->qty, ['type' => 'float', 'required' => true]);
$this->addField($this->fieldName()->add_date, ['type' => 'datetime']);

$this->addExpression($this->fieldName()->total_gross, function (self $m) {
$this->addExpression($this->fieldName()->total_gross, ['expr' => function (self $m) {
return $m->price * $m->qty * (1 + $m->vat_rate_id->rate / 100);
});
}, 'type' => 'float']);

// each line can have multiple discounts and calculate total of these discounts
$this->containsMany($this->fieldName()->discounts, ['model' => [Discount::class]]);
Expand Down
2 changes: 1 addition & 1 deletion tests/FieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ public function testCalculatedField(): void
$this->assertEquals(38, $mm->get('total'));

$d = $m->export(); // in export calculated fields are not included
$this->assertFalse(isset($d[0]['total']));
$this->assertFalse(array_key_exists('total', $d[0]));
}

public function testSystem1(): void
Expand Down