Skip to content

Commit 9fcc4da

Browse files
author
Oleksandr Gorkun
committed
MAGETWO-89540: Static CompilerTest doesn't understand nullable type hint
1 parent 452710d commit 9fcc4da

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

dev/tests/integration/testsuite/Magento/Framework/Code/Reader/SourceArgumentsReaderTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public function getConstructorArgumentTypesDataProvider()
4444
'\Imported\Name\Space\ClassName\Under\Test',
4545
'\Imported\Name\Space\ClassName',
4646
'\Some\Testing\Name\Space\Test',
47+
'\Exception',
48+
'\Imported\Name\Space\ClassName',
4749
'array',
4850
''
4951
],

dev/tests/integration/testsuite/Magento/Framework/Code/Reader/_files/SourceArgumentsReaderTest.php.sample

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class AnotherSimpleClass
1919
ClassName\Under\Test $itemFive,
2020
ClassName $itemSix,
2121
Test $itemSeven,
22+
?\Exception $optionalException,
23+
?ClassName $optionalWithDefaultValue = null,
2224
array $itemEight = [],
2325
$itemNine = 'test'
2426
) {

lib/internal/Magento/Framework/Code/Reader/SourceArgumentsReader.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function getConstructorArgumentTypes(\ReflectionClass $class, $inherited
5656
$source = '<?php ' . trim(implode('', $fileContent));
5757

5858
// Remove parameter default value.
59-
$source = preg_replace("/ = (.*)/", ',)', $source);
59+
$source = preg_replace("/(\s*)=([^\,\)]*)/", '', $source);
6060

6161
$methodTokenized = token_get_all($source);
6262
$argumentsStart = array_search('(', $methodTokenized) + 1;
@@ -85,6 +85,9 @@ public function getConstructorArgumentTypes(\ReflectionClass $class, $inherited
8585
foreach ($arguments as $key => &$argument) {
8686
$argument = $this->removeToken($argument, '=');
8787
$argument = $this->removeToken($argument, '&');
88+
if (mb_strpos($argument, '?') === 0) {
89+
$argument = mb_substr($argument, 1);
90+
}
8891
$argument = $this->namespaceResolver->resolveNamespace($argument, $availableNamespaces);
8992
}
9093
unset($argument);

0 commit comments

Comments
 (0)