PHPackages                             arthurkushman/detox - 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. arthurkushman/detox

ActiveDetox[Utility &amp; Helpers](/categories/utility)

arthurkushman/detox
===================

Detox is a library to detect toxic text (comments/posts etc) of variable length with different patterns

1.1.5(7y ago)1316.3k1[2 issues](https://github.com/arthurkushman/detox/issues)MITPHPPHP ^7.1

Since Jun 30Pushed 6y ago2 watchersCompare

[ Source](https://github.com/arthurkushman/detox)[ Packagist](https://packagist.org/packages/arthurkushman/detox)[ RSS](/packages/arthurkushman-detox/feed)WikiDiscussions master Synced yesterday

READMEChangelog (7)Dependencies (3)Versions (9)Used By (0)

Detox is a library to detect toxic comments/posts of variable length with different patterns
--------------------------------------------------------------------------------------------

[](#detox-is-a-library-to-detect-toxic-commentsposts-of-variable-length-with-different-patterns)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/c956cf2fc35e448c80747e541774a0d66966abd5135a5720b0446351af2644f4/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6172746875726b7573686d616e2f6465746f782f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/arthurkushman/detox/?branch=master)[![Build Status](https://camo.githubusercontent.com/348507c3431be483fa0054e8c58813efad9ea5dba27eff278afce83473298b47/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6172746875726b7573686d616e2f6465746f782f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/arthurkushman/detox/build-status/master)[![Total Downloads](https://camo.githubusercontent.com/f4095051402a8668763d1adc73e984c2838ca6d8e17160425b901d3c0b6a6b2b/68747470733a2f2f706f7365722e707567782e6f72672f6172746875726b7573686d616e2f6465746f782f646f776e6c6f616473)](https://packagist.org/packages/arthurkushman/detox)[![Code Intelligence Status](https://camo.githubusercontent.com/09a083494fa5743efdd9e61ddf29fd08a6dcefe9c90243b20e24f557b7de370b/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6172746875726b7573686d616e2f6465746f782f6261646765732f636f64652d696e74656c6c6967656e63652e7376673f623d6d6173746572)](https://scrutinizer-ci.com/code-intelligence)[![codecov](https://camo.githubusercontent.com/bb672f6ef9f5e785dccb100c637f8c6905448a224694884dc965e232c43b8c06/68747470733a2f2f636f6465636f762e696f2f67682f6172746875726b7573686d616e2f6465746f782f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/arthurkushman/detox)[![License: MIT](https://camo.githubusercontent.com/08cef40a9105b6526ca22088bc514fbfdbc9aac1ddbf8d4e6c750e3a88a44dca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d626c75652e737667)](https://opensource.org/licenses/MIT)

It's inspired by providing tool for simple scoring/filtering with just a PHP implementation (without the need to set multiple libs probably on C/Python, or importing db dumps etc).

### Installation

[](#installation)

```
composer require arthurkushman/detox
```

### Using words and word patterns

[](#using-words-and-word-patterns)

To get toxicity score on any text:

```
    $text  = new Text('Some text');
    $words = new Words(new EnglishSet(), $text);
    $words->processWords();
    if ($words->getScore() >= 0.5) {
        echo 'Toxic text detected';
    }
```

to test an input string on asterisk pattern occurrences:

```
    $words->processPatterns();
    if ($words->getScore() >= 0.5) {
        echo 'Toxic text detected';
    }
```

### Using phrases

[](#using-phrases)

Another option is to check for phrases:

```
    $phrases = new Phrases(new EnglishSet(), $text);
    $phrases->processPhrases();
    if ($words->getScore() >= 0.5) {
        echo 'Toxic text detected';
    }
```

There are no constraints to use all options at once, so u can do the following:

```
    // Phrases object extends Words - just use all inherited methods
    $detox = new Phrases(new EnglishSet(), $text);
    $detox->processWords();
    // change string in Text object
    $text->setString('Another text');
    // inject Text object to Phrases
    $detox->setText($text);
    $detox->processPhrases();
    $text->setString('Yet another text');
    $detox->setText($text);
    $detox->processPatterns();
    if ($detox->getScore() >= 0.5) {
        echo 'Toxic text detected';
    }
```

### Replace with custom templates and prefix/postfix pre-sets

[](#replace-with-custom-templates-and-prefixpostfix-pre-sets)

An additional option that u may need in particular situations is to replace words/phrases with pre-set template:

```
    $this->text->setPrefix('[');
    $this->text->setPostfix(']');
    $this->text->setReplaceChars('____');
    $this->text->setString('Just piss off dude');
    $this->text->setReplaceable(true);
    $this->phrases->setText($this->text);

    $this->phrases->processPhrases();
    echo $this->phrases->getText()->getString(); // output: Just [____] dude
```

By default pattern is 5 dashes, so u can call only `$this->text->setReplaceable(true);` before any processor to achieve replacement with default settings.

### Creating custom data-set

[](#creating-custom-data-set)

```
    $customSet = new CustomSet();
    $customSet->setWords([
        '0.9' => ['weird']
    ]);
    $this->text->setString('This weird text should be detected');
    $this->words->setText($this->text);
    $this->words->setDataSet($customSet);
    $this->words->processWords();
    echo $this->words->getScore(); // output: 0.9
```

### Run tests

[](#run-tests)

In root directory (in console) run the following:

```
phpunit
```

Be sure to install phpunit globally, or run it from vendor:

```
vendor/bin/phpunit
```

All contributions are welcome

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity63

Established project with proven stability

 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 ~0 days

Total

7

Last Release

2919d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1f7457ca41f3ffc690f41a6035fdeb4ab8eced3871a3061a638fd8dc80343588?d=identicon)[arthurkushman](/maintainers/arthurkushman)

---

Top Contributors

[![arthurkushman](https://avatars.githubusercontent.com/u/2669610?v=4)](https://github.com/arthurkushman "arthurkushman (25 commits)")

---

Tags

badwordsdetoxfilterphpphp-libphp-libraryphp7toxictoxicity

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

PHPackages © 2026

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