PHPackages                             ancor/yii2-code-syntax - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. ancor/yii2-code-syntax

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

ancor/yii2-code-syntax
======================

Check syntax for some programming languages

032PHP

Since Feb 22Pushed 10y ago1 watchersCompare

[ Source](https://github.com/ancor-dev/yii2-code-syntax)[ Packagist](https://packagist.org/packages/ancor/yii2-code-syntax)[ RSS](/packages/ancor-yii2-code-syntax/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Code Syntax validators for Yii 2
================================

[](#code-syntax-validators-for-yii-2)

Check code in some programming languages for syntax errors.

**Currently supported languages:**

- [php](#php-syntax-validator)
- [sql](#sql-syntax-validator)
- [json](#json-syntax-validator)

Feel free to let me know what else you want added via:

- [Issues](https://github.com/ancor-dev/yii2-code-syntax/issues)

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

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
$ php composer.phar require ancor/yii2-code-syntax
```

or add

```
"ancor/yii2-code-syntax": "dev-master"

```

to the `require` section of your `composer.json` file.

Validators
----------

[](#validators)

### Sql Syntax Validator

[](#sql-syntax-validator)

**Validation occurs as follows:**

1. Get the data from the field model
2. Wrapping wrapper
3. Add at the start `EXPLAIN `
4. Execute sql query
5. If the returned error, add this errors to validation message

##### Basic usage

[](#basic-usage)

```
use ancor\codeSyntax\SqlSyntaxValidator;
public function rules()
{
    return [
        [['sqlCodeField'], SqlSyntaxValidator::className()],
    ];
}
```

##### Advanced usage with options

[](#advanced-usage-with-options)

```
use ancor\codeSyntax\SqlSyntaxValidator;
public function rules()
{
    return [
        [
            ['sqlCodeField'],
            SqlSyntaxValidator::className(),
            // 'wrapper' => '...{{part}}...',
            // 'makeSql' => function($validator, $partSql) { ... }
            'message' => 'Field {attribute} is invalid',
        ],
    ];
}
```

### Php Syntax Validator

[](#php-syntax-validator)

**Warning:** this validator use php cli. And if php has been not added to $PATH, validator will not work.

##### Basic usage

[](#basic-usage-1)

```
use ancor\codeSyntax\PhpSyntaxValidator;

public function rules()
{
    return [
       [['phpCodeField'], PhpSyntaxValidator::className()],
    ];
}
```

##### Advanced usage with options

[](#advanced-usage-with-options-1)

```
use ancor\codeSyntax\PhpSyntaxValidator;

public function rules()
{
    return [
       [
           ['phpCodeField'],
           PhpSyntaxValidator::className(),
           'isWrapPhp' => true,
           'message' => 'Field {attribute} is invalid',
       ],
    ];
}
```

### Json Syntax Validator

[](#json-syntax-validator)

**Warning:** this validator use `json_decode()` php function. And depends on php-json extension.

##### Basic usage

[](#basic-usage-2)

```
use ancor\codeSyntax\JsonSyntaxValidator;

public function rules()
{
    return [
       [['jsonCodeField'], JsonSyntaxValidator::className()],
    ];
}
```

##### Advanced usage with options

[](#advanced-usage-with-options-2)

```
use ancor\codeSyntax\JsonSyntaxValidator;

public function rules()
{
    return [
       [
           ['jsonCodeField'],
           JsonSyntaxValidator::className(),
           'message' => 'Field {attribute} has invalid json. Code: {errCode}, Msg: {errMsg}',
       ],
    ];
}
```

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/11b715dbbb813e6d3cd3c1bba6a6f7b8af7ffb0aa9d1b1a46a11910a2c41cb45?d=identicon)[ancor.dev](/maintainers/ancor.dev)

---

Top Contributors

[![Ancor-dev](https://avatars.githubusercontent.com/u/180199345?v=4)](https://github.com/Ancor-dev "Ancor-dev (2 commits)")

### Embed Badge

![Health badge](/badges/ancor-yii2-code-syntax/health.svg)

```
[![Health](https://phpackages.com/badges/ancor-yii2-code-syntax/health.svg)](https://phpackages.com/packages/ancor-yii2-code-syntax)
```

PHPackages © 2026

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