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

voku / Arrayy / 3787581697

pending completion
3787581697

push

github

Lars Moelleken
[*]: update the changelog

2479 of 2793 relevant lines covered (88.76%)

30.03 hits per line

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

83.33
/src/Type/DetectFirstValueTypeCollection.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Arrayy\Type;
6

7
use function Arrayy\array_first;
8
use Arrayy\Arrayy;
9
use Arrayy\ArrayyIterator;
10
use Arrayy\Collection\Collection;
11

12
/**
13
 * @template TKey of array-key
14
 * @template T
15
 * @extends Collection<TKey,T>
16
 */
17
final class DetectFirstValueTypeCollection extends Collection implements TypeInterface
18
{
19
    /**
20
     * @var string
21
     */
22
    private $getTypeHelper;
23

24
    /**
25
     * @param array|Arrayy|mixed $data
26
     * @param string             $iteratorClass
27
     * @param bool               $checkPropertiesInConstructor
28
     *
29
     * @phpstan-param array<TKey,T>|Arrayy<TKey,T> $data
30
     * @phpstan-param class-string<\Arrayy\ArrayyIterator> $iteratorClass
31
     */
32
    public function __construct(
33
        $data = [],
34
        string $iteratorClass = ArrayyIterator::class,
35
        bool $checkPropertiesInConstructor = true
36
    ) {
37
        /**
38
         * @psalm-suppress RedundantConditionGivenDocblockType - We also allow other types here,
39
         * but I don't know how to tell psalm about that. :/
40
         */
41
        if ($data instanceof Arrayy) {
9✔
42
            $firstValue = $data->first();
2✔
43
        } elseif (\is_array($data)) {
7✔
44
            $firstValue = array_first($data);
7✔
45
        } else {
46
            $firstValue = $data;
×
47
            $data = [$data];
×
48
        }
49

50
        $this->getTypeHelper = $this->getTypeFromFirstValue($firstValue);
9✔
51

52
        parent::__construct(
9✔
53
            $data,
9✔
54
            $iteratorClass,
55
            $checkPropertiesInConstructor
56
        );
57
    }
6✔
58

59
    /**
60
     * The type (FQCN) associated with this collection.
61
     *
62
     * @return string
63
     */
64
    public function getType()
65
    {
66
        return $this->getTypeHelper;
9✔
67
    }
68

69
    /**
70
     * @param mixed $value
71
     *
72
     * @return string
73
     */
74
    private function getTypeFromFirstValue($value): string
75
    {
76
        return \is_object($value) ? \get_class($value) : \gettype($value);
9✔
77
    }
78
}
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