DateValues   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 23.81 %

Importance

Changes 0
Metric Value
wmc 6
dl 10
loc 42
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 5 1
A parseDate() 0 8 2
A transform() 9 9 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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