Skip to content

Commit 25c47df

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into psr-control-structure-spacing
2 parents 18c5d20 + aec6744 commit 25c47df

File tree

69 files changed

+11079
-1797
lines changed

Some content is hidden

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

69 files changed

+11079
-1797
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010

1111
.phpunit.result.cache
1212
.DS_Store
13+
phpunit.xml

Magento2/Helpers/Assert.php

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

Magento2/Internal/Cache.php

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento2\Internal;
8+
9+
use PHP_CodeSniffer\Files\File;
10+
11+
/**
12+
* Wrapper for \PHPCSUtils\Internal\Cache
13+
*
14+
* @see \PHPCSUtils\Internal\Cache
15+
* @internal
16+
*/
17+
final class Cache
18+
{
19+
/**
20+
* Wrapper for \PHPCSUtils\Internal\Cache::isCached() method.
21+
*
22+
* @param \PHP_CodeSniffer\Files\File $phpcsFile
23+
* @param string $key
24+
* @param int|string $id
25+
*
26+
* @return bool
27+
* @see \PHPCSUtils\Internal\Cache::isCached()
28+
*/
29+
public static function isCached(File $phpcsFile, $key, $id)
30+
{
31+
return \PHPCSUtils\Internal\Cache::isCached($phpcsFile, $key, $id);
32+
}
33+
34+
/**
35+
* Wrapper for \PHPCSUtils\Internal\Cache::get() method.
36+
*
37+
* @param \PHP_CodeSniffer\Files\File $phpcsFile
38+
* @param string $key
39+
* @param int|string $id
40+
*
41+
* @return mixed
42+
* @see \PHPCSUtils\Internal\Cache::get()
43+
*/
44+
public static function get(File $phpcsFile, $key, $id)
45+
{
46+
return \PHPCSUtils\Internal\Cache::get($phpcsFile, $key, $id);
47+
}
48+
49+
/**
50+
* Wrapper for \PHPCSUtils\Internal\Cache::getForFile() method.
51+
*
52+
* @param \PHP_CodeSniffer\Files\File $phpcsFile
53+
* @param string $key
54+
* @return array
55+
* @see \PHPCSUtils\Internal\Cache::getForFile()
56+
*/
57+
public static function getForFile(File $phpcsFile, $key)
58+
{
59+
return \PHPCSUtils\Internal\Cache::getForFile($phpcsFile, $key);
60+
}
61+
62+
/**
63+
* Wrapper for \PHPCSUtils\Internal\Cache::set() method.
64+
*
65+
* @param \PHP_CodeSniffer\Files\File $phpcsFile
66+
* @param string $key
67+
* @param int|string $id
68+
* @param mixed $value
69+
* @return void
70+
* @see \PHPCSUtils\Internal\Cache::set()
71+
*/
72+
public static function set(File $phpcsFile, $key, $id, $value)
73+
{
74+
\PHPCSUtils\Internal\Cache::set($phpcsFile, $key, $id, $value);
75+
}
76+
77+
/**
78+
* Wrapper for \PHPCSUtils\Internal\Cache::clear() method.
79+
*
80+
* @return void
81+
* @see \PHPCSUtils\Internal\Cache::clear()
82+
*/
83+
public static function clear()
84+
{
85+
\PHPCSUtils\Internal\Cache::clear();
86+
}
87+
}

0 commit comments

Comments
 (0)