GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 35aa2b...d96a39 )
by
unknown
31:28 queued 13:57
created

AbstractDataConverter::convertDateTimeValues()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.4285
cc 1
eloc 6
nc 1
nop 1
crap 1
1
<?php
2
namespace Dkd\PhpCmis\Converter;
3
4
/**
5
 * This file is part of php-cmis-lib.
6
 *
7
 * (c) Sascha Egerer <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
use function array_filter;
14
use function array_map;
15
use Dkd\PhpCmis\Exception\CmisRuntimeException;
16
17
/**
18
 * An Abstract data converter that contains some basic converter methods
19
 */
20
abstract class AbstractDataConverter implements DataConverterInterface
21
{
22
    /**
23
     * Cast all array values to string
24
     *
25
     * @param array $source
26 1
     * @return array
27
     */
28 1
    protected function convertStringValues(array $source)
29
    {
30
        return array_map('strval', $source);
31
    }
32
33
    /**
34
     * Cast all array values to boolean
35
     *
36
     * @param array $source
37 1
     * @return array
38
     */
39 1
    protected function convertBooleanValues(array $source)
40
    {
41 1
        return array_map('boolval', $source);
42 1
    }
43 1
44 1
    /**
45
     * Cast all array values to integer
46
     *
47
     * @param array $source
48
     * @return array
49
     */
50
    protected function convertIntegerValues(array $source)
51
    {
52
        return array_map('intval', $source);
53 1
    }
54
55 1
    /**
56
     * Cast all array values to float
57
     *
58
     * @param array $source
59
     * @return array
60
     */
61
    protected function convertDecimalValues(array $source)
62
    {
63
        return array_map('floatval', $source);
64 1
    }
65
66 1
    /**
67
     * @param array $source
68
     * @return array
69
     */
70
    protected function convertDateTimeValues($source)
71
    {
72
        return array_map(
73 1
            [$this, 'convertDateTimeValue'],
74
            array_filter(
75 1
                (array) $source,
76
                function ($item) { return !empty($item); }
77 1
            )
78 1
        );
79 1
    }
80 1
81 1
    /**
82 1
     * @param mixed $source
83 1
     * @return \DateTime
84
     */
85 1
    protected function convertDateTimeValue($source)
86
    {
87
        if (is_int($source)) {
88
            $date = new \DateTime();
89
            // DateTimes are given in a Timestamp with milliseconds.
90
            // see http://docs.oasis-open.org/cmis/CMIS/v1.1/os/CMIS-v1.1-os.html#x1-5420004
91
            $date->setTimestamp($source / 1000);
92 4
        } elseif (PHP_INT_SIZE == 4 && is_double($source)) {
93
            //TODO: 32-bit - handle this specially?
94 4
            $date = new \DateTime();
95 2
            $date->setTimestamp($source / 1000);
96
        } elseif (is_string($source)) {
97
            try {
98 2
                $date = new \DateTime($source);
99 4
            } catch (\Exception $exception) {
100
                throw new CmisRuntimeException('Invalid property value: ' . $source, 1416296900, $exception);
101
            }
102
        } else {
103 3
            throw new CmisRuntimeException(
104
                'Invalid property value: ' . (is_scalar($source) ? $source : gettype($source)),
105 2
                1416296901
106 2
            );
107 1
        }
108
109 1
        return $date;
110 1
    }
111
}
112