{"id":15647299,"url":"https://github.com/wata727/pahout","last_synced_at":"2025-04-15T11:54:09.099Z","repository":{"id":62546697,"uuid":"99998970","full_name":"wata727/pahout","owner":"wata727","description":"A pair programming partner for writing better PHP. Pahout means PHP mahout :elephant: ","archived":false,"fork":false,"pushed_at":"2020-06-26T11:13:16.000Z","size":219,"stargazers_count":46,"open_issues_count":1,"forks_count":1,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-13T03:49:04.531Z","etag":null,"topics":["clean-code","lint","linter","php","static-analysis"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wata727.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-08-11T06:29:15.000Z","updated_at":"2024-11-07T18:31:03.000Z","dependencies_parsed_at":"2022-11-02T22:16:00.583Z","dependency_job_id":null,"html_url":"https://github.com/wata727/pahout","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wata727%2Fpahout","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wata727%2Fpahout/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wata727%2Fpahout/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wata727%2Fpahout/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wata727","download_url":"https://codeload.github.com/wata727/pahout/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249067767,"owners_count":21207395,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clean-code","lint","linter","php","static-analysis"],"created_at":"2024-10-03T12:18:18.280Z","updated_at":"2025-04-15T11:54:09.080Z","avatar_url":"https://github.com/wata727.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pahout\n[![Build Status](https://travis-ci.org/wata727/pahout.svg?branch=master)](https://travis-ci.org/wata727/pahout)\n[![Latest Stable Version](https://poser.pugx.org/wata727/pahout/v/stable)](https://packagist.org/packages/wata727/pahout)\n[![Docker Hub](https://img.shields.io/badge/docker-ready-blue.svg)](https://hub.docker.com/r/wata727/pahout/)\n[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE)\n\nA pair programming partner for writing better PHP. Pahout means PHP mahout :elephant:\n\n## Motivation\n\nPHP has been added various features in the long history. However, due to the length of its history, many old syntax is scattered over the Internet. If a PHPer learned from them, the PHPer cannot know the excellent syntax and functions existing in the latest PHP version. This is a very sad thing.\n\nSo, I thought about making a linter like a pair programming partner who tells you a good way. It will help you write better PHP with you.\n\nHowever, please do not try to fix all existing codes based on the hints of Pahout first. Pahout is a pair programming partner. When pairing programming, you don't check all existing codes, do you? My recommendation is to only check on newly created or modified files. For example, it is a good idea to set pre-commit hook as follows:\n\n```sh\n#!/bin/sh\n\ngit diff --name-only | grep .php | xargs vendor/bin/pahout\nif [\"$?\" -ne 0]; then\n    exit 1\nfi\n```\n\n## Installation\n\nPahout requires the following environment:\n\n- PHP 7.1 or newer\n- [php-ast](https://github.com/nikic/php-ast) v0.1.7 or newer\n\n### Using Composer\n\nYou can install with composer.\n\n```\n$ composer require --dev wata727/pahout\n$ vendor/bin/pahout -V\n```\n\n### Using Docker\n\nBy using the [Docker image](https://hub.docker.com/r/wata727/pahout/), you can easily try Pahout without affecting the local environment.\n\n```\n$ docker run --rm -t -v $(pwd):/workdir wata727/pahout\n```\n\n## Quick Start\n\nYou are using PHP 7.1.8 in your project. What do you think of the following code?\n\n```php\n\u003c?php\n\n// Do something...\n\n$response = get_awesome_response();\n$error = isset($response['error']) ? $response['error'] : null;\n\n// Do something...\n\n```\n\nPerhaps it is a familiar code. However, if you know the [null coalescing operator](https://secure.php.net/manual/en/language.operators.comparison.php#language.operators.comparison.coalesce), you will write something like this:\n\n```php\n\u003c?php\n\n// Do something...\n\n$response = get_awesome_response();\n$error = $response['error'] ?? null; # Great!\n\n// Do something...\n\n```\n\nPahout will support such rewriting. Try to run on the above example.\n\n```\n$ pahout --php-version 7.1.8 test.php\ntest.php:8\n    NullCoalescingOperator: Use the null coalecing operator instead of the ternary operator. [https://github.com/wata727/pahout/blob/master/docs/NullCoalescingOperator.md]\n\n1 files checked, 1 hints detected.\n```\n\nPahout tells you where the null coalescing operator can be used! For the list of hints provided by Pahout, please see this [documentation](docs).\n\nIf you want to analyze multiple files, you can specify more than one.\n\n```\n$ pahout --php-version 7.1.8 test.php test2.php ...\n```\n\nIf you specify a directory name, all `.php` files under that directory will be covered.\n\n```\n$ pahout --php-version 7.1.8 src\n```\n\n## Configuration\n\nYou can change the configuration from the command line.\n\n```\n$ pahout --help\nDescription:\n  A pair programming partner for writing better PHP\n\nUsage:\n  check [options] [--] [\u003cfiles\u003e...]\n\nArguments:\n  files                              List of file names or directory names to be analyzed\n\nOptions:\n      --php-version[=PHP-VERSION]    Target PHP version [default: runtime version]\n      --ignore-tools[=IGNORE-TOOLS]  Ignore tool types [default: Nothing to ignore] (multiple values allowed)\n      --ignore-paths[=IGNORE-PATHS]  Ignore files and directories [default: Nothing to ignore] (multiple values allowed)\n      --extensions[=EXTENSIONS]      File extensions to be analyzed [default: php] (multiple values allowed)\n      --vendor[=VENDOR]              Check vendor directory [default: false]\n  -f, --format[=FORMAT]              Output format [default: \"pretty\", possibles: \"pretty\", \"json\"]\n  -c, --config[=CONFIG]              Config file path [default: \".pahout.yaml\"]\n      --only-tools[=ONLY-TOOLS]      Check only the given tool types (multiple values allowed)\n  -h, --help                         Display this help message\n  -q, --quiet                        Do not output any message\n  -V, --version                      Display this application version\n      --ansi                         Force ANSI output\n      --no-ansi                      Disable ANSI output\n  -n, --no-interaction               Do not ask any interactive question\n  -v|vv|vvv, --verbose               Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug\n```\n\nYou can also change the configuration by preparing a configuration file called `.pahout.yaml`.\n\n```yaml\nphp_version: 7.0.0\nignore_tools:\n    - ShortArraySyntax\nignore_paths:\n    - tests\n    - bin\nextensions:\n    - php\n    - module\n    - inc\nvendor: true\n```\n\n### PHP Version\n\nSpecify the PHP version of your project. The default is the runtime version. Pahout uses this version to select tools.\n\n### Ignore Tools\n\nIn Pahout, what generates hints is called \"Tool\". You can specify the tool name you want to ignore. Please look at the documentation for the list of tool names.\n\n### Only Tools\n\nContrary to `ignore_tools`, specify tools to check.\n\n### Ignore Paths\n\nYou can specify the file or directory you want to ignore. If a directory name is specified, all files under that directory are ignored.\n\n### Extensions\n\nFile extensions to be analyzed. Default is `php` only.\n\n### Vendor\n\nYou can set whether to ignore the vendor directory.\n\nNote: The vendor directory is ignored by default. Generally, you don't need to check the vendor directory.\n\n### Format\n\nSpecify the output format. Currently only `pretty` and `json` are supported.\n\n### Config\n\nSpecify a configuration file name. This is useful when you want to use the file name other than `.pahout.yaml` in the configuration file.\n\n## Annotation\n\nUsing annotations, you can ignore hints for specific lines. Specify the tool name you want to ignore with `@rebel`.\n\n```php\n\u003c?php\n\n/** @rebel NullCoalescingOperator */\n$error = isset($response['error']) ? $response['error'] : null;\n```\n\nThe following comments will work in the same way.\n\n```php\n\u003c?php\n\n/**\n* @rebel NullCoalescingOperator\n*/\n$error = isset($response['error']) ? $response['error'] : null;\n\n$error = isset($response['error']) ? $response['error'] : null; # @rebel NullCoalescingOperator\n```\n\n## Author\n\n[Kazuma Watanabe](https://github.com/wata727)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwata727%2Fpahout","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwata727%2Fpahout","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwata727%2Fpahout/lists"}