Completed
Push — master ( b81036...d62670 )
by Andrii
05:59
created

SaleRepository::findId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 0
cts 11
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 1
crap 2
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, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\billing\hiapi\sale;
12
13
use hiapi\db\CallExpression;
14
use hiapi\db\HstoreExpression;
15
use hiapi\components\EntityManagerInterface;
16
use hiapi\repositories\BaseRepository;
17
use hiqdev\php\billing\sale\SaleInterface;
18
use hiqdev\php\billing\sale\SaleFactoryInterface;
19
use hiqdev\php\billing\sale\SaleQuery;
20
use hiqdev\php\billing\sale\Sale;
21
22
class SaleRepository extends BaseRepository
23
{
24
    public $queryClass = SaleQuery::class;
25
26
    /**
27
     * @var SaleFactory
28
     */
29
    protected $factory;
30
31
    public function __construct(
32
        EntityManagerInterface $em,
33
        SaleFactoryInterface $factory,
34
        array $config = []
35
    ) {
36
        parent::__construct($config);
37
38
        $this->em = $em;
0 ignored issues
show
Documentation introduced by
The property em does not exist on object<hiqdev\billing\hiapi\sale\SaleRepository>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
39
        $this->factory = $factory;
0 ignored issues
show
Documentation Bug introduced by
It seems like $factory of type object<hiqdev\php\billin...e\SaleFactoryInterface> is incompatible with the declared type object<hiqdev\billing\hiapi\sale\SaleFactory> of property $factory.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
40
    }
41
42
    public function findId(SaleInterface $sale)
43
    {
44
        $hstore = new HstoreExpression(array_filter([
45
            'buyer'     => $sale->getCustomer()->getLogin(),
46
            'buyer_id'  => $sale->getCustomer()->getId(),
47
            'object_id' => $sale->getTarget()->getId(),
48
            'tariff_id' => $sale->getPlan()->getId(),
49
        ]));
50
        $call = new CallExpression('sale_id', [$hstore]);
51
        $command = $this->em->getConnection()->createSelect($call);
0 ignored issues
show
Documentation introduced by
The property em does not exist on object<hiqdev\billing\hiapi\sale\SaleRepository>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
52
53
        return $command->scalar();
54
    }
55
}
56