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,18 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\TestFramework\CodingStandard\Tool;
interface BlacklistInterface
{
/**
* Set list of paths to be excluded from tool run
*
* @param array $blackList
* @return void
*/
public function setBlackList(array $blackList);
}
@@ -0,0 +1,76 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/**
* PHP Code Mess v1.3.3 tool wrapper
*/
namespace Magento\TestFramework\CodingStandard\Tool;
use \Magento\TestFramework\CodingStandard\ToolInterface;
class CodeMessDetector implements ToolInterface
{
/**
* Ruleset directory
*
* @var string
*/
private $rulesetFile;
/**
* Report file
*
* @var string
*/
private $reportFile;
/**
* Constructor
*
* @param string $rulesetDir \Directory that locates the inspection rules
* @param string $reportFile Destination file to write inspection report to
*/
public function __construct($rulesetFile, $reportFile)
{
$this->reportFile = $reportFile;
$this->rulesetFile = $rulesetFile;
}
/**
* Whether the tool can be ran on the current environment
*
* @return bool
*/
public function canRun()
{
return class_exists(\PHPMD\TextUI\Command::class);
}
/**
* {@inheritdoc}
*/
public function run(array $whiteList)
{
if (empty($whiteList)) {
return \PHPMD\TextUI\Command::EXIT_SUCCESS;
}
$commandLineArguments = [
'run_file_mock', //emulate script name in console arguments
implode(',', $whiteList),
'text', //report format
$this->rulesetFile,
'--reportfile',
$this->reportFile,
];
$options = new \PHPMD\TextUI\CommandLineOptions($commandLineArguments);
$command = new \PHPMD\TextUI\Command();
return $command->run($options, new \PHPMD\RuleSetFactory());
}
}
@@ -0,0 +1,112 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\TestFramework\CodingStandard\Tool;
use Magento\TestFramework\CodingStandard\Tool\CodeSniffer\Wrapper;
use Magento\TestFramework\CodingStandard\ToolInterface;
/**
* PHP Code Sniffer tool wrapper
*/
class CodeSniffer implements ToolInterface, ExtensionInterface
{
/**
* Ruleset directory
*
* @var string
*/
private $rulesetDir;
/**
* Report file
*
* @var string
*/
private $reportFile;
/**
* PHPCS cli tool wrapper
*
* @var Wrapper
*/
private $wrapper;
/**
* List of extensions for tool run
*
* @var array
*/
private $extensions = [
'php' => 'PHP',
'phtml' => 'PHP',
];
/**
* Constructor
*
* @param string $rulesetDir \Directory that locates the inspection rules
* @param string $reportFile Destination file to write inspection report to
* @param Wrapper $wrapper
*/
public function __construct($rulesetDir, $reportFile, Wrapper $wrapper)
{
$this->rulesetDir = $rulesetDir;
// phpcs:ignore Magento2.Functions.DiscouragedFunction
if (!file_exists($rulesetDir) && file_exists($fullPath = realpath(__DIR__ . '/../../../../' . $rulesetDir))) {
$this->rulesetDir = $fullPath;
}
$this->reportFile = $reportFile;
$this->wrapper = $wrapper;
}
/**
* @inheritdoc
*/
public function setExtensions(array $extensions)
{
$this->extensions = $extensions;
}
/**
* Whether the tool can be ran on the current environment
*
* @return bool
*/
public function canRun()
{
return class_exists('\PHP_CodeSniffer\Runner');
}
/**
* @inheritdoc
*/
public function run(array $whiteList)
{
if (empty($whiteList)) {
return 0;
}
if (!defined('PHP_CODESNIFFER_IN_TESTS')) {
define('PHP_CODESNIFFER_IN_TESTS', true);
}
$this->wrapper->checkRequirements();
$settings = [];
$settings['files'] = $whiteList;
$settings['standards'] = [$this->rulesetDir];
$settings['extensions'] = $this->extensions;
$settings['reports']['full'] = $this->reportFile;
$settings['reportWidth'] = 120;
$this->wrapper->setSettings($settings);
// phpcs:ignore Magento2.Functions.DiscouragedFunction
ob_start();
$result = $this->wrapper->runPHPCS();
ob_end_clean();
return $result;
}
}
@@ -0,0 +1,70 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/**
* PHP Code Sniffer Cli wrapper
*/
namespace Magento\TestFramework\CodingStandard\Tool\CodeSniffer;
use PHP_CodeSniffer\Config;
use PHP_CodeSniffer\Runner;
/**
* PHP Code Sniffer wrapper class
*/
class Wrapper extends Runner
{
/**
* @var array
*/
private $settings = [];
/**
* Return the current version of php code sniffer
*
* @return string
*/
public function version()
{
$version = '0.0.0';
if (defined('\PHP_CodeSniffer\Config::VERSION')) {
$version = Config::VERSION;
}
return $version;
}
/**
* Initialize PHPCS runner and modifies the configuration settings
*
* @throws \PHP_CodeSniffer\Exceptions\DeepExitException
*/
public function init()
{
$this->config->extensions = $this->settings['extensions'];
unset($this->settings['extensions']);
$settings = $this->config->getSettings();
unset($settings['files']);
$this->config->setSettings($settings);
$this->config->setSettings(array_replace_recursive(
$this->config->getSettings(),
$this->settings
));
return parent::init();
}
/**
* Sets the settings
*
* @param array $settings
*/
public function setSettings($settings)
{
$this->settings = $settings;
}
}
@@ -0,0 +1,22 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\TestFramework\CodingStandard\Tool;
/**
* Defines an interface for compatibility checks against a specific version.
*/
interface CompatibilityInterface
{
/**
* Sets the version against which to test code.
*
* @param string $version
* @return void
*/
public function setTestVersion(string $version): void;
}
@@ -0,0 +1,174 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\TestFramework\CodingStandard\Tool;
use Magento\TestFramework\CodingStandard\ToolInterface;
use SebastianBergmann\FileIterator\Facade;
use SebastianBergmann\PHPCPD\Detector\Detector;
use SebastianBergmann\PHPCPD\Detector\Strategy\DefaultStrategy;
use SebastianBergmann\PHPCPD\Log\PMD;
use SebastianBergmann\PHPCPD\Log\Text;
use Symfony\Component\Finder\Finder;
/**
* PHP Copy Paste Detector tool wrapper
*/
class CopyPasteDetector implements ToolInterface, BlacklistInterface
{
/**
* Minimum number of equal lines to identify a copy paste snippet
*/
private const MIN_LINES = 13;
/**
* Destination file to write inspection report to
*
* @var string
*/
private $reportFile;
/**
* List of paths to be excluded from tool run
*
* @var array
*/
private $blacklist;
/**
* @param string $reportFile
*/
public function __construct(string $reportFile)
{
$this->reportFile = $reportFile;
}
/**
* @inheritdoc
*/
public function setBlackList(array $blackList): void
{
$this->blacklist = $blackList;
}
/**
* Whether the tool can be run in the current environment
*
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
*
* @return bool
*/
public function canRun(): bool
{
return class_exists(Detector::class)
&& class_exists(Facade::class)
&& class_exists(Finder::class);
}
/**
* Run tool for files specified
*
* @param array $whiteList Files/directories to be inspected
* @return bool
*/
public function run(array $whiteList): bool
{
$clones = (new Detector(new DefaultStrategy()))->copyPasteDetection(
(new Facade())->getFilesAsArray(
$whiteList,
'',
'',
$this->getExclude()
),
self::MIN_LINES
);
(new PMD($this->reportFile))->processClones($clones);
(new Text)->printResult($clones, false);
return count($clones) === 0;
}
/**
* Get exclude params from blacklist
*
* @return string[]
*/
private function getExclude(): array
{
$exclude = [];
$blacklistedDirs = [];
$blacklistedFileNames = [];
$blacklistedPatterns = [];
foreach ($this->blacklist as $file) {
$file = trim($file);
if (!$file) {
continue;
}
$realPath = realpath(BP . '/' . $file);
if ($realPath === false) {
$ext = pathinfo($file, PATHINFO_EXTENSION);
if ($ext != '') {
$blacklistedFileNames[] = $file;
} else {
$blacklistedPatterns[] = $file;
}
continue;
}
$exclude[] = [$realPath];
$blacklistedDirs[] = $file;
}
foreach ($blacklistedPatterns as $pattern) {
$files = $this->find($pattern, false, $blacklistedDirs);
if (empty($files)) {
continue;
}
$exclude[] = $files;
}
foreach ($blacklistedFileNames as $fileName) {
$files = $this->find($fileName, true, $blacklistedDirs);
if (empty($files)) {
continue;
}
$exclude[] = $files;
}
return array_unique(array_merge(...$exclude));
}
/**
* Find all files by pattern
*
* @param string $pattern
* @param bool $searchFiles
* @param array $excludePaths
* @return array
*/
private function find(string $pattern, bool $searchFiles, array $excludePaths): array
{
$finder = new Finder();
$finder->in(BP);
$finder->notPath($excludePaths);
if ($searchFiles) {
$finder->files();
$finder->name($pattern);
} else {
$finder->path($pattern);
}
$result = [];
foreach ($finder as $file) {
$result[] = $file->getRealPath();
}
return $result;
}
}
@@ -0,0 +1,19 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\TestFramework\CodingStandard\Tool;
interface ExtensionInterface
{
/**
* Set extensions for tool to run
* Example: 'php', 'xml', 'phtml', 'css'
*
* @param array $extensions
* @return void
*/
public function setExtensions(array $extensions);
}
@@ -0,0 +1,108 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\TestFramework\CodingStandard\Tool;
use Magento\TestFramework\CodingStandard\ToolInterface;
/**
* PhpStan tool wrapper.
*/
class PhpStan implements ToolInterface
{
/**
* Rule level to be used.
*
* @see https://github.com/phpstan/phpstan#rule-levels
*/
private const RULE_LEVEL = 1;
/**
* Memory limit required by PHPStan for full Magento project scan.
*/
private const MEMORY_LIMIT = '4G';
/**
* Error formatter to be used.
*
* @see https://github.com/phpstan/phpstan#existing-error-formatters-to-be-used
*/
private const ERROR_FORMAT = 'filtered';
/**
* Report file.
*
* @var string
*/
private $reportFile;
/**
* PHPStan configuration file in neon format.
*
* @var string
*/
private $confFile;
/**
* @param string $confFile
* @param string $reportFile
*/
public function __construct(string $confFile, string $reportFile)
{
$this->reportFile = $reportFile;
$this->confFile = $confFile;
}
/**
* @inheritdoc
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
*/
public function canRun(): bool
{
// phpcs:disable Magento2.Security.InsecureFunction
exec($this->getCommand() . ' --version', $output, $exitCode);
return $exitCode === 0;
}
/**
* @inheritdoc
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
*/
public function run(array $whiteList): int
{
if (empty($whiteList)) {
return 0;
}
$command = $this->getCommand() . ' analyse' .
' --level ' . self::RULE_LEVEL .
' --no-progress' .
' --error-format=' . self::ERROR_FORMAT .
' --memory-limit=' . self::MEMORY_LIMIT .
// phpcs:ignore Magento2.Functions.DiscouragedFunction
' --configuration ' . escapeshellarg($this->confFile) .
' ' . implode(' ', $whiteList) .
' > ' . $this->reportFile;
// phpcs:disable Magento2.Security.InsecureFunction
exec($command, $output, $exitCode);
return $exitCode;
}
/**
* Get PHPStan CLI command
*
* @return string
*/
private function getCommand(): string
{
// phpcs:ignore Magento2.Security.IncludeFile
$vendorDir = require BP . '/app/etc/vendor_path.php';
return 'php ' . BP . '/' . $vendorDir . '/bin/phpstan';
}
}
@@ -0,0 +1,28 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/**
* Code standard tool wrapper interface
*/
namespace Magento\TestFramework\CodingStandard;
interface ToolInterface
{
/**
* Whether the tool can be ran on the current environment
*
* @return bool
*/
public function canRun();
/**
* Run tool for files specified
*
* @param array $whiteList Files/directories to be inspected
* @return int
*/
public function run(array $whiteList);
}