Skip to content

Instantly share code, notes, and snippets.

@ircmaxell
Last active December 27, 2015 18:39
Show Gist options
  • Save ircmaxell/7371299 to your computer and use it in GitHub Desktop.
Save ircmaxell/7371299 to your computer and use it in GitHub Desktop.
Sturgeon Compat
<?php
if (!function_exists('philsturgeon_said_so')) {
function philsturgeon_said_so($what) {
return 0 !== preg_match('(FIG|PSR|Pyro|Cider|doing it wrong)i', $what);
}
}
@stevenwadejr
Copy link

This is awesome!

In my dream it was something like this:

if (philsturgeon_said_so("You're doing it wrong")) {
    die;
}

@ircmaxell
Copy link
Author

Well, That's supported now :-D

@WMeldon
Copy link

WMeldon commented Nov 8, 2013

Ran this through CodeSniffer to bring it up to PSR-2 standards.

<?php

if (!function_exists('philsturgeon_said_so')) {
    function philsturgeon_said_so($what)
    {
        return 0 !==
        preg_match('(FIG
                                    |PSR|
                                        Pyro|
                                            Cider|
                                    doi
                                    ng it wr
                                    ong)i',
        $what);
    }
}

@philsturgeon
Copy link

All good so far:

php > var_dump(philsturgeon_said_so('something about cheese'));
bool(false)
php > var_dump(philsturgeon_said_so('Use PyroCMS or shut the fuck up'));
bool(true)
php > 
php > var_dump(philsturgeon_said_so('MongoDB is webscale'));
bool(false)
php > 
php > var_dump(philsturgeon_said_so('The FIG is a shitshow but at least we\'re making progress on PSR-4 now.'));
bool(true)

@zackkitzmiller
Copy link

<?php

if (!function_exists('philsturgeon_said_so')) {
    function philsturgeon_said_so($what) {
        return preg_match('(FIG|PSR|Pyro|Cider|doing it wrong)i', $what) !== 0;
    }
}

I hate those Yoda conditionals.

@jerel
Copy link

jerel commented Nov 8, 2013

I felt like we should be able to check for sturgeon_compat in Python also (using PHP of course)

import os, subprocess

def philsturgeon_said_so(what):
    right_or_wrong = "echo preg_match('(FIG|PSR|Pyro|Cider|doing it wrong)i', '{0}');".format(what)
    if subprocess.check_output(['php', '-r', right_or_wrong]) is not '1':
        while(1):
            os.fork()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment