Skip to content

Commit 81676df

Browse files
committed
ACP2E-2977: Implement Static test which will check for no usage of object manager in .phtml files
1 parent 5b71a74 commit 81676df

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Magento2/Sniffs/Phtml/PhtmlTemplateObjectManagerSniff.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@
2121
use PHP_CodeSniffer\Files\File;
2222
use PHP_CodeSniffer\Sniffs\Sniff;
2323

24+
/**
25+
* Class PhtmlTemplateObjectManagerSniff
26+
*
27+
* Templates must not instantiate new objects within their code.
28+
* All objects must be passed from the Block object.
29+
*
30+
* @link https://developer.adobe.com/commerce/frontend-core/guide/templates/override/#getting-argument-values-from-layout
31+
*/
2432
class PhtmlTemplateObjectManagerSniff implements Sniff
2533
{
2634
private const WARNING_CODE_OBJECT_MANAGER_USAGE = 'ObjectManagerUsageFound';
@@ -48,7 +56,7 @@ public function process(File $phpcsFile, $stackPtr)
4856

4957
$phpcsFile->addWarning(
5058
'ObjectManager should not be used in .phtml template ' .
51-
'as its not a templates responsibility to create objects.',
59+
'as it\'s not a template\'s responsibility to create objects.',
5260
$stackPtr,
5361
self::WARNING_CODE_OBJECT_MANAGER_USAGE
5462
);

0 commit comments

Comments
 (0)