Date   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 34
c 0
b 0
f 0
ccs 10
cts 10
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A transform() 0 21 4
1
<?php
2
/**
3
 * inetprocess/transformation
4
 *
5
 * PHP Version 5.3
6
 *
7
 * @author Emmanuel Dyan
8
 * @copyright 2005-2015 iNet Process
9
 *
10
 * @package inetprocess/transformation
11
 *
12
 * @license GNU General Public License v2.0
13
 *
14
 * @link http://www.inetprocess.com
15
 */
16
17
namespace Inet\Transformation\Rule;
18
19
use Inet\Transformation\Exception\TransformationException;
20
21
/**
22
 * Transforms a Date format to another
23
 */
24
class Date extends AbstractRule
25
{
26
    /**
27
     * Operate the transformation
28
     *
29
     * @param string $input
30
     * @param array  $arguments
31
     *
32
     * @throws Inet\Transformation\Exception\TransformationException
33
     *
34
     * @return string
35
     */
36 6
    public function transform($input, array $arguments)
37
    {
38
        // I should have two arguments: old format / new format
39 6
        if (count($arguments) !== 2) {
40 2
            throw new TransformationException('Rule Date Expects exactly 2 arguments');
41
        }
42
43
        // Validate the date with the format provided
44 4
        $dateTime = \DateTime::createFromFormat($arguments[0], $input);
45 4
        if ($dateTime === false) {
46 1
            throw new TransformationException("Input ($input) or format ({$arguments[0]}) is not valid");
47
        }
48
49
        // Transform it
50 3
        $output = $dateTime->format($arguments[1]);
51 3
        if (strlen($output) === 0) {
52 1
            throw new TransformationException('Output format seems not valid. Returned date is empty');
53
        }
54
55 2
        return $output;
56
    }
57
}
58