Open guvra opened 2 years ago
Hi @guvra. Thank you for your report. To speed up processing of this issue, make sure that you provided the following information:
Make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:
@magento give me 2.4-develop instance
- upcoming 2.4.x release
For more details, review the Magento Contributor Assistant documentation.
Add a comment to assign the issue: @magento I am working on this
To learn more about issue processing workflow, refer to the Code Contributions.
Join Magento Community Engineering Slack and ask your questions in #github channel.
:warning: According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.
:clock10: You can find the schedule on the Magento Community Calendar page.
:telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.
:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel
Until it is fixed, I implemented a workaround with a phpstan extension:
<?php
declare(strict_types=1);
namespace Magento\PhpStan\Type\Php;
use Magento\Framework\Phrase;
use PhpParser\Node\Expr\FuncCall;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\FunctionReflection;
use PHPStan\Type\DynamicFunctionReturnTypeExtension;
use PHPStan\Type\ObjectType;
use PHPStan\Type\StringType;
use PHPStan\Type\Type;
use PHPStan\Type\UnionType;
class TranslationFunctionReturnTypeExtension implements DynamicFunctionReturnTypeExtension
{
public function isFunctionSupported(FunctionReflection $functionReflection): bool
{
return $functionReflection->getName() === '__';
}
public function getTypeFromFunctionCall(
FunctionReflection $functionReflection,
FuncCall $functionCall,
Scope $scope
): ?Type {
return new UnionType([new StringType(), new ObjectType(Phrase::class)]);
}
}
This workaround is not ideal, because this extension will prevent phpstan from displaying an error when a Phrase object is passed to a function that only accepts strings (e.g. public function foo(string $text)
.
Hi @engcom-Hotel. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:
[ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).Details
If the issue has a valid description, the label Issue: Format is valid
will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid
appears.
[ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description
label to the issue by yourself.
[ ] 3. Add Component: XXXXX
label(s) to the ticket, indicating the components it may be related to.
[ ] 4. Verify that the issue is reproducible on 2.4-develop
branchDetails
- Add the comment @magento give me 2.4-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.4-develop
branch, please, add the label Reproduced on 2.4.x
.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!
[ ] 5. Add label Issue: Confirmed
once verification is complete.
[ ] 6. Make sure that automatic system confirms that report has been added to the backlog.
Hello @guvra,
Thanks for the report and collaboration!
We have tried to reproduce the issue in Magento 2.4-develop instance and the issue is reproducible for us with the same steps as mentioned in the main description:
<?php
declare(strict_types=1);
namespace Foo\Bar\Controller;
use Magento\Framework\App\Action\Action; use Magento\Framework\App\Action\HttpGetActionInterface; use Magento\Framework\View\Result\Page;
class Test extends Action implements HttpGetActionInterface { public function execute() { $this->messageManager->addErrorMessage(__('foobar'));
return $this->resultFactory->create(Page::class);
}
}
2. Run PHPStan:
vendor/bin/phpstan analyse --level 6 -c dev/tests/static/testsuite/Magento/Test/Php/_files/phpstan/phpstan.neon Test.php
Please find below the screenshot of the error for reference:
<img width="1403" alt="image" src="https://user-images.githubusercontent.com/51681618/192763551-5b953ffa-628f-45a5-b58d-7b5ac201ac28.png">
Hence confirming the issue.
Thanks
:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-6760 is successfully created for this GitHub issue.
:white_check_mark: Confirmed by @engcom-Hotel. Thank you for verifying the issue.
Issue Available: @engcom-Hotel, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.
I temp. fix with this row on ignoreErrors on phpstan config file
'#Parameter \#1 \$data of method Magento\\Framework\\Escaper::escapeHtml\(\) expects array\|string, Magento\\Framework\\Phrase given.#'
Preconditions and environment
declare(strict_types=1);
at the top of php filesSteps to reproduce
declare(strict_types=1);
namespace Foo\Bar\Controller;
use Magento\Framework\App\Action\Action; use Magento\Framework\App\Action\HttpGetActionInterface; use Magento\Framework\View\Result\Page;
class Test extends Action implements HttpGetActionInterface { public function execute() { $this->messageManager->addErrorMessage(__('foobar'));
}
vendor/bin/phpstan analyse --level 6 -c dev/tests/static/testsuite/Magento/Test/Php/_files/phpstan/phpstan.neon Test.php
Parameter #1 $message of method Magento\Framework\Message\ManagerInterface::addErrorMessage() expects string, Magento\Framework\Phrase given.
Must be changed to:
In Magento\Backend\Block\Widget\Button\ButtonList:
Must be changed to:
In Magento\Framework\Message\ManagerInterface:
Must be changed to:
(same for the other addXxX methods of the same class).
In Magento\Framework\View\Page\Title:
Must be changed to:
Other option: add Stringable interface to the phrase class and use
string|Stringable
.Release note
No response
Triage and priority