Completed
Push — master ( 9b0b98...ab27ce )
by Andrii
23:47 queued 08:57
created

PriceColumn   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 30
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getDataCellValue() 0 12 2
1
<?php
2
3
namespace hiqdev\yii2\cart\grid;
4
5
use hiqdev\yii2\cart\ShoppingCart;
6
use hiqdev\yii2\cart\CartPositionInterface;
7
use yii\grid\DataColumn;
8
9
class PriceColumn extends DataColumn
10
{
11
    /**
12
     * @var ShoppingCart
13
     */
14
    public $cart;
15
16
    public $format = 'html';
17
18
    public $contentOptions = ['style' => 'vertical-align: middle; white-space: nowrap;'];
19
20
    /**
21
     * @param CartPositionInterface $position
22
     * @param mixed $key
23
     * @param int $index
24
     * @return string
25
     */
26
    public function getDataCellValue($position, $key, $index): string
27
    {
28
        $price = $this->cart->formatCurrency($position->cost, $position->currency);
0 ignored issues
show
Bug introduced by
Accessing cost on the interface hiqdev\yii2\cart\CartPositionInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
Bug introduced by
Accessing currency on the interface hiqdev\yii2\cart\CartPositionInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
29
        if ($relatedPosition = $this->cart->findRelatedFor($position)) {
30
            $price .= sprintf(
31
                '&nbsp;+&nbsp;<span class="text-success text-bold">%s</span>',
32
                $this->cart->formatCurrency($relatedPosition->getCost(), $relatedPosition->currency)
0 ignored issues
show
Bug introduced by
Accessing currency on the interface hiqdev\yii2\cart\CartPositionInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
33
            );
34
        }
35
36
        return $price;
37
    }
38
}
39