Completed
Push — master ( f3d682...6367b5 )
by Gilmar
21:40
created

Shippings::factoryElement()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 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\Order\Shippings;
16
17
use Gpupo\CommonSdk\Entity\CollectionAbstract;
18
19
class Shippings extends CollectionAbstract
20
{
21 2
    public function factoryElement($data)
22
    {
23 2
        return new Shipping($data);
24
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29 11
    public function first()
30
    {
31 11
        $f = parent::first();
32
33 11
        if (empty($f)) {
34
            $o = $this->factoryElement([]);
35
            $this->addElement($o);
0 ignored issues
show
Documentation Bug introduced by
The method addElement does not exist on object<Gpupo\NetshoesSdk...er\Shippings\Shippings>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
36
37
            return $o;
38
        }
39
40 11
        return $f;
41
    }
42
}
43