Giter Club home page Giter Club logo

php-hound's Introduction

PHP Hound

Build Status Code Climate Scrutinizer Code Quality Test Coverage Packagist Version Total Downloads

This is a work in progress!

PHP Hound runs a set of quality assurance tools for PHP and reduce results to a single beautiful report.

It currently supports:

HTML index page example

Installation

PHP Hound can be installed through Composer.

Local installation

To install it locally, run the following command:

composer require alanwillms/php-hound

Then you can execute PHP Hound by running ./vendor/bin/php-hound.

Global installation

You can install PHP Hound globally with:

composer global require alanwillms/php-hound

Then you can add ~/.composer/bin directory to your PATH, so you can simply type php-hound to run it from anywhere. If you want to do this, add the following to your ~/.profile (or ~/.bashrc) file:

export PATH="$HOME/.composer/vendor/bin:$PATH"

If you want to apply the changes to your current terminal session, run source ~/.profile (or source ~/bashrc).

Command line usage

Basic usage:

# Analyze current directory files
php-hound

# Analyze "informed/directory/" files
php-hound informed/directory/

# Analyze "script.php" file
php-hound script.php

You can run php-hound --help to display a list of all available options.

php-hound [optional arguments] [path to be analysed]

Optional Arguments:
	-f format, --format format (default: text)
		Output format
	-h, --help
		Prints a usage statement
	-i ignore, --ignore ignore (default: vendor,tests,features,spec)
		Ignore a comma-separated list of directories
	-v, --version
		Prints installed version

Gradually fix legacy code

If you have a huge base of legacy code, it's really hard to fix all code issues at the same time, in a single commit.

PHP Hound helps you to gradually fix your code by only warning about issues found in the files and lines touched by a branch or commit. All other files or lines will be ignored.

That's pretty easy to achieve:

# Usage:
# php-hound --git-diff <commits or branches to compare> <target directory>

# Only return issues found on lines and files changed on the "windows10" branch:
php-hound --git-diff master..windows10 /path/to/git/repo

# Only return issues found on lines and files changed between two commits
php-hound --git-diff b28a1df..4fff883 /path/to/git/repo

php-hound's People

Contributors

alanwillms avatar guidobr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

php-hound's Issues

PHP 7: check for functions with no return type

Warn user about functions and methods that do not define a return type:

// Regex: "function.*\)\s*\{"
function foo() { ... } // wrong
function foo() : int { ... } // right

Since PHP 7.0 does not have a void return type, those warning should not return an error exit status.

Add "format" option to output in different formats

php-hound must be able to receive a --format flag containing one of the following values:

  • text (current output)
  • json
  • xml
  • csv
  • Add change log
  • Add description to the Readme file

text will be the default format when --format flag is not informed

Add "version" option

--version option must output current PHP Hound version.

-v must be added as an alias for --version.

Quality evolution over time

When outputting HTML, display a chart in its index page containing the evolution of quality (number of issues over time).

Add "ignore" option

php-hound command must be able to receive an optional flag called --ignore. This flag will receive a comma-separated list of files and/or directories which must be ignored by the analysis tools.

Also, -i must be added as an alias for --ignore.

Example:

php-hound --ignore # does nothing
php-hound --ignore=vendor/ # ignore vendor directory
php-hound --ignore=vendor,index.php # ignore vendor directory and index.php file

Check if a directory is empty before running analysis

When I run php-hound in a empty directory, it starts running forever.

~/.composer/vendor/alanwillms/php-hound/bin/php-hound
Starting analysis
Running PHPCodeSniffer...

It should display a message like "Please provide an directory with PHP code".

Supress target path in text output format file paths

Scenario:

  • current directory: /Users/alanwillms/Sites/phactory/
  • command: php-hound lib

Current output:

== /Users/alanwillms/Sites/phactory/lib/Phactory/Dependency.php ==
56: The method get uses an else expression. Else is never necessary and you can simplify the code to work without else.
62: The method get uses an else expression. Else is never necessary and you can simplify the code to work without else.

== /Users/alanwillms/Sites/phactory/lib/Phactory/Factory.php ==
66: The method getVariation uses an else expression. Else is never necessary and you can simplify the code to work without else.

Expected output:

== Phactory/Dependency.php ==
56: The method get uses an else expression. Else is never necessary and you can simplify the code to work without else.
62: The method get uses an else expression. Else is never necessary and you can simplify the code to work without else.

== Phactory/Factory.php ==
66: The method getVariation uses an else expression. Else is never necessary and you can simplify the code to work without else.

Progress indicator

php-hound should show a progress indicator on each analysis.

It could be done by counting how many files it will analyse and doing a simple % operation.

Starting analysis
Running PHPCodeSniffer... 0%

Using \r to update the same line. What do you think?

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.