PHPackages                             lynter/lynter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. lynter/lynter

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

lynter/lynter
=============

A PHP tool for analyzing code and enforcing restrictions on specific functions, variables, and coding patterns.

0.1.8(6mo ago)17MITPHPPHP &gt;=8.2CI passing

Since Aug 17Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/yigitcukuren/lynter)[ Packagist](https://packagist.org/packages/lynter/lynter)[ RSS](/packages/lynter-lynter/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (8)Dependencies (7)Versions (12)Used By (0)

Lynter
======

[](#lynter)

Lynter is a PHP code analysis tool focused on restricting specific usages within your codebase. It allows you to enforce custom rules, such as restricting certain functions, variables, or classes, ensuring that your code adheres to specific standards. Lynter can be used in continuous integration pipelines or as a pre-commit hook in your Git workflow.

Table of Contents
-----------------

[](#table-of-contents)

1. [Installation](#installation)
2. [Usage](#usage)
3. [Configuration](#configuration)
4. [Built-in Rules](#built-in-rules)
5. [Excluding Files and Directories](#excluding-files-and-directories)
6. [Parallel Execution](#parallel-execution)
7. [Output Formats](#output-formats)
8. [Examples](#examples)
9. [Testing](#testing)
10. [Contributing](#contributing)
11. [License](#license)

Installation
------------

[](#installation)

To install Lynter, use Composer:

```
composer require --dev lynter/lynter
```

Make sure to include Lynter in your `composer.json` file's `require-dev` section for development dependencies.

Usage
-----

[](#usage)

Lynter can be run from the command line to analyze PHP files or directories. Here's the basic syntax:

```
./vendor/bin/lynter analyze [options]
```

### Options

[](#options)

- `--config=`: Specify the path to the YAML configuration file (default: `lynter.yml`).
- `--output=`: Specify the output format (`raw`, `json`). Default is `raw`.
- `--parallel=`: Specify the number of parallel processes to use for analysis.

### Example Usage

[](#example-usage)

```
./vendor/bin/lynter analyze src --config=lynter.yml --output=raw --parallel=4
```

This command will analyze the `src` directory using the configuration file `lynter.yml`, output results in raw format, and utilize 4 parallel processes.

Configuration
-------------

[](#configuration)

Lynter is configured using a YAML file. The default configuration file is `lynter.yml`. You can specify custom rules, messages, and exclusions in this file.

### Example Configuration

[](#example-configuration)

```
rules:
  - name: restrict-functions
    rule: restrictFunction
    matcher: exact
    values:
      - eval
      - exec
      - shell_exec
    message: "This function '{value}' is not allowed."

  - name: restrict-functions-regex
    rule: restrictFunction
    matcher: pattern
    values:
      - '/^debug_/' # Restricts any function starting with "debug_"
    message: "This function matching '{value}' is not allowed."

  - name: restrict-variables
    rule: restrictVariable
    matcher: exact
    values:
      - $_GET
      - $_POST
    message: "This variable '{value}' is restricted."

  - name: restrict-variables-regex
    rule: restrictVariable
    matcher: pattern
    values:
      - '/^\$temp/' # Restricts any variable starting with "$temp"
    message: "This variable matching '{value}' is restricted."

  - name: restrict-classes
    rule: restrictClass
    matcher: exact
    values:
      - MyRestrictedClass
    message: "Instantiation of '{value}' is not allowed."

  - name: restrict-classes-regex
    rule: restrictClass
    matcher: pattern
    values:
      - '/^Legacy/' # Restricts any class starting with "Legacy"
    message: "Instantiation of class matching '{value}' is not allowed."

exclude:
  - vendors
  - tests
```

### Configuration Details

[](#configuration-details)

- **rules**: Define the rules for restricting functions, variables, and classes. Each rule type (`restrictFunction`, `restrictVariable`, `restrictClass`) accepts an array of values to restrict, a matcher (`exact` or `pattern`), and a custom message template.
- **exclude**: Specify directories or files to exclude from analysis.

Built-in Rules
--------------

[](#built-in-rules)

Lynter comes with the following built-in rules:

### 1. `restrictFunction`

[](#1-restrictfunction)

Restrict the usage of specific functions.

#### Example

[](#example)

```
rules:
  - name: restrict-functions
    rule: restrictFunction
    matcher: exact
    values:
      - eval
      - exec
    message: "This function '{value}' is not allowed."
```

### 2. `restrictVariable`

[](#2-restrictvariable)

Restrict the usage of specific global variables.

#### Example

[](#example-1)

```
rules:
  - name: restrict-variables
    rule: restrictVariable
    matcher: exact
    values:
      - $_GET
      - $_POST
    message: "This variable '{value}' is restricted."
```

### 3. `restrictClass`

[](#3-restrictclass)

Restrict the instantiation of specific classes.

#### Example

[](#example-2)

```
rules:
  - name: restrict-classes
    rule: restrictClass
    matcher: exact
    values:
      - MyRestrictedClass
    message: "Instantiation of '{value}' is not allowed."
```

Excluding Files and Directories
-------------------------------

[](#excluding-files-and-directories)

You can exclude specific files or directories from being analyzed by using the `exclude` option in your configuration file.

### Example

[](#example-3)

```
exclude:
  - vendor/
  - tests/
  - src/legacy/
```

Parallel Execution
------------------

[](#parallel-execution)

Lynter supports parallel execution to speed up the analysis of large codebases. You can specify the number of parallel processes using the `--parallel` option.

### Example

[](#example-4)

```
./vendor/bin/lynter analyze src --parallel=4
```

This will run Lynter with 4 parallel processes.

Output Formats
--------------

[](#output-formats)

Lynter supports two output formats: `raw` and `json`.

### Raw Output

[](#raw-output)

The default output format is `raw`, which provides a human-readable summary of the issues.

### JSON Output

[](#json-output)

For machine-readable output, use the `json` format.

```
./vendor/bin/lynter analyze src --output=json
```

Examples
--------

[](#examples)

### Example 1: Analyzing a Directory

[](#example-1-analyzing-a-directory)

```
./vendor/bin/lynter analyze src --config=lynter.yml
```

### Example 2: Analyzing Multiple Files

[](#example-2-analyzing-multiple-files)

```
./vendor/bin/lynter analyze src/Example.php src/AnotherExample.php --config=lynter.yml
```

### Example 3: Running in Parallel

[](#example-3-running-in-parallel)

```
./vendor/bin/lynter analyze src --config=lynter.yml --parallel=4
```

### Example 4: JSON Output

[](#example-4-json-output)

```
./vendor/bin/lynter analyze src --output=json
```

Testing
-------

[](#testing)

Lynter includes a set of PHPUnit tests to ensure the integrity of the tool.

### Running Tests

[](#running-tests)

To run the tests, use the following command:

```
./vendor/bin/phpunit
```

This will execute the test suite and provide feedback on any issues.

Contributing
------------

[](#contributing)

Contributions are welcome! Please fork this repository, make your changes, and submit a pull request.

### Steps to Contribute

[](#steps-to-contribute)

1. Fork the repository.
2. Create a new branch for your feature or bugfix.
3. Write tests for your changes.
4. Ensure all tests pass.
5. Submit a pull request.

### Code Style

[](#code-style)

This project follows PSR-12 coding standards. Please ensure your code adheres to these guidelines.

License
-------

[](#license)

Lynter is open-source software licensed under the MIT license. See the `LICENSE` file for more information.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance67

Regular maintenance activity

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~56 days

Recently: every ~111 days

Total

9

Last Release

191d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ba6fe596e30fb87408c8a989194e62afcd5a2ea218839f1b67a5077ec6fadbc0?d=identicon)[yigitcukuren](/maintainers/yigitcukuren)

---

Top Contributors

[![yigitcukuren](https://avatars.githubusercontent.com/u/42731194?v=4)](https://github.com/yigitcukuren "yigitcukuren (31 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/lynter-lynter/health.svg)

```
[![Health](https://phpackages.com/badges/lynter-lynter/health.svg)](https://phpackages.com/packages/lynter-lynter)
```

###  Alternatives

[behat/behat

Scenario-oriented BDD framework for PHP

4.0k96.8M2.0k](/packages/behat-behat)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

19462.3M1.3k](/packages/drupal-core)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[jolicode/castor

A lightweight and modern task runner. Automate everything. In PHP.

53541.0k3](/packages/jolicode-castor)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
