-
Notifications
You must be signed in to change notification settings - Fork 159
/
Copy pathAssert.php
60 lines (52 loc) · 1.62 KB
/
Assert.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/**
* Copyright 2023 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);
namespace Magento2\Helpers;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Util\Tokens;
use PHPCSUtils\Tokens\Collections;
/**
* phpcs:disable Magento2.Functions.StaticFunction.StaticFunction
*/
class Assert
{
/**
* Checks whether it is a built-in function call.
*
* @param File $phpcsFile
* @param int $stackPtr
*
* @return bool
*/
public static function isBuiltinFunctionCall(File $phpcsFile, int $stackPtr): bool
{
$tokens = $phpcsFile->getTokens();
$nextPtr = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
if (
$nextPtr === false
|| $tokens[$nextPtr]['code'] !== \T_OPEN_PARENTHESIS
|| isset($tokens[$nextPtr]['parenthesis_owner'])
) {
return false;
}
$prevPtr = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
if ($prevPtr !== false) {
if (
isset(Collections::objectOperators()[$tokens[$prevPtr]['code']])
|| $tokens[$prevPtr]['code'] === \T_NEW
) {
return false;
}
if ($tokens[$prevPtr]['code'] === \T_NS_SEPARATOR) {
$prevPrevPr = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($prevPtr - 1), null, true);
if ($prevPrevPr !== false && \in_array($tokens[$prevPrevPr]['code'], [\T_STRING, \T_NAMESPACE], true)) {
return false;
}
}
}
return true;
}
}