Giter Site home page Giter Site logo

php-code-scanner's Introduction

Code Scanner

Introduction

It can be difficult to understand what code does exactly when working with code-bases that are large, legacy, or low quality.

Sometimes you just want to know if the code writes to disk or reads from a DB.

The purpose of this project is to give insight into which parts of code have certain behaviour. Such behaviour is called an "identity".

By default the scanner can identify code that:

  • Accesses a database
  • Accesses a network
  • Accesses the environment (ini/env/apache/etc.)
  • Accesses the filesystem
  • Sends emails
  • Uses native PHP global variables
  • Writes output (STDOUT/print/echo/etc.)

The scanner is smart enough to distinguish internal/native PHP functions and classes from user-land and vendor classes and functions.

The scanner is not meant to cover 100% of all cases, it is intended to be "good enough". If there are cases the scanner does not support, please open an issue to gain support.

Installation

Use composer to install the tool in a project:

composer require 'potherca/php-scanner'

or globally:

composer global require 'potherca/php-scanner'

Usage

Call php-scanner --help to see the most up-to-date overview iof supported options:

 ./bin/php-scanner --help

Usage: php-scanner --subject <path-to-scan> [--help] [--identifier=<path-to-identifier>] [--ignore=<path-to-ignore>]

    --subject <path-to-scan>            Path to directory or file to scan. Recurses into directories
    [--help]                            Display this information
    [--identifier=<path-to-identifier>] Path to directory or file declaring custom identifiers. Does not recurse into directories
    [--ignore=<path-to-ignore>]         Path to directory or file to exclude from scanning

Simple usage

Call php-scanner with a subject that should be scanned.

php-scanner --subject /path/to/file/or/folder

The subject can be a file or directory. If it is a directory it will be recursively scanned.

Ignore files and folders

Specific files and folders can be ignored by adding ignore flag(s).

php-scanner --subject /path/to/file/or/folder --ignore=path/to/ignore

Multiple flags can be added:

php-scanner --subject /path/to/file/or/folder --ignore=path/to/ignore --ignore=path/to/ignore.file

Note the use of the "equals" sign =. Without it the flag does not work.

The ignore path should be relative from the root of the directory to scan.

If the ignore flag points to a directory, make sure to add a slash / at the end to avoid unexpected behaviour. All files and folders in that directory will be ignored.

Custom scanning

The scanner supports custom scanners so users can expand the identities the scanner can identify.

All a custom Identifier has to do is implement the Potherca\Scanner\Identifier\IdentifierInterface

The file (or folder) containing custom Identifier(s) can be passed to the scanner using the --identifier flag.

  • Multiple identifier flags can be added
  • An "equals" sign = must be used between the falg and the path. Without it the flag does not work.
  • Directories will not be recursed into.

License

This project has been licensed under GPL-3.0 License (GNU General Public License v3.0).

Created by Potherca.

php-code-scanner's People

Contributors

potherca avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

php-code-scanner's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Edited/Blocked

These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

composer
composer.json
  • commerceguys/enum ~1.0
  • league/flysystem ~1.0
  • nikic/php-parser ~4.0
  • symfony/finder ^5.0.0

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.