Failed Conditions
Push — master ( 656579...2742cd )
by Marco
11:55
created

lib/Doctrine/DBAL/Types/SimpleArrayType.php (1 issue)

1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license. For more information, see
17
 * <http://www.doctrine-project.org>.
18
 */
19
20
namespace Doctrine\DBAL\Types;
21
22
use Doctrine\DBAL\Platforms\AbstractPlatform;
23
24
/**
25
 * Array Type which can be used for simple values.
26
 *
27
 * Only use this type if you are sure that your values cannot contain a ",".
28
 *
29
 * @since  2.3
30
 * @author Johannes M. Schmitt <[email protected]>
31
 */
32
class SimpleArrayType extends Type
33
{
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
38
    {
39
        return $platform->getClobTypeDeclarationSQL($fieldDeclaration);
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function convertToDatabaseValue($value, AbstractPlatform $platform)
46
    {
47
        if (!$value) {
48
            return null;
49
        }
50
51
        return implode(',', $value);
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57 View Code Duplication
    public function convertToPHPValue($value, AbstractPlatform $platform)
58
    {
59
        if ($value === null) {
60
            return [];
61
        }
62
63
        $value = (is_resource($value)) ? stream_get_contents($value) : $value;
64
65
        return explode(',', $value);
0 ignored issues
show
It seems like $value can also be of type false; however, parameter $string of explode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

65
        return explode(',', /** @scrutinizer ignore-type */ $value);
Loading history...
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71 17
    public function getName()
72
    {
73 17
        return Type::SIMPLE_ARRAY;
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79 814
    public function requiresSQLCommentHint(AbstractPlatform $platform)
80
    {
81 814
        return true;
82
    }
83
}
84