DiscountAction   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 17
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A createAdjustment() 0 8 2
1
<?php
2
3
/*
4
 * This file is part of ibrand/discount.
5
 *
6
 * (c) iBrand <https://www.ibrand.cc>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace iBrand\Component\Discount\Actions;
13
14
use iBrand\Component\Discount\Contracts\AdjustmentContract;
15
use iBrand\Component\Discount\Contracts\DiscountActionContract;
16
use iBrand\Component\Discount\Contracts\DiscountContract;
17
18
abstract class DiscountAction implements DiscountActionContract
19
{
20
    /**
21
     * @param DiscountContract $discount
22
     * @param $amount
23
     *
24
     * @return mixed
25
     */
26 2
    protected function createAdjustment(DiscountContract $discount, $amount)
27
    {
28 2
        $adjustment = app(AdjustmentContract::class);
29
30 2
        $originType = $discount->isCouponBased() ? 'coupon' : 'discount';
31
32 2
        return $adjustment->createNew(AdjustmentContract::ORDER_DISCOUNT_ADJUSTMENT, $discount->label, $amount, $discount->id, $originType);
0 ignored issues
show
Bug introduced by
Accessing label on the interface iBrand\Component\Discoun...tracts\DiscountContract 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 id on the interface iBrand\Component\Discoun...tracts\DiscountContract 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