![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/magento/magento-coding-standard/Magento2/Sniffs/Legacy/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ namespace Magento2\Sniffs\Legacy; use DOMDocument; use PHP_CodeSniffer\Files\File; use PHP_CodeSniffer\Sniffs\Sniff; /** * Test to find obsolete acl declaration */ class ObsoleteAclSniff implements Sniff { private const WARNING_OBSOLETE_ACL_STRUCTURE = 'ObsoleteAclStructure'; /** * @inheritdoc */ public function register(): array { return [ T_INLINE_HTML ]; } /** * @inheritDoc */ public function process(File $phpcsFile, $stackPtr) { if ($stackPtr > 0) { return; } $xml = simplexml_load_string($this->getFormattedXML($phpcsFile)); $foundElements = $xml->xpath('/config/acl/*[boolean(./children) or boolean(./title)]'); foreach ($foundElements as $element) { $phpcsFile->addWarning( 'Obsolete acl structure detected in line ' . dom_import_simplexml($element)->getLineNo(), dom_import_simplexml($element)->getLineNo() - 1, self::WARNING_OBSOLETE_ACL_STRUCTURE ); } } /** * Format the incoming XML to avoid tags split into several lines. * * @param File $phpcsFile * @return false|string */ private function getFormattedXML(File $phpcsFile) { $doc = new DomDocument('1.0'); $doc->formatOutput = true; $doc->loadXML($phpcsFile->getTokensAsString(0, 999999)); return $doc->saveXML(); } }