• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

DerManoMann / json-object-mapper / 3868897722

pending completion
3868897722

push

github

GitHub
Merge pull request #33 from DerManoMann/refresh

357 of 409 relevant lines covered (87.29%)

33.96 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.0
/src/TypeReference/CollectionTypeReference.php
1
<?php declare(strict_types=1);
2

3
/*
4
* This file is part of the ObjectMapper library.
5
*
6
* (c) Martin Rademacher <mano@radebatz.net>
7
*
8
* For the full copyright and license information, please view the LICENSE
9
* file that was distributed with this source code.
10
*/
11

12
namespace Radebatz\ObjectMapper\TypeReference;
13

14
use Radebatz\ObjectMapper\TypeReferenceInterface;
15

16
/**
17
 * Type reference for collections.
18
 *
19
 * A `collectionType` value of `null` will be resolved as simple `array` / `[]`.
20
 */
21
class CollectionTypeReference implements TypeReferenceInterface
22
{
23
    protected $valueType;
24
    protected $collectionType = null;
25
    protected $nullable;
26

27
    /**
28
     * @param string|ClassTypeReference $valueType String values are taken as build in data type
29
     */
30
    public function __construct($valueType, ?string $collectionType = null, bool $nullable = true)
31
    {
32
        $this->valueType = $valueType;
40✔
33
        $this->collectionType = $collectionType;
40✔
34
        $this->nullable = $nullable;
40✔
35
    }
36

37
    /**
38
     * @inheritdoc
39
     */
40
    public function isCollection(): bool
41
    {
42
        return true;
37✔
43
    }
44

45
    /**
46
     * @inheritdoc
47
     */
48
    public function isNullable()
49
    {
50
        return $this->nullable;
×
51
    }
52

53
    /**
54
     * @inheritdoc
55
     */
56
    public function getType(): string
57
    {
58
        $vt = $this->getValueType();
3✔
59
        $vt = $vt instanceof TypeReferenceInterface ? $vt->getType() : $vt;
3✔
60

61
        return sprintf('%s<%s>', ($this->getCollectionType() ?: 'array'), $vt);
3✔
62
    }
63

64
    public function getValueType()
65
    {
66
        return $this->valueType;
40✔
67
    }
68

69
    public function getCollectionType(): ?string
70
    {
71
        return $this->collectionType;
40✔
72
    }
73
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc