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.

FormatConversionStrategy::extract()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
ccs 6
cts 6
cp 1
rs 9.4285
cc 3
eloc 7
nc 3
nop 1
crap 3
1
<?php
2
/*
3
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
4
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
5
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
6
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
7
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
8
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9
 */
10
11
namespace MpaCustomDoctrineHydrator\Stdlib\Hydrator\Strategy;
12
13
use DateTime;
14
use Zend\Stdlib\Hydrator\Strategy\StrategyInterface;
15
16
class FormatConversionStrategy implements StrategyInterface
0 ignored issues
show
Deprecated Code introduced by
The interface Zend\Stdlib\Hydrator\Strategy\StrategyInterface has been deprecated with message: Use Zend\Hydrator\Strategy\StrategyInterface from zendframework/zend-hydrator instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
17
{
18
    protected $conversionFormat;
19
20
    /**
21
     * @param  string $conversionFormat
22
     * @throws \InvalidArgumentException
23
     */
24 9
    public function __construct($conversionFormat)
25
    {
26 9
        if (!is_string($conversionFormat)) {
27 1
            throw new \InvalidArgumentException(sprintf('The strategy is expecting as string as constructor argument'));
28
        }
29 8
        $this->conversionFormat = $conversionFormat;
30 8
    }
31
32
    /**
33
     * @param  DateTime|null $value
34
     * @return string|null
35
     * @throws \InvalidArgumentException
36
     */
37 5
    public function extract($value)
38
    {
39
        /** @var $value DateTime */
40 5
        if (null !== $value) {
41 4
            if (!($value instanceof DateTime)) {
42 1
                throw new \InvalidArgumentException(sprintf('Field "%s" is not a valid DateTime object', $value));
43
            }
44
45 3
            return $value->format($this->conversionFormat);
46
        } else {
47 1
            return $value;
48
        }
49
    }
50
51
    /**
52
     * @param  string $value
53
     * @return string
54
     */
55 1
    public function hydrate($value)
56
    {
57 1
        return $value;
58
    }
59
}
60