<commit_before>Improve the code quality of your Lithium applications
=====================================================
This project is a 100% Lithium based replacement for the [li3_qa](https://github.com/UnionOfRAD/li3_qa) library, which in turn depends on [phpca](https://github.com/UnionOfRAD/phpca).

Here are some of the key features:

- Detect coding-standard violations.
- Find weak- or untested classes/methods.
- No external dependencies.
- Color-Highlighting.
- Integrates into the Lithium test dashboard.
- Runs on Windows without hassle.
- Cool shortcuts to ease your workflow.

Installation
------------
Clone the repository in your libraries path and then add this line to the `config/bootstrap/libraries.php` file:

```php
/**
 * Add some plugins:
 */
Libraries::add('li3_quality');
```
If you open the test dashboard (under `/test` in your browser), you can should have an additional `Syntax` button to check the files directly in your browser.

Usage
-----
If you run the `li3` command from your console, you'll now find the `syntax` command with its various params:

```bash
$ li3 quality
Lithium console started in the development environment. Use the --env=environment key to alter this.
USAGE
    li3 quality syntax
    li3 quality documented
    li3 quality coverage
DESCRIPTION
    The Quality command helps you to run static code analysis on your codebase.
OPTIONS
    syntax
        Checks the syntax of your class files through static code analysis.
    documented
        Checks for undocumented classes or methods inside the namespace.
    coverage
        Lists code coverage for a given threshold (100 by default).
    --namespace=<>
        The namespace to run the quality checks on.
    --silent=<>
        If `--silent` is used, only failures are shown.
    --threshold=<>
        If `--slient NUM` is used, only classes below this coverage are shown.
```

The "syntax" command
--------------------
If you just run it with `li3 quality syntax`, it will run all rules against your `app` library.

```bash
$ li3 quality syntax
--------------------
Lithium Syntax Check
--------------------
Performing 16 rules on 6 classes.
[FAIL] app\models\Authors
Line    Position        Violation
----    --------        ---------
7       1               Trailing whitespace found
[OK] app\models\Groups
[OK] app\models\Posts
[FAIL] app\controllers\HelloWorldController
Line    Position        Violation
----    --------        ---------
17      -               Function "to_string" is not in camelBack style
21      -               Function "to_json" is not in camelBack style
24      1               Trailing whitespace found
[FAIL] app\controllers\PagesController
Line    Position        Violation
----    --------        ---------
32      1               Trailing whitespace found
34      1               Trailing whitespace found
28      -               Protected Method "view" does not start with "_"
33      -               Protected Method "foobar" does not start with "_"
```

If you have lots of fils to check (for example if you test against the lithium core), you can pass the `--silent` option to only show errors. The `--namespace` param allows you to run the checks against a different library:

```bash
$ li3 quality syntax --silent --namespace=lithium
--------------------
Lithium Syntax Check
--------------------
Performing 16 rules on 375 classes.
[FAIL] lithium\tests\cases\net\http\RouteTest
Line    Position        Violation
----    --------        ---------
383     103             Maximum line length exceeded
[FAIL] lithium\tests\cases\console\command\LibraryTest
Line    Position        Violation
----    --------        ---------
241     101             Maximum line length exceeded
[FAIL] lithium\test\Unit
Line    Position        Violation
----    --------        ---------
1017    102             Maximum line length exceeded
[FAIL] lithium\data\Entity
Line    Position        Violation
----    --------        ---------
379     111             Maximum line length exceeded
381     110             Maximum line length exceeded
```

GIT Pre Commit Hook
--------------------

This pre commit hook is based upon the example found in `.git/hooks/pre-commit.sample`. Copy the sample script to `/path/to/project/.git/hooks/pre-commit` and make it executable. Then, replace the code in the script with the code shown below and adjust the paths to Lithium QA and the li3 command.

```
cd /path/to/project
cp .git/hooks/pre-commit.sample .git/hooks/pre-commit
chmod a+x .git/hooks/pre-commit
```

Now add the following code to .git/hooks/pre-commit and adjust the `LITHIUM_QA` and `LI3` values.

```bash
#!/bin/sh

APP=/path/to/li3_quality_enabled/app/
LI3=/path/to/lithium/libraries/lithium/console/li3

if git-rev-parse --verify HEAD >/dev/null 2>&1
then
    AGAINST=HEAD
else
    # Initial commit: diff against an empty tree object
    AGAINST=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi

EXIT_STATUS=0
PROJECT=`pwd`<commit_msg>Found a typo in readme.<commit_after>Improve the code quality of your Lithium applications
=====================================================
This project is a 100% Lithium based replacement for the [li3_qa](https://github.com/UnionOfRAD/li3_qa) library, which in turn depends on [phpca](https://github.com/UnionOfRAD/phpca).

Here are some of the key features:

- Detect coding-standard violations.
- Find weak- or untested classes/methods.
- No external dependencies.
- Color-Highlighting.
- Integrates into the Lithium test dashboard.
- Runs on Windows without hassle.
- Cool shortcuts to ease your workflow.

Installation
------------
Clone the repository in your libraries path and then add this line to the `config/bootstrap/libraries.php` file:

```php
/**
 * Add some plugins:
 */
Libraries::add('li3_quality');
```
If you open the test dashboard (under `/test` in your browser), you can should have an additional `Syntax` button to check the files directly in your browser.

Usage
-----
If you run the `li3` command from your console, you'll now find the `syntax` command with its various params:

```bash
$ li3 quality
Lithium console started in the development environment. Use the --env=environment key to alter this.
USAGE
    li3 quality syntax
    li3 quality documented
    li3 quality coverage
DESCRIPTION
    The Quality command helps you to run static code analysis on your codebase.
OPTIONS
    syntax
        Checks the syntax of your class files through static code analysis.
    documented
        Checks for undocumented classes or methods inside the namespace.
    coverage
        Lists code coverage for a given threshold (100 by default).
    --namespace=<>
        The namespace to run the quality checks on.
    --silent=<>
        If `--silent` is used, only failures are shown.
    --threshold=<>
        If `--slient NUM` is used, only classes below this coverage are shown.
```

The "syntax" command
--------------------
If you just run it with `li3 quality syntax`, it will run all rules against your `app` library.

```bash
$ li3 quality syntax
--------------------
Lithium Syntax Check
--------------------
Performing 16 rules on 6 classes.
[FAIL] app\models\Authors
Line    Position        Violation
----    --------        ---------
7       1               Trailing whitespace found
[OK] app\models\Groups
[OK] app\models\Posts
[FAIL] app\controllers\HelloWorldController
Line    Position        Violation
----    --------        ---------
17      -               Function "to_string" is not in camelBack style
21      -               Function "to_json" is not in camelBack style
24      1               Trailing whitespace found
[FAIL] app\controllers\PagesController
Line    Position        Violation
----    --------        ---------
32      1               Trailing whitespace found
34      1               Trailing whitespace found
28      -               Protected Method "view" does not start with "_"
33      -               Protected Method "foobar" does not start with "_"
```

If you have lots of fils to check (for example if you test against the lithium core), you can pass the `--silent` option to only show errors. The `--namespace` param allows you to run the checks against a different library:

```bash
$ li3 quality syntax --silent --namespace=lithium
--------------------
Lithium Syntax Check
--------------------
Performing 16 rules on 375 classes.
[FAIL] lithium\tests\cases\net\http\RouteTest
Line    Position        Violation
----    --------        ---------
383     103             Maximum line length exceeded
[FAIL] lithium\tests\cases\console\command\LibraryTest
Line    Position        Violation
----    --------        ---------
241     101             Maximum line length exceeded
[FAIL] lithium\test\Unit
Line    Position        Violation
----    --------        ---------
1017    102             Maximum line length exceeded
[FAIL] lithium\data\Entity
Line    Position        Violation
----    --------        ---------
379     111             Maximum line length exceeded
381     110             Maximum line length exceeded
```

GIT Pre Commit Hook
--------------------

This pre commit hook is based upon the example found in `.git/hooks/pre-commit.sample`. Copy the sample script to `/path/to/project/.git/hooks/pre-commit` and make it executable. Then, replace the code in the script with the code shown below and adjust the paths to Lithium QA and the li3 command.

```
cd /path/to/project
cp .git/hooks/pre-commit.sample .git/hooks/pre-commit
chmod a+x .git/hooks/pre-commit
```

Now add the following code to .git/hooks/pre-commit and adjust the `APP` and `LI3` values.

```bash
#!/bin/sh

APP=/path/to/li3_quality_enabled/app/
LI3=/path/to/lithium/libraries/lithium/console/li3

if git-rev-parse --verify HEAD >/dev/null 2>&1
then
    AGAINST=HEAD
else
    # Initial commit: diff against an empty tree object
    AGAINST=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi

EXIT_STATUS=0
PROJECT=`pwd`
{'fraction_non_alphanumeric': 0.13292474630764595, 'fraction_numerical': 0.02150105495830403, 'mean_word_length': 2.2508164598301765, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 4, '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': '2290574', 'n_tokens_mistral': 2823, 'n_tokens_neox': 2609, 'n_words': 1089}