Scan source code for calls to ray() and related calls.

Overview

Quickly scan source code for calls to Ray

x-ray logo

Package Version license Test Run Status

This package can quickly scan source code for calls to ray(), rd(), Ray::*, and ->ray() helper methods from the spatie/ray and spatie/laravel-ray packages.

The primary use case is when calls to ray() cannot be left in source code before deploying, even if ray is disabled. This package does NOT remove the calls, it simply displays their locations so they can be removed manually.

The exit code of the x-ray command is zero if no ray calls are found, and non-zero if calls are found. This allows the package to be used in an automated environment such as Github Workflows.

Visit myray.app for information on downloading the Ray debugging app.

Installation

composer require spatie/x-ray --dev

Usage

Specify one or more valid path names and/or filenames to scan:

./vendor/bin/x-ray ./app/Actions/MyAction.php ./app/Models/*.php ./tests --snippets

Display a summary table of the located calls within ./src and ./tests while also ignoring some files:

./vendor/bin/x-ray \
  --summary \
  --ignore src/MyClass.php \
  --ignore 'test/fixtures/*.php' \
  ./src ./tests

Display each filename & pass/fail status, along with compact results:

./vendor/bin/x-ray ./app --compact --verbose

Available Options

Flag Description
--compact or -c Minimal output. Display each result on a single line.
--ignore or -i Ignore a file or path, can be specified multiple times. Accepts glob patterns.
--no-progress or -P Don't display the progress bar while scanning files
--snippets or -S Display code snippets from located calls
--summary or -s Display a summary of the files/calls discovered
--verbose or -v Display each filename and pass/fail status while scanning. Implies --no-progress.

Configuration files

Create a file named x-ray.yml or x-ray.yml.dist in the root directory of your project to configure the package.

If the configuration file exists, it must have the root sections functions and paths.

Each section may have an ignore or include item, both, or neither. Each item contains an array of strings, and includes override ignores if an entry exists in both. Add a * item to ignore or include all matches (make sure to quote the asterisk).

By default, functions.include matches the ray and rd functions.

functions:
  include:
    - '*'

paths:
  include:
    - 'tests/fixtures/*'
  ignore:
    - tests
    - 'SettingsTest.php'

Automation

x-ray was designed to be used not only as a manual utility, but in conjunction with automation tools.

Github workflows

You may use ray-scan within a github workflow to help ensure you don't commit any calls to ray().

The following example workflow runs unit tests with PHPUnit and then runs ray-scan:

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.0, 7.4, 7.3]

    name: P${{ matrix.php }} - ${{ matrix.os }}

    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - 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 hooks

In some cases you may want to use a git pre-commit hook to avoid commiting any ray() calls:

#!/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

You can also use ray-scan with husky in your package.json configuration:

...
"husky": {
    "hooks": {
        "pre-commit": "lint-staged && .x-ray -s ."
    }
},
....

Screenshots

Various screenshots can be viewed in the docs.

Testing

./vendor/bin/phpunit

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

You might also like...
This package makes it easy for developers to access WhatsApp Cloud API service in their PHP code.
This package makes it easy for developers to access WhatsApp Cloud API service in their PHP code.

The first PHP API to send and receive messages using a cloud-hosted version of the WhatsApp Business Platform

A RESTful and extendable Backend as a Service that provides instant backend to develop sites and apps faster, with dead-simple integration for JavaScript, iOS, Android and more.

Welcome to hook ![Gitter](https://badges.gitter.im/Join Chat.svg) hook is a RESTful, extendable Backend as a Service that provides instant backend to

Online Book Store is a E-commerce Website and Book Conversion(pdf to audio and Img to txt) and Book Sharing platform.

Online-Book-Store Online Book Store is a E-commerce Website and Book Conversion(pdf to audio and Img to txt) and Book Sharing platform. The main descr

Read and write OpenAPI 3.0.x YAML and JSON files and make the content accessible in PHP objects.

php-openapi Read and write OpenAPI 3.0.x YAML and JSON files and make the content accessible in PHP objects. It also provides a CLI tool for validatin

Simple and effective multi-format Web API Server to host your PHP API as Pragmatic REST and / or RESTful API

Luracast Restler ![Gitter](https://badges.gitter.im/Join Chat.svg) Version 3.0 Release Candidate 5 Restler is a simple and effective multi-format Web

A simple and flexible PHP middleware dispatcher based on PSR-7, PSR-11, and PSR-15

Woohoo Labs. Harmony Woohoo Labs. Harmony is a PSR-15 compatible middleware dispatcher. Harmony was born to be a totally flexible and almost invisible

This API provides functionality for creating and maintaining users to control a simple To-Do-List application. The following shows the API structure for users and tasks resources.
This API provides functionality for creating and maintaining users to control a simple To-Do-List application. The following shows the API structure for users and tasks resources.

PHP API TO-DO-LIST v.2.0 This API aims to present a brief to consume a API resources, mainly for students in the early years of Computer Science cours

a tool to get Facebook data, and some Facebook bots, and extra tools found on Facebook Toolkit ++.
a tool to get Facebook data, and some Facebook bots, and extra tools found on Facebook Toolkit ++.

FACEBOOK TOOLKIT a tool to get Facebook data, and some Facebook bots, and extra tools found on Facebook Toolkit ++. Graph API Facebook. Made with ❤️ b

Create REST and GraphQL APIs, scaffold Jamstack webapps, stream changes in real-time.
Create REST and GraphQL APIs, scaffold Jamstack webapps, stream changes in real-time.

API Platform is a next-generation web framework designed to easily create API-first projects without compromising extensibility and flexibility: Desig

Comments
Releases(1.1.1)
  • 1.1.1(Jun 29, 2022)

    What's Changed

    • Update typehint for Symfony 6 support by @patinthehat in https://github.com/spatie/x-ray/pull/4
    • Typehint for isDecorated() by @colinmackinlay in https://github.com/spatie/x-ray/pull/5
    • Add support for symfony 6 to support Laravel 9 - typehints added by @colinmackinlay in https://github.com/spatie/x-ray/pull/6
    • Bump actions/cache from 2 to 3 by @dependabot in https://github.com/spatie/x-ray/pull/8
    • Bump actions/checkout from 2 to 3 by @dependabot in https://github.com/spatie/x-ray/pull/7

    New Contributors

    • @colinmackinlay made their first contribution in https://github.com/spatie/x-ray/pull/5
    • @dependabot made their first contribution in https://github.com/spatie/x-ray/pull/8

    Full Changelog: https://github.com/spatie/x-ray/compare/1.1.0...1.1.1

    Source code(tar.gz)
    Source code(zip)
  • 1.1.0(Oct 12, 2021)

  • 1.0.0(Sep 17, 2021)

Owner
Spatie
We create products and courses for the developer community
Spatie
A bundle providing routes and glue code between Symfony and a WOPI connector.

WOPI Bundle A Symfony bundle to facilitate the implementation of the WOPI endpoints and protocol. Description The Web Application Open Platform Interf

Champs-Libres 5 Aug 20, 2022
Modern version of pocketmine forms API, ported to PHP 8.0+ with high quality code and phpstan integration

forms Modern version of pocketmine forms API, ported to PHP 8.0+ with high quality code and phpstan integration Code samples ModalForm Using ModalForm

Frago9876543210 23 Nov 18, 2022
Open source API management platform

About Fusio is an open source API management platform which helps to build and manage REST APIs. Fusio provides all tools to quickly build an API from

Apioo 1.2k Jan 4, 2023
An open source PHP framework for the mcsrvstat.us api

MinePHP An open source PHP framework for the Minecraft Server Status API. Installation Clone the repository in the first place. git clone https://gith

null 2 May 23, 2022
Official docker container of Fusio an open source API management system

Fusio docker container Official docker container of Fusio. More information about Fusio at: https://www.fusio-project.org Usage The most simple usage

Apioo 28 Dec 13, 2022
Open Source Telecommunications API Platform

A reimplementation of the open source Plivo framework on top of ReactPHP and FreeSWITCH. If you are not familiar with the legacy platform, please inspect its repository as well as the archived web resources here, here and here.

rtckit 33 Nov 25, 2022
Check a project's code coverage, optionally enforcing a minimum value

coverage-check Display the code coverage for a project using a clover.xml file, optionally enforcing a minimum code coverage percentage. This package

Permafrost Software 15 Aug 9, 2022
Judge0 API integration for running/judging code with different languages

Laravel Judge0 Judge0 API integration for running/judging code with different languages use Mouadbnl\Judge0\Models\Submission; $submission = Submissi

Mouad Benali 10 Dec 6, 2022
Collection of value objects that represent the PHP code units

sebastian/code-unit Collection of value objects that represent the PHP code units. Installation You can add this library as a local, per-project depen

Sebastian Bergmann 740 Dec 29, 2022
Code shared by the schema packages

Code shared by the schema packages

PoP CMS Schema 2 Nov 4, 2022