DateValues::boot()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace Ghc\Rosetta\Transformers;
4
5
use Carbon\Carbon;
6
7
class DateValues extends Transformer
8
{
9
    /**
10
     * Boot Transformer.
11
     */
12
    protected function boot()
13
    {
14
        $this->addDefaultConfig([
15
            'locale'   => setlocale(LC_ALL, 0),
16
            'timezone' => date_default_timezone_get(),
17
        ]);
18
    }
19
20
    /**
21
     * @param array $data
22
     *
23
     * @return array
24
     */
25 View Code Duplication
    public function transform($data)
0 ignored issues
show
Duplication introduced by
This method 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
        foreach ($this->config['properties'] as $property) {
28
            if (isset($data[$property])) {
29
                $data[$property] = $this->parseDate($data[$property]);
30
            }
31
        }
32
33
        return $data;
34
    }
35
36
    /**
37
     * @param $value
38
     *
39
     * @return \Money\Money
40
     */
41
    private function parseDate($value)
42
    {
43
        try {
44
            $value = (new Carbon($value, $this->config['timezone']))->toIso8601String();
45
        } catch (\Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
46
        }
47
48
        return $value;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $value returns the type string which is incompatible with the documented return type Money\Money.
Loading history...
49
    }
50
}
51