2017 © Pedro Peláez
 

library spam-detector

PHP Spam Detector

image

denismitr/spam-detector

PHP Spam Detector

  • Sunday, July 8, 2018
  • by denismitr
  • Repository
  • 1 Watchers
  • 1 Stars
  • 9 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 13 % Grown

The README.md

Spam Detector

Author

Denis Mitrofanov, (*1)

Installation

composer require denismitr/spam-detector

Usage

You can pass as many inspections as you want to the Denismitr\Spam\Spam class constructor. Every inspection must implement Denismitr\Spam\Contracts\Inspection interface. Right now, out of the box, you get 6 of them:, (*2)

  • Denismitr\Spam\Inspections\AsciiOnly
  • Denismitr\Spam\Inspections\YahooCustomerSupport
  • Denismitr\Spam\Inspections\RussianForbiddenWords
  • Denismitr\Spam\Inspections\RussianBadWords
  • Denismitr\Spam\Inspections\KeyHeldDown
  • Denismitr\Spam\Inspections\EnglishForbiddenWords

An example of usage:, (*3)

$text = "Some text to check";

$spam = new Spam([
    YahooCustomerSupport::class,
    RussianForbiddenWords::class,
    RussianBadWords::class,
    KeyHeldDown::class
]);

try {
    $spam->detect($text);
} catch(SpamDetected $e) {
    // Do stuff
}

or to see if any of the given fields contain spam use ```detectAny`` method, (*4)

try {
    $spam->detectAny([
        'title' => 'Some title...',
        'body' => 'Some body...'
    ]);
} catch(SpamDetected $e) {
    // Do stuff
}

This method will throw if any of the given fields contain spam., (*5)

And, of course, if you need, another method detectAll will throw if all fields contain spam:, (*6)

try {
    $spam->detectAll([
        'title' => 'Some title...',
        'body' => 'Some body...'
    ]);
} catch(SpamDetected $e) {
    // Do stuff
}

Another usecase is when you want to check against only one inspection. For this case there is a static method inspect that accepts a string for a haystack and the Inspection instance like so:, (*7)

$text = 'Some text to check';

try {
    Spam::inspect($text, new KeyHeldDown);
} catch(SpamDetected $e) {
    // Do stuff
}

You can easily add your own inspections. They must implement Inspection interface. That looks like so:, (*8)

interface Inspection
{
    /**
     * @param string $text
     * @return void
     */
    public function detect(string $text);
}

The Versions

08/07 2018

dev-master

9999999-dev

PHP Spam Detector

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

08/07 2018

v0.4

0.4.0.0

PHP Spam Detector

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

29/08 2017

v0.3

0.3.0.0

PHP Spam Detector

  Sources   Download

MIT

The Requires

  • php ^7.0,<7.2

 

The Development Requires

28/08 2017

v0.2

0.2.0.0

PHP Spam Detector

  Sources   Download

MIT

The Requires

  • php ^7.0,<7.2

 

The Development Requires

22/08 2017

v0.1

0.1.0.0

PHP Spam Detector

  Sources   Download

MIT

The Requires

  • php ^7.0,<7.2

 

The Development Requires