Completed
Push — master ( 42f197...d72e6b )
by Gilmar
24:25
created

DateTimeTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 75%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 0
cbo 0
dl 0
loc 26
ccs 9
cts 12
cp 0.75
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A dateFormat() 0 11 2
A dateGet() 0 12 2
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\Traits;
16
17
use DateTime;
18
use DateTimeZone;
19
20
trait DateTimeTrait
21
{
22 19
    protected function dateFormat($string)
23
    {
24 19
        $timezone = new DateTimeZone('UTC');
25
        try {
26 19
            $datetime = new DateTime($string, $timezone);
27
28 19
            return $datetime->format('c');
29
        } catch (\Exception $e) {
30
            return;
31
        }
32
    }
33 6
    protected function dateGet($key)
34
    {
35 6
        $value = $this->get($key);
0 ignored issues
show
Bug introduced by
It seems like get() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
36
37 6
        if (empty($value)) {
38
            return;
39
        }
40
41 6
        $string = $this->dateFormat($value);
42
43 6
        return str_replace('-03:00', '.000-03:00', $string);
44
    }
45
}
46