Issues (92)

src/action/ActionRepository.php (2 issues)

1
<?php
2
/**
3
 * API for Billing
4
 *
5
 * @link      https://github.com/hiqdev/billing-hiapi
6
 * @package   billing-hiapi
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2017-2018, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\billing\hiapi\action;
12
13
use hiqdev\php\billing\action\ActionInterface;
14
use hiqdev\php\billing\action\ActionQuery;
0 ignored issues
show
The type hiqdev\php\billing\action\ActionQuery was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use hiqdev\yii\DataMapper\expressions\CallExpression;
16
use hiqdev\yii\DataMapper\expressions\HstoreExpression;
17
use hiqdev\yii\DataMapper\repositories\BaseRepository;
18
use yii\db\Query;
19
20
class ActionRepository extends BaseRepository
21
{
22
    public function save(ActionInterface $action)
23
    {
24
        $sale = $action->getSale();
25
        $time = $action->getTime();
26
        $hstore = new HstoreExpression(array_filter([
27
            'id'        => $action->getId(),
28
            'parent_id' => $action->hasParent() ? $action->getParent()->getId() : null,
29
            'object_id' => $action->getTarget()->getId(),
30
            'type'      => $action->getType()->getName(),
31
            'type_id'   => $action->getType()->getId(),
32
            'amount'    => $action->getQuantity()->getQuantity(),
33
            'sale_id'   => $sale ? $this->em->findId($sale) : null,
34
            'state'     => $action->getState() ? $action->getState()->getName() : null,
35
            'time'      => $time ? $time->format('c') : null,
0 ignored issues
show
$time is of type DateTimeImmutable, thus it always evaluated to true.
Loading history...
36
        ], static function ($value): bool {
37
            return $value !== null;
38
        }, ARRAY_FILTER_USE_BOTH));
39
        $call = new CallExpression('set_action', [$hstore]);
40
        $command = (new Query())->select($call);
41
        $action->setId($command->scalar($this->db));
42
    }
43
}
44