spatie/x-ray

GitHub: spatie/x-ray

用于扫描源代码中Ray调用的工具。

Stars: 80 | Forks: 7

# 快速扫描源代码中的 Ray 调用

x-ray logo

Package Version license Test Run Status Downloads

此包可以快速扫描源代码中对 `ray()`、`rd()`、`Ray::*` 和 `->ray()` 辅助方法的调用,这些方法来自 [spatie/ray](https://github.com/spatie/ray) 和 [spatie/laravel-ray](https://github.com/spatie/laravel-ray) 包。 主要用例是在部署前不能在源代码中留下对 `ray()` 的调用,即使 ray 已禁用。此包不会删除调用,它只是显示它们的位置,以便可以手动删除。 `x-ray` 命令的退出代码为零表示未找到 ray 调用,非零表示找到调用。这允许在如 Github Workflows 这样的自动化环境中使用此包。 访问 [myray.app](https://myray.app) 获取有关下载 Ray 调试应用程序的信息。 ## 安装 ``` composer require spatie/x-ray --dev ``` ## 使用方法 指定一个或多个有效的路径名和/或文件名以进行扫描: ``` ./vendor/bin/x-ray ./app/Actions/MyAction.php ./app/Models/*.php ./tests --snippets ``` 在 `./src` 和 `./tests` 中显示找到的调用的摘要表格,同时忽略一些文件: ``` ./vendor/bin/x-ray \ --summary \ --ignore src/MyClass.php \ --ignore 'test/fixtures/*.php' \ ./src ./tests ``` 显示每个文件名和通过/失败状态,以及紧凑的结果: ``` ./vendor/bin/x-ray ./app --compact --verbose ``` ## 可用选项 | 标志 | 描述 |---|---| |`--compact` 或 `-c` | 最小输出。在单行上显示每个结果。 | |`--github` 或 `-g` | GitHub 注释输出。使用 `error` 命令创建注释。当你在 GitHub Actions 中运行 x-ray 时很有用。 | |`--ignore` 或 `-i` | 忽略一个文件或路径,可以指定多次。接受 glob 模式。 | |`--no-progress` 或 `-P` | 在扫描文件时不要显示进度条 | |`--snippets` 或 `-S` | 显示找到的调用的代码片段 | |`--summary` 或 `-s` | 显示发现的文件/调用的摘要 | |`--verbose` 或 `-v` | 在扫描时显示每个文件名和通过/失败状态。隐含 `--no-progress`。 | ## 配置文件 在您项目的根目录中创建一个名为 `x-ray.yml` 或 `x-ray.yml.dist` 的文件以配置此包。 如果配置文件存在,它必须具有根部分 `functions` 和 `paths`。 每个部分可以有一个 `ignore` 或 `include` 项,两者都可以,或者两者都不可以。每个项包含一个字符串数组,如果两个部分中都有条目,则包括覆盖忽略。添加一个 `*` 项来忽略或包括所有匹配项(确保引用星号)。 默认情况下,`functions.include` 匹配 `ray` 和 `rd` 函数。 ``` functions: include: - '*' paths: include: - 'tests/fixtures/*' ignore: - tests - 'SettingsTest.php' ``` ## 自动化 `x-ray` 被设计为不仅作为手动工具使用,还可以与自动化工具结合使用。 ## Github 工作流程 您可以在 github 工作流程中使用 `x-ray` 以确保不会提交任何 `ray()` 调用。 以下示例工作流程运行 PHPUnit 单元测试,然后运行 `x-ray`: ``` name: run-tests on: push: branches: - main pull_request: jobs: test: runs-on: ${{ matrix.os }} strategy: fail-fast: true matrix: os: [ubuntu-latest] php: [8.3, 8.2, 8.1] name: P${{ matrix.php }} - ${{ matrix.os }} steps: - name: Checkout code uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo coverage: pcov - name: Setup problem matchers run: | echo "::add-matcher::${{ runner.tool_cache }}/php.json" echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - name: Install dependencies run: composer update --prefer-stable --prefer-dist --no-interaction - name: Execute tests run: ./vendor/bin/phpunit - name: Check for ray calls run: ./vendor/bin/x-ray . --compact ``` ## Git 钩子 在某些情况下,您可能希望使用 git `pre-commit` 钩子来避免提交任何 `ray()` 调用: ``` #!/bin/sh echo "Checking for ray() calls...\n" x-ray -s . rayScanExitCode=$? printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' - localPreCommitExitCode=0 if [ -e ./.git/hooks/pre-commit ]; then ./.git/hooks/pre-commit "$@" localPreCommitExitCode=$? fi exit $rayScanExitCode || $localPreCommitExitCode ``` 您还可以在 `package.json` 配置中使用 `x-ray` 与 husky: ``` ... "husky": { "hooks": { "pre-commit": "lint-staged && .x-ray -s ." } }, .... ``` ## 截图 各种截图可以在 [文档](docs/screenshots.md) 中查看。 ## 测试 ``` ./vendor/bin/phpunit ``` ## 更新日志 请参阅 [CHANGELOG](CHANGELOG.md) 了解最近更改的详细信息。 ## 贡献 请参阅 [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) 了解详细信息。 ## 安全漏洞 请参阅 [我们的安全策略](../../security/policy) 了解如何报告安全漏洞。 ## 致谢 - [Patrick Organ](https://github.com/patinthehat) - [Alex Vanderbist](https://github.com/AlexVanderbist) - [Tom Witkowski](https://github.com/Gummibeer) - [所有贡献者](../../contributors) ## 许可证 MIT 许可证 (MIT)。请参阅 [许可证文件](LICENSE.md) 了解更多信息。
标签:ffuf, GitHub Actions, Laravel, OpenVAS, PHP, Spatie, 代码优化, 代码分析工具, 代码安全工具, 代码定位, 代码审查, 代码审查助手, 代码审查工具, 代码审查库, 代码审查插件, 代码审查服务, 代码审查解决方案, 代码审查软件, 代码工具, 代码搜索, 代码查找, 代码清理, 代码管理, 代码维护, 代码调试, 代码质量工具, 安全可观测性, 开源框架, 持续集成, 源代码分析, 源代码分析工具, 源代码搜索, 源代码管理, 版本控制, 自动笔记