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.

LegsDoctrineType::getName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/*
3
 * This file is part of the prooph/php-ddd-cargo-sample.
4
 * (c) Alexander Miertsch <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 * 
9
 * Date: 01.03.14 - 17:25
10
 */
11
12
namespace Codeliner\CargoBackend\Infrastructure\Persistence\Doctrine\Type;
13
14
use Codeliner\CargoBackend\Model\Cargo\Leg;
15
use Doctrine\DBAL\Platforms\AbstractPlatform;
16
use Doctrine\DBAL\Types\ConversionException;
17
use Doctrine\DBAL\Types\TextType;
18
19
/**
20
 * Class LegsDoctrineType
21
 *
22
 * @package Codeliner\CargoBackend\Infrastructure\Persistence\Doctrine\Type
23
 * @author Alexander Miertsch <[email protected]>
24
 */
25
final class LegsDoctrineType extends TextType
26
{
27
    /**
28
     * @return string
29
     */
30
    public function getName()
31
    {
32
        return 'cargo_itinerary_legs';
33
    }
34
35
    /**
36
     * @param string $value
37
     * @param AbstractPlatform $platform
38
     * @return Leg[]
39
     */
40
    public function convertToPhpValue($value, AbstractPlatform $platform)
41
    {
42
        if (null === $value) {
43
            return [];
44
        }
45
46
        $legsData = json_decode($value, true);
47
48
        $legs = array();
49
50
        foreach($legsData as $legData) {
51
            $legs[] = new Leg(
52
                $legData['load_location'],
53
                $legData['unload_location'],
54
                \DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $legData['load_time']),
55
                \DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $legData['unload_time'])
56
            );
57
        }
58
59
        return $legs;
60
    }
61
62
    /**
63
     * @param Leg[]|null $value
64
     * @param AbstractPlatform $platform
65
     * @return string
66
     * @throws \Doctrine\DBAL\Types\ConversionException
67
     */
68
    public function convertToDatabaseValue($value, AbstractPlatform $platform)
69
    {
70
        if (null === $value) {
71
            return $value;
72
        }
73
74
        if (!is_array($value)) {
75
            throw ConversionException::conversionFailed($value, $this->getName());
76
        }
77
78
        $legsData = array();
79
80
        foreach($value as $leg) {
81
            if (!$leg instanceof Leg) {
82
                throw ConversionException::conversionFailed($value, $this->getName());
0 ignored issues
show
Documentation introduced by
$value is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
83
            }
84
85
            $legsData[] = array(
86
                'load_location'   => $leg->loadLocation(),
87
                'unload_location' => $leg->unloadLocation(),
88
                'load_time'       => $leg->loadTime()->format('Y-m-d H:i:s'),
89
                'unload_time'     => $leg->unloadTime()->format('Y-m-d H:i:s'),
90
            );
91
        }
92
93
        return json_encode($legsData);
94
    }
95
}