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

keradus / PHP-CS-Fixer / 17678835382

12 Sep 2025 03:24PM UTC coverage: 94.69% (-0.06%) from 94.75%
17678835382

push

github

keradus
fix typo

1 of 1 new or added line in 1 file covered. (100.0%)

1042 existing lines in 177 files now uncovered.

28424 of 30018 relevant lines covered (94.69%)

45.5 hits per line

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

78.95
/src/Tokenizer/Analyzer/Analysis/TypeAnalysis.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of PHP CS Fixer.
7
 *
8
 * (c) Fabien Potencier <fabien@symfony.com>
9
 *     Dariusz RumiƄski <dariusz.ruminski@gmail.com>
10
 *
11
 * This source file is subject to the MIT license that is bundled
12
 * with this source code in the file LICENSE.
13
 */
14

15
namespace PhpCsFixer\Tokenizer\Analyzer\Analysis;
16

17
/**
18
 * @readonly
19
 *
20
 * @internal
21
 *
22
 * @no-named-arguments Parameter names are not covered by the backward compatibility promise.
23
 */
24
final class TypeAnalysis
25
{
26
    /**
27
     * This list contains soft and hard reserved types that can be used or will be used by PHP at some point.
28
     *
29
     * More info:
30
     *
31
     * @var non-empty-list<string>
32
     *
33
     * @see https://php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration.types
34
     * @see https://php.net/manual/en/reserved.other-reserved-words.php
35
     */
36
    private const RESERVED_TYPES = [
37
        'array',
38
        'bool',
39
        'callable',
40
        'false',
41
        'float',
42
        'int',
43
        'iterable',
44
        'list',
45
        'mixed',
46
        'never',
47
        'null',
48
        'object',
49
        'parent',
50
        'resource',
51
        'self',
52
        'static',
53
        'string',
54
        'true',
55
        'void',
56
    ];
57

58
    private string $name;
59

60
    private ?int $startIndex;
61

62
    private ?int $endIndex;
63

64
    private bool $nullable;
65

66
    /**
67
     * @param ($startIndex is null ? null : int) $endIndex
68
     */
69
    public function __construct(string $name, ?int $startIndex = null, ?int $endIndex = null)
70
    {
71
        if (str_starts_with($name, '?')) {
62✔
72
            $this->name = substr($name, 1);
4✔
73
            $this->nullable = true;
4✔
74
        } elseif (\PHP_VERSION_ID >= 8_00_00) {
59✔
75
            $this->name = $name;
59✔
76
            $this->nullable = \in_array('null', array_map('trim', explode('|', strtolower($name))), true);
59✔
77
        } else {
UNCOV
78
            $this->name = $name;
×
UNCOV
79
            $this->nullable = false;
×
80
        }
81

82
        $this->startIndex = $startIndex;
62✔
83
        $this->endIndex = $endIndex;
62✔
84
    }
85

86
    public function getName(): string
87
    {
88
        return $this->name;
1✔
89
    }
90

91
    public function getStartIndex(): int
92
    {
93
        if (null === $this->startIndex) {
1✔
UNCOV
94
            throw new \RuntimeException('TypeAnalysis: no start index.');
×
95
        }
96

97
        return $this->startIndex;
1✔
98
    }
99

100
    public function getEndIndex(): int
101
    {
102
        if (null === $this->endIndex) {
1✔
UNCOV
103
            throw new \RuntimeException('TypeAnalysis: no end index.');
×
104
        }
105

106
        return $this->endIndex;
1✔
107
    }
108

109
    public function isReservedType(): bool
110
    {
111
        return \in_array(strtolower($this->name), self::RESERVED_TYPES, true);
21✔
112
    }
113

114
    public function isNullable(): bool
115
    {
116
        return $this->nullable;
39✔
117
    }
118
}
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

© 2026 Coveralls, Inc