Completed
Push — master ( e11229...90bc38 )
by Gilmar
23:15
created

PriceScheduleCollection::factoryEntity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
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 <http://www.g1mr.com/>.
13
 */
14
15
namespace Gpupo\NetshoesSdk\Entity\Product\Sku;
16
17
use Gpupo\NetshoesSdk\Entity\AbstractMetadata;
18
19
class PriceScheduleCollection extends AbstractMetadata
20
{
21
    protected function getKey()
22
    {
23
        return 'items';
24
    }
25
26
    protected function factoryEntity(array $data)
27
    {
28
        return new PriceSchedule($data);
29
    }
30
31
    public function getCurrent()
32
    {
33
        if (1 > $this->count()) {
34
            return;
35
        }
36
37
        $current = null;
38
39
        foreach ($this->all() as $schedule) {
40
            if (empty($current) || $schedule->getDateInit() > $current->getDateInit()) {
41
                $current = $schedule;
42
            }
43
        }
44
        $convert = function ($int) {
45
            return date('d-m-Y', ($int / 1000));
46
        };
47
        $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 39. 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...
48
        $current->setDateEnd($convert($schedule->getDateEnd()));
49
50
        return $current;
51
    }
52
}
53