Profanify

Profanify stats

Downloads
9.4K
Stars
49
Open Issues
2
Forks
9

View on GitHub →

A PestPHP Plugin to Help Catch Profanity in Your Applications.

Profanify

A PestPHP Plugin that helps catch profanity in your application.

Introduction

Profanify is a PestPHP Plugin designed to detect and flag instances of profanity within your application. As developers, we've all faced moments of frustration, whether it be debugging a persistent issue or trying to decipher confusing code written by someone else. These moments can sometimes result in the inclusion of profanity in your code.

Whilst this might be fine during local development, it's important to remove any profanity before pushing your changes, so your past frustration doesn't end up being in production and in the local version of whoever else works on your application. It also means your codebase is kept professional and respectful.

This is where Profanify comes in, the package makes it really easy to test your application for common swear words, that you may have forgotten about or had no idea they were in there in the first place. If you have your tests running as part of a CI/CD pipeline, then it should mean the pipeline will fail if there's any profanity in your codebase.

Installation

To install Profanify, you can run the following command in your project's root:

composer require jonpurvis/profanify --dev

Examples

Let's take a look at how Profanify works. There's not much to it but because it's a PestPHP plugin, we can use the functionality that Pest provides out of the box, and combine it with what Profanify offers.

Let's take the following scenario, let's say we have this in our application:

/**
* Adds 2 numbers together
*
* @TODO make this less fucking stupid, why doesn't it just add them up?!? Absolute shit
*/
protected function addNumbers($a, $b): int
{
$str = $a . ',' . $b;
$arr = explode(',', $str);
 
$num1 = (int)$arr[0];
$num2 = (int)$arr[1];
 
$sum = ($num1 + 0) + ($num2 * 1);
 
return $sum;
}

So yes, the method is overly complex for what it does, we can see someone has added a TODO comment, in an effort to refactor it and make it nicer. Unfortunately, they've resorted to using profanity so if we were to write and run the following test:

expect('App')
->toHaveNoProfanity()

The test suite would fail, because there's multiple usages of Profanity in one of the files. You don't have to only test the whole application though, you could limit it to, for example, Controllers:

expect('App\Http\Controllers')
->toHaveNoProfanity()

You could even expect profanity, if you really wanted to:

expect('App\Providers')
->not->toHaveNoProfanity()

There may also be times when you want to ignore certain phrases included in the profanity list. To do this, you can pass an excluding argument to the toHaveNoProfanity method. This argument should be an array of strings that you want to ignore. For example:

expect('App')
->toHaveNoProfanity(excluding: ['69']);

In the test above, the test would pass even if the word 69 was included in one of the tested files.

Or, you may want to test for profanity not included in the list. To do this, pass an including argument to the toHaveNoProfanity method. This argument should be an array of strings you also want to consider as profanity. For example:

expect('App')
->toHaveNoProfanity(including: ['dagnabbit']);

If a test does fail because of Profanity, then the output will show the offending file and line. IDE's such as PHPStorm, will allow you to click the file and be taken straight to the line that contains profanity:

Expecting 'tests/Fixtures/HasProfanityInComment.php' to not use profanity.
at tests/Fixtures/HasProfanityInComment.php:10
 
Tests: 1 failed (1 assertions)
Duration: 0.06s

By default, Profanify will scan all language files, which may cause some problems if a word in your language is fine but is listed as profane in another language. To combat this, you can specify a default language, which means only that file will be checked against when the test runs:

expect('App')
->toHaveNoProfanity(language: 'en');

The example above means that only profanity in Config/profanities/en.php file will be picked up.

Languages

Profanify currently supports the following languages:

  • English
  • Italian
  • Arabic
  • Portuguese

Each language has its own configuration file. If you'd like to add a language, please create a new configuration file.

Contributing

Contributions to the package are more than welcome as there's bound to be extra words that need adding. Feel free to submit a Pull Request with any additions. If you have any issues using the package, then please open an Issue.

Useful Links & Credit

JonPurvis photo

DevOps Engineering Lead.

Addicted to Howdyz. Never heard of it? You haven't lived. 🍗

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Jonpurvis Profanify Related Articles

Blastup logo

Blastup

Blastup provides social media enhancement services including buying Instagram likes, followers, and views, with features like instant delivery and a variety of packages to suit different needs.

Blastup
Typesense Search logo

Typesense Search

Typesense is an open source, blazing-fast search engine, optimized for helping you build delightful search experiences for your sites and apps. Natively integrated with Laravel Scout.

Typesense Search
No Compromises logo

No Compromises

Joel and Aaron, the two seasoned devs from the No Compromises podcast, are now available to hire for your Laravel project. ⬧ Flat rate of $9500/mo. ⬧ No lengthy sales process. ⬧ No contracts. ⬧ 100% money back guarantee.

No Compromises
Acquaint Softtech logo

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech
The Certification of Competence for Laravel logo

The Certification of Competence for Laravel

A community-driven, proctored assessment across 4 levels designed to validate real-world Laravel knowledge, from Junior to mastery-level Artisan. Official Vue.js, Official Nuxt, Angular, React, JS certifications also available.

The Certification of Competence for Laravel
Laravel Cloud logo

Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Cloud