@@ -50,6 +50,11 @@ public static function provideFixCases(): iterable
5050 '<?php class Foo { public const BAR = [true, 1, "foo"]; } ' ,
5151 ];
5252
53+ yield 'array as result of an expression ' => [
54+ '<?php class Foo { public const array BAR = [1 => 2] + array(3 => 4) + [5 => 6]; } ' ,
55+ '<?php class Foo { public const BAR = [1 => 2] + array(3 => 4) + [5 => 6]; } ' ,
56+ ];
57+
5358 yield 'false ' => [
5459 '<?php class Foo { public const false BAR = false; } ' ,
5560 '<?php class Foo { public const BAR = false; } ' ,
@@ -60,19 +65,29 @@ public static function provideFixCases(): iterable
6065 '<?php class Foo { public const BAR = true; } ' ,
6166 ];
6267
63- yield 'float ' => [
64- '<?php class Foo { public const float BAR = 2.5; } ' ,
65- '<?php class Foo { public const BAR = 2.5; } ' ,
66- ];
67-
6868 yield 'integer ' => [
6969 '<?php class Foo { public const int BAR = 123; } ' ,
7070 '<?php class Foo { public const BAR = 123; } ' ,
7171 ];
7272
73- yield 'integer as result of sum ' => [
74- '<?php class Foo { public const int BAR = 1 + 2 + 3; } ' ,
75- '<?php class Foo { public const BAR = 1 + 2 + 3; } ' ,
73+ yield 'integer as result of an expression ' => [
74+ '<?php class Foo { public const int BAR = 1 + 2 - 3 * 4; } ' ,
75+ '<?php class Foo { public const BAR = 1 + 2 - 3 * 4; } ' ,
76+ ];
77+
78+ yield 'integer as result of an expression with parentheses ' => [
79+ '<?php class Foo { public const int BAR = 1000 * (701 + 22); } ' ,
80+ '<?php class Foo { public const BAR = 1000 * (701 + 22); } ' ,
81+ ];
82+
83+ yield 'float ' => [
84+ '<?php class Foo { public const float BAR = 2.5; } ' ,
85+ '<?php class Foo { public const BAR = 2.5; } ' ,
86+ ];
87+
88+ yield 'float as result of expression ' => [
89+ '<?php class Foo { public const float BAR = 1 + (2 - 3) * 4 / 5; } ' ,
90+ '<?php class Foo { public const BAR = 1 + (2 - 3) * 4 / 5; } ' ,
7691 ];
7792
7893 yield 'null ' => [
@@ -95,14 +110,9 @@ public static function provideFixCases(): iterable
95110 "<?php class Foo { public const BAR = 'John Doe'; } " ,
96111 ];
97112
98- yield 'unknown other constant ' => [
99- '<?php class Foo { public const mixed BAR = CONSTANT_FROM_FAR_AWAY; } ' ,
100- '<?php class Foo { public const BAR = CONSTANT_FROM_FAR_AWAY; } ' ,
101- ];
102-
103- yield 'expression of unknown type ' => [
104- '<?php class Foo { public const mixed BAR = 10 * (FLOAT_OR_INTEGER + 7); } ' ,
105- '<?php class Foo { public const BAR = 10 * (FLOAT_OR_INTEGER + 7); } ' ,
113+ yield 'string as result of concatenation ' => [
114+ '<?php class Foo { public const string BAR = "A" . 1 . "B" . 0.25 . "C"; } ' ,
115+ '<?php class Foo { public const BAR = "A" . 1 . "B" . 0.25 . "C"; } ' ,
106116 ];
107117
108118 yield 'multiple constants ' => [
@@ -136,9 +146,18 @@ class Bar {
136146 PHP,
137147 ];
138148
139- // if someone does these, they deserve to have their code broken
149+ yield 'unknown other constant ' => [
150+ '<?php class Foo { public const mixed BAR = CONSTANT_FROM_FAR_AWAY; } ' ,
151+ '<?php class Foo { public const BAR = CONSTANT_FROM_FAR_AWAY; } ' ,
152+ ];
153+
154+ yield 'expression of unknown type ' => [
155+ '<?php class Foo { public const mixed BAR = 10 * FLOAT_OR_INTEGER + 3; } ' ,
156+ '<?php class Foo { public const BAR = 10 * FLOAT_OR_INTEGER + 3; } ' ,
157+ ];
158+
140159 yield 'constant that can be of different types ' => [
141- '<?php class Foo { public const string BAR = SHOULD_BE_INT ? 1 : "one"; } ' ,
160+ '<?php class Foo { public const mixed BAR = SHOULD_BE_INT ? 1 : "one"; } ' ,
142161 '<?php class Foo { public const BAR = SHOULD_BE_INT ? 1 : "one"; } ' ,
143162 ];
144163
@@ -147,7 +166,7 @@ class Bar {
147166 <?php
148167 class HellCoreServiceManagerHelper
149168 {
150- const float OPTION_666__YES__1010011010_VALUE_4_1_3
169+ const mixed OPTION_666__YES__1010011010_VALUE_4_1_3
151170 = IS_OVERRIDEN_BY_BEELZEBOSS
152171 ? "Hell yeah"
153172 : CIRCLES_MANAGER_ACCESS === [0o1232, 'super_manager', false, -66.6]
0 commit comments