Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into simplify-install…
Browse files Browse the repository at this point in the history
…-instructions
  • Loading branch information
fredden committed May 16, 2023
2 parents c534321 + aec6744 commit 4d13bb7
Show file tree
Hide file tree
Showing 69 changed files with 11,046 additions and 1,793 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@

.phpunit.result.cache
.DS_Store
phpunit.xml
55 changes: 55 additions & 0 deletions Magento2/Helpers/Assert.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
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;
}
}
87 changes: 87 additions & 0 deletions Magento2/Internal/Cache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento2\Internal;

use PHP_CodeSniffer\Files\File;

/**
* Wrapper for \PHPCSUtils\Internal\Cache
*
* @see \PHPCSUtils\Internal\Cache
* @internal
*/
final class Cache
{
/**
* Wrapper for \PHPCSUtils\Internal\Cache::isCached() method.
*
* @param \PHP_CodeSniffer\Files\File $phpcsFile
* @param string $key
* @param int|string $id
*
* @return bool
* @see \PHPCSUtils\Internal\Cache::isCached()
*/
public static function isCached(File $phpcsFile, $key, $id)
{
return \PHPCSUtils\Internal\Cache::isCached($phpcsFile, $key, $id);
}

/**
* Wrapper for \PHPCSUtils\Internal\Cache::get() method.
*
* @param \PHP_CodeSniffer\Files\File $phpcsFile
* @param string $key
* @param int|string $id
*
* @return mixed
* @see \PHPCSUtils\Internal\Cache::get()
*/
public static function get(File $phpcsFile, $key, $id)
{
return \PHPCSUtils\Internal\Cache::get($phpcsFile, $key, $id);
}

/**
* Wrapper for \PHPCSUtils\Internal\Cache::getForFile() method.
*
* @param \PHP_CodeSniffer\Files\File $phpcsFile
* @param string $key
* @return array
* @see \PHPCSUtils\Internal\Cache::getForFile()
*/
public static function getForFile(File $phpcsFile, $key)
{
return \PHPCSUtils\Internal\Cache::getForFile($phpcsFile, $key);
}

/**
* Wrapper for \PHPCSUtils\Internal\Cache::set() method.
*
* @param \PHP_CodeSniffer\Files\File $phpcsFile
* @param string $key
* @param int|string $id
* @param mixed $value
* @return void
* @see \PHPCSUtils\Internal\Cache::set()
*/
public static function set(File $phpcsFile, $key, $id, $value)
{
\PHPCSUtils\Internal\Cache::set($phpcsFile, $key, $id, $value);
}

/**
* Wrapper for \PHPCSUtils\Internal\Cache::clear() method.
*
* @return void
* @see \PHPCSUtils\Internal\Cache::clear()
*/
public static function clear()
{
\PHPCSUtils\Internal\Cache::clear();
}
}
Loading

0 comments on commit 4d13bb7

Please sign in to comment.