Skip to content

Commit ef47b1d

Browse files
committed
Update
1 parent 1eb53e7 commit ef47b1d

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[![Latest stable version](https://img.shields.io/packagist/v/kubawerlos/php-cs-fixer-custom-fixers.svg?label=current%20version)](https://packagist.org/packages/kubawerlos/php-cs-fixer-custom-fixers)
66
[![PHP version](https://img.shields.io/packagist/php-v/kubawerlos/php-cs-fixer-custom-fixers.svg)](https://php.net)
77
[![License](https://img.shields.io/github/license/kubawerlos/php-cs-fixer-custom-fixers.svg)](LICENSE)
8-
![Tests](https://img.shields.io/badge/tests-3724-brightgreen.svg)
8+
![Tests](https://img.shields.io/badge/tests-3726-brightgreen.svg)
99
[![Downloads](https://img.shields.io/packagist/dt/kubawerlos/php-cs-fixer-custom-fixers.svg)](https://packagist.org/packages/kubawerlos/php-cs-fixer-custom-fixers)
1010

1111
[![CI status](https://github.com/kubawerlos/php-cs-fixer-custom-fixers/actions/workflows/ci.yaml/badge.svg)](https://github.com/kubawerlos/php-cs-fixer-custom-fixers/actions/workflows/ci.yaml)

src/Fixer/TypedClassConstantFixer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ private static function getTypeOfExpression(Tokens $tokens, int $assignmentIndex
121121
if ($tokens[$beforeSemicolonIndex]->isGivenKind(\T_STRING)) {
122122
$lowercasedContent = \strtolower($tokens[$beforeSemicolonIndex]->getContent());
123123
if (\in_array($lowercasedContent, ['false', 'true', 'null'], true)) {
124-
return new Token([\T_STRING, $tokens[$beforeSemicolonIndex]->getContent()]);
124+
return new Token([\T_STRING, $lowercasedContent]);
125125
}
126126
}
127127

tests/Fixer/TypedClassConstantFixerTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ public static function provideFixCases(): iterable
7575
'<?php class Foo { public const BAR = null; }',
7676
];
7777

78+
yield 'NULL' => [
79+
'<?php class Foo { public const null BAR = NULL; }',
80+
'<?php class Foo { public const BAR = NULL; }',
81+
];
82+
7883
yield 'string with double quotes' => [
7984
'<?php class Foo { public const string BAR = "Jane Doe"; }',
8085
'<?php class Foo { public const BAR = "Jane Doe"; }',
@@ -94,5 +99,36 @@ public static function provideFixCases(): iterable
9499
'<?php class Foo { public const mixed BAR = 10 * (FLOAT_OR_INTEGER + 7); }',
95100
'<?php class Foo { public const BAR = 10 * (FLOAT_OR_INTEGER + 7); }',
96101
];
102+
103+
yield 'multiple constants' => [
104+
<<<'PHP'
105+
<?php
106+
class Foo {
107+
public const int ONE = 1;
108+
public const bool ALREADY_TYPED = true;
109+
public const string NAME = 'name';
110+
}
111+
const NOT_CLASS = true;
112+
class Bar {
113+
public const array ARRAY_LONG_SYNTAX = array();
114+
public const array ARRAY_SHORT_SYNTAX = [];
115+
public const string lowercased_name = 'lowercased_name';
116+
}
117+
PHP,
118+
<<<'PHP'
119+
<?php
120+
class Foo {
121+
public const ONE = 1;
122+
public const bool ALREADY_TYPED = true;
123+
public const NAME = 'name';
124+
}
125+
const NOT_CLASS = true;
126+
class Bar {
127+
public const ARRAY_LONG_SYNTAX = array();
128+
public const ARRAY_SHORT_SYNTAX = [];
129+
public const lowercased_name = 'lowercased_name';
130+
}
131+
PHP,
132+
];
97133
}
98134
}

0 commit comments

Comments
 (0)