Completed
Push — master ( e7303e...8fbc07 )
by Armando
02:05 queued 25s
created

ShippingOption   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A subEntities() 6 6 1
A getPrices() 16 16 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * This file is part of the TelegramBot package.
4
 *
5
 * (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Longman\TelegramBot\Entities\Payments;
12
13
use Longman\TelegramBot\Entities\Entity;
14
15
/**
16
 * Class ShippingOption
17
 *
18
 * This object represents one shipping option.
19
 *
20
 * @link https://core.telegram.org/bots/api#shippingoption
21
 *
22
 * @method string getId()    Shipping option identifier
23
 * @method string getTitle() Option title
24
 **/
25 View Code Duplication
class ShippingOption extends Entity
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
26
{
27
    /**
28
     * {@inheritdoc}
29
     */
30
    protected function subEntities()
31
    {
32
        return [
33
            'prices' => LabeledPrice::class,
34
        ];
35
    }
36
37
    /**
38
     * List of price portions
39
     *
40
     * This method overrides the default getPrices method and returns a nice array
41
     *
42
     * @return LabeledPrice[]
43
     */
44
    public function getPrices()
45
    {
46
        $all_prices = [];
47
48
        if ($these_prices = $this->getProperty('prices')) {
49
            foreach ($these_prices as $prices) {
50
                $new_prices = [];
51
                foreach ($prices as $price) {
52
                    $new_prices[] = new LabeledPrice($price);
53
                }
54
                $all_prices[] = $new_prices;
55
            }
56
        }
57
58
        return $all_prices;
59
    }
60
}
61