Skip to content

Commit aec6744

Browse files
authored
Merge pull request #218 from magento-l3/ACP2E-1946
ACP2E-1946: Move PHPCompatibility/PHPCompatibility sniffs into separate namespace
2 parents df39772 + ea5897b commit aec6744

File tree

59 files changed

+4741
-4591
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+4741
-4591
lines changed

Magento2/Helpers/Assert.php

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento2\Helpers;
9+
10+
use PHP_CodeSniffer\Files\File;
11+
use PHP_CodeSniffer\Util\Tokens;
12+
use PHPCSUtils\Tokens\Collections;
13+
14+
/**
15+
* phpcs:disable Magento2.Functions.StaticFunction.StaticFunction
16+
*/
17+
class Assert
18+
{
19+
/**
20+
* Checks whether it is a built-in function call.
21+
*
22+
* @param File $phpcsFile
23+
* @param int $stackPtr
24+
* @return bool
25+
*/
26+
public static function isBuiltinFunctionCall(File $phpcsFile, int $stackPtr): bool
27+
{
28+
$tokens = $phpcsFile->getTokens();
29+
$nextPtr = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
30+
if ($nextPtr === false
31+
|| $tokens[$nextPtr]['code'] !== \T_OPEN_PARENTHESIS
32+
|| isset($tokens[$nextPtr]['parenthesis_owner'])
33+
) {
34+
return false;
35+
}
36+
37+
$prevPtr = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
38+
if ($prevPtr !== false) {
39+
if (isset(Collections::objectOperators()[$tokens[$prevPtr]['code']])
40+
|| $tokens[$prevPtr]['code'] === \T_NEW
41+
) {
42+
return false;
43+
}
44+
45+
if ($tokens[$prevPtr]['code'] === \T_NS_SEPARATOR) {
46+
$prevPrevPr = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($prevPtr - 1), null, true);
47+
if ($prevPrevPr !== false && \in_array($tokens[$prevPrevPr]['code'], [\T_STRING, \T_NAMESPACE], true)) {
48+
return false;
49+
}
50+
}
51+
}
52+
53+
return true;
54+
}
55+
}

0 commit comments

Comments
 (0)