Completed
Push — master ( 796b11...f7c1ef )
by Dmitry
02:59
created

Price   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 7
c 1
b 0
f 1
lcom 2
cbo 5
dl 0
loc 48
ccs 0
cts 31
cp 0
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A tableName() 0 4 1
A conversions() 0 6 1
A getTarget() 0 4 1
A getType() 0 4 1
A getUnit() 0 4 1
A getCurrency() 0 4 1
A getEntity() 0 13 1
1
<?php
2
3
namespace hiqdev\billing\hiapi\models;
4
5
use hiqdev\php\billing\AbstractPrice as Entity;
6
use hiqdev\php\units\Quantity;
7
use Money\Money;
8
use yii\db\ActiveRecord;
9
10
/**
11
 * Class Price
12
 *
13
 * @property Target target
14
 */
15
class Price extends ActiveRecord
16
{
17
    public static function tableName()
18
    {
19
        return 'tariff_resourcez';
20
    }
21
22
    public static function conversions()
23
    {
24
        return [
25
            'id' => 'obj_id',
26
        ];
27
    }
28
29
    public function getTarget()
30
    {
31
        return $this->hasOne(Target::class, ['obj_id' => 'object_id']);
32
    }
33
34
    public function getType()
35
    {
36
        return $this->hasOne(Type::class, ['obj_id' => 'type_id']);
37
    }
38
39
    public function getUnit()
40
    {
41
        return $this->hasOne(Type::class, ['obj_id' => 'unit_id']);
42
    }
43
44
    public function getCurrency()
45
    {
46
        return $this->hasOne(Type::class, ['obj_id' => 'currency_id']);
47
    }
48
49
    public function getEntity()
50
    {
51
        $unit = $this->unit->getEntity();
0 ignored issues
show
Documentation introduced by
The property unit does not exist on object<hiqdev\billing\hiapi\models\Price>. 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
        $currency = $this->currency->getEntity();
0 ignored issues
show
Documentation introduced by
The property currency does not exist on object<hiqdev\billing\hiapi\models\Price>. 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...
53
54
        return Entity::create([
55
            'id'        => $this->obj_id,
0 ignored issues
show
Documentation introduced by
The property obj_id does not exist on object<hiqdev\billing\hiapi\models\Price>. 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...
56
            'target'    => $this->target->getEntity(),
57
            'type'      => $this->type->getEntity(),
0 ignored issues
show
Documentation introduced by
The property type does not exist on object<hiqdev\billing\hiapi\models\Price>. 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...
58
            'prepaid'   => Quantity::create($unit, $this->quantity),
0 ignored issues
show
Documentation introduced by
The property quantity does not exist on object<hiqdev\billing\hiapi\models\Price>. 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...
59
            'price'     => new Money($this->price, $currency),
0 ignored issues
show
Documentation introduced by
The property price does not exist on object<hiqdev\billing\hiapi\models\Price>. 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...
60
        ]);
61
    }
62
}
63