PriceScheduleCollection   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
c 0
b 0
f 0
lcom 0
cbo 2
dl 0
loc 37
rs 10
ccs 12
cts 12
cp 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getKey() 0 4 1
A factoryEntity() 0 4 1
A getCurrent() 0 21 5
1
<?php
2
3
/*
4
 * This file is part of gpupo/netshoes-sdk
5
 * Created by Gilmar Pupo <[email protected]>
6
 * For the information of copyright and license you should read the file
7
 * LICENSE which is distributed with this source code.
8
 * Para a informação dos direitos autorais e de licença você deve ler o arquivo
9
 * LICENSE que é distribuído com este código-fonte.
10
 * Para obtener la información de los derechos de autor y la licencia debe leer
11
 * el archivo LICENSE que se distribuye con el código fuente.
12
 * For more information, see <https://www.gpupo.com/>.
13
 */
14
15
namespace Gpupo\NetshoesSdk\Entity\Product\Sku;
16
17
use Gpupo\NetshoesSdk\Entity\AbstractMetadata;
18
19
final class PriceScheduleCollection extends AbstractMetadata
20
{
21
    /**
22
     * @codeCoverageIgnore
23
     */
24
    protected function getKey()
25
    {
26
        return 'items';
27
    }
28
29 1
    protected function factoryEntity(array $data)
30
    {
31 1
        return new PriceSchedule($data);
32
    }
33
34 2
    public function getCurrent()
35
    {
36 2
        if (1 > $this->count()) {
37 1
            return;
38
        }
39
40 1
        $current = null;
41
42 1
        foreach ($this->all() as $schedule) {
43 1
            if (empty($current) || $schedule->getDateInit() > $current->getDateInit()) {
44 1
                $current = $schedule;
45
            }
46
        }
47 1
        $convert = function ($int) {
48 1
            return date('d-m-Y', ($int / 1000));
49 1
        };
50
        $current->setDateInit($convert($schedule->getDateInit()));
0 ignored issues
show
Bug introduced by
The variable $schedule seems to be defined by a foreach iteration on line 42. Are you sure the iterator is never empty, otherwise this variable is not defined?

It seems like you are relying on a variable being defined by an iteration:

foreach ($a as $b) {
}

// $b is defined here only if $a has elements, for example if $a is array()
// then $b would not be defined here. To avoid that, we recommend to set a
// default value for $b.


// Better
$b = 0; // or whatever default makes sense in your context
foreach ($a as $b) {
}

// $b is now guaranteed to be defined here.
Loading history...
51
        $current->setDateEnd($convert($schedule->getDateEnd()));
52
53
        return $current;
54
    }
55
}
56