Source of file Pluralize.php

Size: 0,891 Bytes - Last Modified: 2015-12-22T09:12:14-05:00

../src/Filter/Pluralize.php

12345678910111213141516171819202122232425262728293031323334353637
Covered by 7 test(s):
  • MvcLite\FilterPluralizeTest::testFilter with data set #0
  • MvcLite\FilterPluralizeTest::testFilter with data set #1
  • MvcLite\FilterPluralizeTest::testFilter with data set #2
  • MvcLite\FilterPluralizeTest::testFilter with data set #3
  • MvcLite\FilterPluralizeTest::testFilter with data set #4
  • MvcLite\FilterPluralizeTest::testFilter with data set #5
  • MvcLite\FilterPluralizeTest::testFilter with data set #6
38
Covered by 2 test(s):
  • MvcLite\FilterPluralizeTest::testFilter with data set #5
  • MvcLite\FilterPluralizeTest::testFilter with data set #6
3940
Covered by 5 test(s):
  • MvcLite\FilterPluralizeTest::testFilter with data set #0
  • MvcLite\FilterPluralizeTest::testFilter with data set #1
  • MvcLite\FilterPluralizeTest::testFilter with data set #2
  • MvcLite\FilterPluralizeTest::testFilter with data set #3
  • MvcLite\FilterPluralizeTest::testFilter with data set #4
414243
<?php
/**
 * pluralize filter
 *
 * @category    PHP
 * @package     MvcLite
 * @subpackage  Filter
 * @since       File available since release 1.1.x
 * @author      Cory Collier <corycollier@corycollier.com>
 */

namespace MvcLite\Filter;

use MvcLite\FilterAbstract as FilterAbstract;

/**
 * pluralize filter
 *
 * @category    PHP
 * @package     MvcLite
 * @subpackage  Filter
 * @since       Class available since release 1.1.x
 * @author      Cory Collier <corycollier@corycollier.com>
 */
class Pluralize extends FilterAbstract
{
    /**
     * filters a given string
     *
     * @param string $word
     *
     * @return string
     */
    public function filter($word = '')
    {
        // if the word ends with the lettter 'y'
        if (substr($word, -1) == 'y') {
            return substr($word, 0, strlen($word) - 1) . 'ies';
        }
        return "{$word}s";
    }
}