ltsecurityinc安防产品在线商城代码

This commit is contained in:
2026-09-14 17:47:10 +08:00
parent 57d8444c15
commit 6a3c9c5bd8
14539 changed files with 1775310 additions and 0 deletions
@@ -0,0 +1,155 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\PhpStan\Formatters;
use PHPStan\Command\AnalysisResult;
use PHPStan\Command\ErrorFormatter\TableErrorFormatter;
use PHPStan\Command\ErrorFormatter\ErrorFormatter;
use PHPStan\Command\Output;
/**
* To mute the PHPStan error message add a comment above the reported error line.
*
* Example of usage:
*
* // phpstan:ignore "Method Magento\TestModule\TestClass::testMethod() invoked with 1 parameter, 0 required."
* $this->testMethod(1);
*
* or replace some part of error message with *
*
* // phpstan:ignore "Method * invoked with 1 parameter, 0 required."
* $this->testMethod(1);
*
* or just
*
* // phpstan:ignore
* $this->testMethod(1);
*
* or
*
* $this->testMethod(1); // phpstan:ignore
*
* The error message will be suppressed.
*
* @see \Magento\PhpStan\Formatters\Fixtures\ClassWithIgnoreAnnotation
*/
class FilteredErrorFormatter implements ErrorFormatter
{
private const MUTE_ERROR_ANNOTATION = 'phpstan:ignore';
private const NO_ERRORS = 0;
/**
* @var TableErrorFormatter
*/
private $tableErrorFormatter;
/**
* @param TableErrorFormatter $tableErrorFormatter
*/
public function __construct(TableErrorFormatter $tableErrorFormatter)
{
$this->tableErrorFormatter = $tableErrorFormatter;
}
/**
* @inheritdoc
*/
public function formatErrors(AnalysisResult $analysisResult, Output $output): int
{
if (!$analysisResult->hasErrors()) {
$output->getStyle()->success('No errors');
return self::NO_ERRORS;
}
//@phpstan:ignore-line
$clearedAnalysisResult = new AnalysisResult(
$this->clearIgnoredErrors($analysisResult->getFileSpecificErrors()),
$analysisResult->getNotFileSpecificErrors(),
$analysisResult->getInternalErrors(),
$analysisResult->getWarnings(),
$analysisResult->getCollectedData(),
$analysisResult->isDefaultLevelUsed(),
$analysisResult->getProjectConfigFile(),
$analysisResult->isResultCacheSaved(),
$analysisResult->getPeakMemoryUsageBytes()
);
return $this->tableErrorFormatter->formatErrors($clearedAnalysisResult, $output);
}
/**
* Filters error list.
*
* @param array $fileSpecificErrors
* @return array
*/
private function clearIgnoredErrors(array $fileSpecificErrors): array
{
foreach ($fileSpecificErrors as $index => $error) {
$fileName = $error->getFile();
// phpcs:ignore Magento2.Functions.DiscouragedFunction
if (!file_exists($fileName)) {
continue;
}
$line = $error->getLine() ? $this->getLineWithMuteErrorAnnotation($error->getLine(), $fileName) : null;
if ($line === null) {
continue;
}
$extractErrorPattern = '@' . self::MUTE_ERROR_ANNOTATION . '\s+"(.*?)"@';
$errorPattern = preg_match($extractErrorPattern, $line, $result) ? $this->preparePattern($result[1]) : '';
if ($errorPattern && !preg_match('@' . $errorPattern . '@i', $error->getMessage())) {
continue;
}
unset($fileSpecificErrors[$index]);
}
return $fileSpecificErrors;
}
/**
* Returns context of the line with mute error annotation.
*
* @param int $errorLine
* @param string $fileName
* @return string|null
*/
private function getLineWithMuteErrorAnnotation(int $errorLine, string $fileName): ?string
{
$file = new \SplFileObject($fileName);
$lineNumbersToCheck = [
$errorLine - 2, // the line above to the line that caused the error
$errorLine - 1, // the line that caused the error
$errorLine - 3, // the line two lines above to the line that caused the error
];
foreach ($lineNumbersToCheck as $lineNumber) {
$file->seek($lineNumber > 0 ? $lineNumber : 0);
$line = $file->current();
if (strpos($line, self::MUTE_ERROR_ANNOTATION) !== false) {
return $line;
}
}
return null;
}
/**
* Prepares error pattern.
*
* @param string $errorDescription
* @return string
*/
private function preparePattern(string $errorDescription)
{
// phpcs:ignore Magento2.Functions.DiscouragedFunction
return str_replace('*', '(?:.*?)', addcslashes(trim($errorDescription), '\()[]'));
}
}
@@ -0,0 +1,105 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\PhpStan\Reflection\Php;
use Magento\Framework\DataObject;
use Magento\Framework\Session\SessionManager;
use PHPStan\DependencyInjection\Container;
use PHPStan\Reflection\Annotations\AnnotationsMethodsClassReflectionExtension;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\MethodsClassReflectionExtension;
/**
* Extension to add support of magic methods (get/set/uns/has) based on @see DataObject
*/
class DataObjectClassReflectionExtension implements MethodsClassReflectionExtension
{
private const MAGIC_METHODS_PREFIXES = [
'get',
'set',
'uns',
'has'
];
private const PREFIX_LENGTH = 3;
/**
* @var Container
*/
private $container;
/**
* @var AnnotationsMethodsClassReflectionExtension
*/
private $annotationsMethodsClassReflectionExtension;
/**
* @param Container $container
*/
public function __construct(Container $container)
{
$this->container = $container;
$this->annotationsMethodsClassReflectionExtension = $this->container
->getByType(AnnotationsMethodsClassReflectionExtension::class);
}
/**
* Check if class has relations with DataObject and requested method can be considered as a magic method.
*
* @param ClassReflection $classReflection
* @param string $methodName
*
* @return bool
*/
public function hasMethod(ClassReflection $classReflection, string $methodName): bool
{
// Workaround due to annotation extension always loads last.
if ($this->annotationsMethodsClassReflectionExtension->hasMethod($classReflection, $methodName)) {
// In case when annotation already available for the method, we will not use 'magic methods' approach.
return false;
}
if ($classReflection->isSubclassOf(DataObject::class) || $classReflection->getName() == DataObject::class) {
return in_array($this->getPrefix($methodName), self::MAGIC_METHODS_PREFIXES);
}
/** SessionManager redirects all calls to `__call` to container which extends DataObject */
if ($classReflection->isSubclassOf(SessionManager::class)
|| $classReflection->getName() === SessionManager::class
) {
/** @see \Magento\Framework\Session\SessionManager::__call */
return in_array($this->getPrefix($methodName), self::MAGIC_METHODS_PREFIXES);
}
return false;
}
/**
* Get prefix from method name.
*
* @param string $methodName
*
* @return string
*/
private function getPrefix(string $methodName): string
{
return (string)substr($methodName, 0, self::PREFIX_LENGTH);
}
/**
* Get method reflection instance.
*
* @param ClassReflection $classReflection
* @param string $methodName
*
* @return MethodReflection
*/
public function getMethod(ClassReflection $classReflection, string $methodName): MethodReflection
{
return new DataObjectMethodReflection($classReflection, $methodName);
}
}
@@ -0,0 +1,269 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\PhpStan\Reflection\Php;
use PHPStan\Reflection\ClassMemberReflection;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\FunctionVariant;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\ParameterReflection;
use PHPStan\Reflection\ParametersAcceptor;
use PHPStan\Reflection\Php\DummyParameter;
use PHPStan\TrinaryLogic;
use PHPStan\Type\BooleanType;
use PHPStan\Type\Generic\TemplateTypeMap;
use PHPStan\Type\IntegerType;
use PHPStan\Type\MixedType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\StringType;
use PHPStan\Type\Type;
use PHPStan\Type\UnionType;
use PHPStan\Type\VoidType;
/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class DataObjectMethodReflection implements MethodReflection
{
private const PREFIX_LENGTH = 3;
/**
* @var ClassReflection
*/
private $classReflection;
/**
* @var string
*/
private $methodName;
/**
* @param ClassReflection $classReflection
* @param string $methodName
*/
public function __construct(ClassReflection $classReflection, string $methodName)
{
$this->classReflection = $classReflection;
$this->methodName = $methodName;
}
/**
* Get methods class reflection.
*
* @return ClassReflection
*/
public function getDeclaringClass(): ClassReflection
{
return $this->classReflection;
}
/**
* Get if method is static.
*
* @return bool
*/
public function isStatic(): bool
{
return false;
}
/**
* Get if method is private.
*
* @return bool
*/
public function isPrivate(): bool
{
return false;
}
/**
* Get if method is public.
*
* @return bool
*/
public function isPublic(): bool
{
return true;
}
/**
* Get Method PHP Doc comment message.
*
* @return string|null
*/
public function getDocComment(): ?string
{
return null;
}
/**
* Get Method Name.
*
* @return string
*/
public function getName(): string
{
return $this->methodName;
}
/**
* Get Prototype.
*
* @return ClassMemberReflection
*/
public function getPrototype(): ClassMemberReflection
{
return $this;
}
/**
* Get Magic Methods variant based on type (get/set/has/uns).
*
* @return ParametersAcceptor[]
*/
public function getVariants(): array
{
return [
new FunctionVariant(
TemplateTypeMap::createEmpty(),
TemplateTypeMap::createEmpty(),
$this->getMethodParameters(),
false,
$this->getReturnType()
)
];
}
/**
* Get prefix from method name.
*
* @return string
*/
private function getMethodNamePrefix(): string
{
return (string)substr($this->methodName, 0, self::PREFIX_LENGTH);
}
/**
* Get Magic Methods parameters.
*
* @return ParameterReflection[]
*/
private function getMethodParameters(): array
{
$params = [];
switch ($this->getMethodNamePrefix()) {
case 'set':
$params[] = new DummyParameter(
'value',
new MixedType(),
false,
null,
false,
null
);
break;
case 'get':
$params[] = new DummyParameter(
'index',
new UnionType([new StringType(), new IntegerType()]),
true,
null,
false,
null
);
break;
}
return $params;
}
/**
* Get Magic Methods return type.
*
* @return Type
*/
private function getReturnType(): Type
{
switch ($this->getMethodNamePrefix()) {
case 'set':
case 'uns':
$returnType = new ObjectType($this->classReflection->getName());
break;
case 'has':
$returnType = new BooleanType();
break;
default:
$returnType = new MixedType();
break;
}
return $returnType;
}
/**
* Get if method is deprecated.
*
* @return TrinaryLogic
*/
public function isDeprecated(): TrinaryLogic
{
return TrinaryLogic::createNo();
}
/**
* Get deprecated description.
*
* @return string|null
*/
public function getDeprecatedDescription(): ?string
{
return null;
}
/**
* Get if method is final.
*
* @return TrinaryLogic
*/
public function isFinal(): TrinaryLogic
{
return TrinaryLogic::createNo();
}
/**
* Get if method is internal.
*
* @return TrinaryLogic
*/
public function isInternal(): TrinaryLogic
{
return TrinaryLogic::createNo();
}
/**
* Get method throw type.
*
* @return Type|null
*/
public function getThrowType(): ?Type
{
return new VoidType();
}
/**
* Get if method has side effect.
*
* @return TrinaryLogic
*/
public function hasSideEffects(): TrinaryLogic
{
return TrinaryLogic::createYes();
}
}
@@ -0,0 +1,34 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
// phpcs:disable
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Code\Generator\Io;
use Magento\Framework\Filesystem\Driver\File;
use Magento\Framework\TestFramework\Unit\Autoloader\ExtensionAttributesGenerator;
use Magento\Framework\TestFramework\Unit\Autoloader\ExtensionAttributesInterfaceGenerator;
use Magento\Framework\TestFramework\Unit\Autoloader\FactoryGenerator;
use Magento\Framework\TestFramework\Unit\Autoloader\GeneratedClassesAutoloader;
if (!defined('TESTS_TEMP_DIR')) {
//phpcs:ignore Magento2.Functions.DiscouragedFunction
define('TESTS_TEMP_DIR', dirname(__DIR__) . '/../../tmp');
}
$generatorIo = new Io(
new File(),
TESTS_TEMP_DIR . '/' . DirectoryList::getDefaultConfig()[DirectoryList::GENERATED_CODE][DirectoryList::PATH]
);
$generatedCodeAutoloader = new GeneratedClassesAutoloader(
[
new ExtensionAttributesGenerator(),
new ExtensionAttributesInterfaceGenerator(),
new FactoryGenerator(),
],
$generatorIo
);
spl_autoload_register([$generatedCodeAutoloader, 'load']);