<commit_before>Phan is a static analyzer for PHP.

[![Code Climate](https://codeclimate.com/github/etsy/phan/badges/gpa.svg)](https://codeclimate.com/github/etsy/phan) [![Build Status](https://travis-ci.org/etsy/phan.svg?branch=master)](https://travis-ci.org/etsy/phan) [![Gitter](https://badges.gitter.im/etsy/phan.svg)](https://gitter.im/etsy/phan?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)

# Features

* Checks for all methods, functions, classes, traits, interfaces, constants, properties and variables to be defined and accessible.
* Checks for type safety and arity issues on method/function/closure calls.
* Checks for PHP7/PHP5 backward compatibility
* Checks for sanity with array accesses
* Checks for type safety on binary operations
* Checks for valid and type safe return values on methods, functions, and closures
* Checks for No-Ops on arrays, closures, constants, properties, variables.
* Checks for unused/dead code.
* Checks for classes, functions and methods being redefined
* Supports namespaces, traits and variadics
* Supports [Union Types](https://github.com/etsy/phan/wiki/About-Union-Types)
* Supports generic arrays such as `int[]`, `UserObject[]`, etc..
* Supports phpdoc [type annotations](https://github.com/etsy/phan/wiki/Annotating-Your-Source-Code)
* Supports `@deprecated` annotation for deprecating classes, methods and functions
* Supports `@suppress <ISSUE_TYPE>` annotations for [suppressing issues](https://github.com/etsy/phan/wiki/Annotating-Your-Source-Code#suppress).
* Offers extensive configuration for weakening the analysis to make it useful on large sloppy code bases
* Can be run on many cores.
* Output is emitted in text, checkstyle, json or codeclimate formats.

See [Phan Error Types](https://github.com/etsy/phan/wiki/Issue-Types-Caught-by-Phan) for descriptions
and examples of all issues that can be detected by Phan. Take a look at the
[\Phan\Issue](https://github.com/etsy/phan/blob/master/src/Phan/Issue.php) to see the
definition of each error type.

Take a look at the [Tutorial for Analyzing a Large Sloppy Code Base](https://github.com/etsy/phan/wiki/Tutorial-for-Analyzing-a-Large-Sloppy-Code-Base) to get a sense of what the process of doing ongoing analysis might look like for you.

See the [tests][tests] directory for some examples of the various checks.

# Getting it running

Phan requires PHP 7+ with the [php-ast][phpast] and sqlite extension loaded. The code you analyze can be written for any version of PHP.

## Standalone usage

To get phan running;

1. Clone the repo
2. Run `composer install` to load dependencies
3. Test phan on itself by running the following

```sh
./phan
```

You can see the full list of command line options by running `phan -h`.

## Attaching it to your project integration process

Require a dependency:
```sh
composer require --dev "etsy/phan:dev-master"
```

Define a step or run manually
```sh
find src/ -type f -name '*.php' > phan.in
./vendor/bin/phan -f phan.in -3 vendor -o phan.out
```

The `phan.out` file will contain the analyzer output. This should look like this:

```
test1.php:191 UndefError call to undefined function get_real_size()
test1.php:232 UndefError static call to undeclared class core\session\manager
test1.php:386 UndefError Trying to instantiate undeclared class lang_installer
test2.php:4 TypeError arg#1(arg) is object but escapeshellarg() takes string
test2.php:4 TypeError arg#1(msg) is int but logmsg() takes string defined at sth.php:5
test2.php:4 TypeError arg#2(level) is string but logmsg() takes int defined at sth.php:5
test3.php:11 TypeError arg#1(number) is string but number_format() takes float
test3.php:12 TypeError arg#1(string) is int but htmlspecialchars() takes string
test3.php:13 TypeError arg#1(str) is int but md5() takes string
test3.php:14 TypeError arg#1(separator) is int but explode() takes string
test3.php:14 TypeError arg#2(str) is int but explode() takes string
```

You can see the full list of command line options by running `./vendor/bin/phan -h`.
<commit_msg>Update of README to add homebrew instalation<commit_after>Phan is a static analyzer for PHP.

[![Code Climate](https://codeclimate.com/github/etsy/phan/badges/gpa.svg)](https://codeclimate.com/github/etsy/phan) [![Build Status](https://travis-ci.org/etsy/phan.svg?branch=master)](https://travis-ci.org/etsy/phan) [![Gitter](https://badges.gitter.im/etsy/phan.svg)](https://gitter.im/etsy/phan?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)

# Features

* Checks for all methods, functions, classes, traits, interfaces, constants, properties and variables to be defined and accessible.
* Checks for type safety and arity issues on method/function/closure calls.
* Checks for PHP7/PHP5 backward compatibility
* Checks for sanity with array accesses
* Checks for type safety on binary operations
* Checks for valid and type safe return values on methods, functions, and closures
* Checks for No-Ops on arrays, closures, constants, properties, variables.
* Checks for unused/dead code.
* Checks for classes, functions and methods being redefined
* Supports namespaces, traits and variadics
* Supports [Union Types](https://github.com/etsy/phan/wiki/About-Union-Types)
* Supports generic arrays such as `int[]`, `UserObject[]`, etc..
* Supports phpdoc [type annotations](https://github.com/etsy/phan/wiki/Annotating-Your-Source-Code)
* Supports `@deprecated` annotation for deprecating classes, methods and functions
* Supports `@suppress <ISSUE_TYPE>` annotations for [suppressing issues](https://github.com/etsy/phan/wiki/Annotating-Your-Source-Code#suppress).
* Offers extensive configuration for weakening the analysis to make it useful on large sloppy code bases
* Can be run on many cores.
* Output is emitted in text, checkstyle, json or codeclimate formats.

See [Phan Error Types](https://github.com/etsy/phan/wiki/Issue-Types-Caught-by-Phan) for descriptions
and examples of all issues that can be detected by Phan. Take a look at the
[\Phan\Issue](https://github.com/etsy/phan/blob/master/src/Phan/Issue.php) to see the
definition of each error type.

Take a look at the [Tutorial for Analyzing a Large Sloppy Code Base](https://github.com/etsy/phan/wiki/Tutorial-for-Analyzing-a-Large-Sloppy-Code-Base) to get a sense of what the process of doing ongoing analysis might look like for you.

See the [tests][tests] directory for some examples of the various checks.

# Getting it running

Phan requires PHP 7+ with the [php-ast][phpast] and sqlite extension loaded. The code you analyze can be written for any version of PHP.

## Standalone usage

To get phan running;

1. Clone the repo
2. Run `composer install` to load dependencies
3. Test phan on itself by running the following

```sh
./phan
```

You can see the full list of command line options by running `phan -h`.

## Instalation with homebrew

To get phan running on a Mac with homebrew

Ensure that homebrew is installed (go to http://brew.sh/ and install it)

1. brew update
2. brew install php70 php70-ast phan
3. Check if it is running:

```sh
phan -h
```
You will see the full list of command line options.

This will install `phan` on the global environment of homebrew, allowing integration with any other software running on the same Mac (like `Jenkins`).

## Attaching it to your project integration process

Require a dependency:
```sh
composer require --dev "etsy/phan:dev-master"
```

Define a step or run manually
```sh
find src/ -type f -name '*.php' > phan.in
./vendor/bin/phan -f phan.in -3 vendor -o phan.out
```

The `phan.out` file will contain the analyzer output. This should look like this:

```
test1.php:191 UndefError call to undefined function get_real_size()
test1.php:232 UndefError static call to undeclared class core\session\manager
test1.php:386 UndefError Trying to instantiate undeclared class lang_installer
test2.php:4 TypeError arg#1(arg) is object but escapeshellarg() takes string
test2.php:4 TypeError arg#1(msg) is int but logmsg() takes string defined at sth.php:5
test2.php:4 TypeError arg#2(level) is string but logmsg() takes int defined at sth.php:5
test3.php:11 TypeError arg#1(number) is string but number_format() takes float
test3.php:12 TypeError arg#1(string) is int but htmlspecialchars() takes string
test3.php:13 TypeError arg#1(str) is int but md5() takes string
test3.php:14 TypeError arg#1(separator) is int but explode() takes string
test3.php:14 TypeError arg#2(str) is int but explode() takes string
```

You can see the full list of command line options by running `./vendor/bin/phan -h`.

{'fraction_non_alphanumeric': 0.10102659822678488, 'fraction_numerical': 0.01271581894540364, 'mean_word_length': 4.800405953991881, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 24, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7402682', 'n_tokens_mistral': 2692, 'n_tokens_neox': 2575, 'n_words': 1008}