http://phing.info/

Source Code Coverage

Designed for use with PHPUnit2, Xdebug and Phing.

Methods: 1 LOC: 54 Statements: 8
Legend: executednot executeddead code
Source file Statements Methods Total coverage
TitleCase.php 100.0% 100.0% 100.0%
 
1
<?php
2
/**
3
 * Xyster Framework
4
 *
5
 * This source file is subject to the new BSD license that is bundled
6
 * with this package in the file LICENSE.txt.
7
 * It is also available through the world-wide-web at this URL:
8
 * http://www.opensource.org/licenses/bsd-license.php
9
 *
10
 * @category  Xyster
11
 * @package   Xyster_Filter
12
 * @copyright Copyright LibreWorks, LLC (http://libreworks.net)
13
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
14
 * @version   $Id: TitleCase.php 418 2010-10-18 21:40:08Z jonathanhawk $
15
 */
16
namespace Xyster\Filter;
17
/**
18
 * A filter for title case
19
 *
20
 * @category  Xyster
21
 * @package   Xyster_Filter
22
 * @copyright Copyright LibreWorks, LLC (http://libreworks.net)
23
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
24
 */
25
class TitleCase implements \Zend_Filter_Interface
26
{
27
    /**
28
     * An array of words that shouldn't be capitalized in title case
29
     *
30
     * @var array
31
     */
32
    static private $_smallWords = array( 'of','a','the','and','an','or','nor',
33
        'but','is','if','then','else','when', 'at','from','by','on','off','for',
34
        'in','out','over','to','into','with' );
35
36
    /**
37
     * Converts a string to title case
38
     *
39
     * @param string $value
40
     * @return string The input in title case
41
     */
42
    public function filter($value)
43
    {
44
        // Split the string into separate words
45 1
        $words = explode(' ', strtolower($value));
46 1
        foreach ( $words as $key => $word ) {
47
            // If this is the first, or it's not a small word, capitalize it
48 1
            if ( $key == 0 or !in_array($word, self::$_smallWords) ) {
49 1
                $words[$key] = ucwords($word);
50 1
            }
51 1
        }
52 1
        return implode(' ', $words);
53
    }
54 1
}


Report generated at 2010-10-18T17:19:49-04:00