Issues

ZF-209: Function names and use of TRUE and FALSE

Issue Type: Coding Standards Violation Created: 2006-07-08T12:40:08.000+0000 Last Updated: 2007-07-05T14:43:13.000+0000 Status: Resolved Fix version(s): Reporter: Oliver Saunders (irkengir) Assignee: Chris Shiflett (chris) Tags: - Zend_Filter

Related issues: Attachments:

Description

I'm slightly confused by function names given meaning numbers. It seems sometimes 'digit' is used and other times 'number'. Also they are shortened.

Functions: isDigits() isAlnum() getDigits() getAlnum() Should be isNumeric() isAlphanumeric() getNumbers() getAlphanumerics()

Also TRUE and FALSE seems to have been used routinely over true and false, personally I think the former is misleading as it implies they are constants and not language keywords. From what I can see the Zend Coding Standard doesn't specify which is acceptable.

Comments

Posted by Jayson Minard (jayson) on 2006-07-09T01:18:29.000+0000

general cleanup.

Posted by Oliver Saunders (irkengir) on 2006-07-09T04:44:57.000+0000

Great, seeing as someone has been assigned to this I should probably point out some other issues:

<pre class="highlight">
    public static function isBetween($value, $min, $max, $inc = true)
    {
        if ($value > $min && 
            $value < $max) {
            return true;
        }

        if ($value >= $min &&
            $value <= $max &&
            $inc) {
                return true;
        }
        
        return false;
    }



<pre class="highlight">
    public static function isBetween($value, $min, $max, $inclusive = true)
    {
        if ($value > $min && $value < $max) {
            return true;
        }

        if ($inclusive) {
            if ($value >= $min && $value <= $max) {
                return true;
            }
        }
        
        return false;
    }



<pre class="highlight">
    public static function isGreaterThan($value, $min)
    {
        return ($value > $min);
    }



<pre class="highlight">
    public static function isGreaterThan($value, $min)
    {
        return $value > $min;
    }



<pre class="highlight">
    public static function isInt($value)
    {
        $locale = localeconv();

        $value = str_replace($locale['decimal_point'], '.', $value);
        $value = str_replace($locale['thousands_sep'], '', $value);

        return (strval(intval($value)) == $value);
    }



<pre class="highlight">
    public static function isInt($value)
    {
        $locale = localeconv();

        $value = str_replace($locale['decimal_point'], '.', $value);
        $value = str_replace($locale['thousands_sep'], '', $value);
        //parentesis around cast necessary here? not sure
        return ((string)(int)$value) == $value; 
    }



<pre class="highlight">
    public static function isName($value)
    {
        return (bool) !preg_match('/[^[:alpha:]\ \-\']/', $value);
    }



<pre class="highlight">
What is this really checking because it sure as hell ain't checking 
if its somebody's name, that would be near impossible?



<pre class="highlight">
    public static function isPhone($value, $country = 'US')
    {
        if (!ctype_digit($value)) {
            return FALSE;
        }

        switch ($country)
        {
            case 'US':
                if (strlen($value) != 10) {
                    return FALSE;
                }

                $areaCode = substr($value, 0, 3);

                $areaCodes = array(201, 202, 203, 204, 205, 206, 207, 208,
                                   209, 210, 212, 213, 214, 215, 216, 217,
                                   218, 219, 224, 225, 226, 228, 229, 231,
                                   234, 239, 240, 242, 246, 248, 250, 251,
                                   252, 253, 254, 256, 260, 262, 264, 267,
                                   268, 269, 270, 276, 281, 284, 289, 301,
                                   302, 303, 304, 305, 306, 307, 308, 309,
                                   310, 312, 313, 314, 315, 316, 317, 318,
....



<pre class="highlight">
Are you planning on supporting every country? Here, I'd hope not.
You should probably rename to IsUsaPhone() and implement select countries only, 
i.e the ones with a phone naming system that is simple enough to get right.

That's it!

Posted by Mark Evans (sparky) on 2006-07-12T11:18:52.000+0000

Hi Jayson

If you want I can take care of this whilst I am finishing some other fixes in Zend_Filter.

Please advise

Posted by Bill Karwin (bkarwin) on 2006-09-25T19:44:21.000+0000

Reassigning from Jayson to Bill Karwin, pending further triage.

Posted by Bill Karwin (bkarwin) on 2006-11-08T12:10:16.000+0000

Assigning to Darby.

Posted by Bill Karwin (bkarwin) on 2006-11-13T15:18:21.000+0000

Changing fix version to unknown.

Posted by Bill Karwin (bkarwin) on 2006-11-13T15:23:34.000+0000

Changing fix version to 0.9.0.

Posted by Chris Shiflett (chris) on 2006-11-25T20:45:59.000+0000

I disagree with the suggested changes to the naming convention. Digits is a very specific way to describe what's happening. The reason for Alnum is to remain consistent with the naming of the character type functions, which developers should already be familiar with.

I agree about the isName() comment. I'll remove that method, barring any objections.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts