Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,13 @@ jobs:
OUTPUT=$(../bashunit -a exit_code "1" "../../bin/phpstan analyse -vv --error-format raw")
echo "$OUTPUT"
../bashunit -a contains 'ClassUsingConstant.php:13:Constant SOME_MODE not found. [identifier=constant.notFound]' "$OUTPUT"
- script: |
cd e2e/result-cache-define
../../bin/phpstan analyse
patch -b src/define.php < changeDefineValue.patch
OUTPUT=$(../bashunit -a exit_code "1" "../../bin/phpstan analyse -vv --error-format raw")
echo "$OUTPUT"
../bashunit -a contains 'ClassUsingDefine.php:13:Method ResultCacheE2EDefine\ClassUsingDefine::getMode() should return int<1, 3> but returns 5. [identifier=return.type]' "$OUTPUT"
- script: |
cd e2e/bug-12606
export CONFIGTEST=test
Expand Down
7 changes: 7 additions & 0 deletions e2e/result-cache-define/changeDefineValue.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
--- src/define.php
+++ src/define.php
@@ -1,3 +1,3 @@
<?php

-define('SOME_DEFINED_MODE', 1);
+define('SOME_DEFINED_MODE', 5);
5 changes: 5 additions & 0 deletions e2e/result-cache-define/phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
level: 8
paths:
- src
tmpDir: tmp
16 changes: 16 additions & 0 deletions e2e/result-cache-define/src/ClassUsingDefine.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace ResultCacheE2EDefine;

class ClassUsingDefine
{

/**
* @return int<1, 3>
*/
public function getMode(): int
{
return SOME_DEFINED_MODE;
}

}
3 changes: 3 additions & 0 deletions e2e/result-cache-define/src/define.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

define('SOME_DEFINED_MODE', 1);
2 changes: 2 additions & 0 deletions e2e/result-cache-define/tmp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.*
19 changes: 19 additions & 0 deletions src/Dependency/ExportedNodeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,25 @@ public function resolve(string $fileName, Node $node): ?RootExportedNode
return new ExportedConstantsNode($constants);
}

if (
$node instanceof Node\Expr\FuncCall
&& $node->name instanceof Name
&& $node->name->toLowerString() === 'define'
) {
$args = $node->getArgs();
if (
isset($args[0], $args[1])
&& $args[0]->value instanceof Node\Scalar\String_
) {
return new ExportedConstantsNode([
new ExportedConstantNode(
$args[0]->value->value,
$this->exprPrinter->printExpr($args[1]->value),
),
]);
}
}

return null;
}

Expand Down
Loading