Source of file CamelcaseToDash.php

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

../src/Filter/CamelcaseToDash.php

123456789101112131415161718192021222324252627282930313233
Covered by 3 test(s):
  • MvcLite\FilterCamelcaseToDashTest::testFilter with data set #0
  • MvcLite\FilterCamelcaseToDashTest::testFilter with data set #1
  • MvcLite\FilterCamelcaseToDashTest::testFilter with data set #2
34
Covered by 3 test(s):
  • MvcLite\FilterCamelcaseToDashTest::testFilter with data set #0
  • MvcLite\FilterCamelcaseToDashTest::testFilter with data set #1
  • MvcLite\FilterCamelcaseToDashTest::testFilter with data set #2
35
Covered by 3 test(s):
  • MvcLite\FilterCamelcaseToDashTest::testFilter with data set #0
  • MvcLite\FilterCamelcaseToDashTest::testFilter with data set #1
  • MvcLite\FilterCamelcaseToDashTest::testFilter with data set #2
36
Covered by 2 test(s):
  • MvcLite\FilterCamelcaseToDashTest::testFilter with data set #0
  • MvcLite\FilterCamelcaseToDashTest::testFilter with data set #2
37
Covered by 2 test(s):
  • MvcLite\FilterCamelcaseToDashTest::testFilter with data set #0
  • MvcLite\FilterCamelcaseToDashTest::testFilter with data set #2
38
Covered by 3 test(s):
  • MvcLite\FilterCamelcaseToDashTest::testFilter with data set #0
  • MvcLite\FilterCamelcaseToDashTest::testFilter with data set #1
  • MvcLite\FilterCamelcaseToDashTest::testFilter with data set #2
39
Covered by 3 test(s):
  • MvcLite\FilterCamelcaseToDashTest::testFilter with data set #0
  • MvcLite\FilterCamelcaseToDashTest::testFilter with data set #1
  • MvcLite\FilterCamelcaseToDashTest::testFilter with data set #2
40
Covered by 3 test(s):
  • MvcLite\FilterCamelcaseToDashTest::testFilter with data set #0
  • MvcLite\FilterCamelcaseToDashTest::testFilter with data set #1
  • MvcLite\FilterCamelcaseToDashTest::testFilter with data set #2
414243
<?php
/**
 * camelcase to dash 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;

/**
 * camelcase to dash filter
 *
 * @category    PHP
 * @package     MvcLite
 * @subpackage  Filter
 * @since       Class available since release 1.1.x
 * @author      Cory Collier <corycollier@corycollier.com>
 */
class CamelcaseToDash extends FilterAbstract
{
    /**
     * (non-PHPdoc)
     * @see \MvcLite\FilterAbstract::filter()
     */
    public function filter($word = '')
    {
        $result = '';
        for ($i = 0; $i < strlen($word); $i++) {
            if ($i > 0 && strtolower($word{$i}) !== $word{$i}) {
                $result .= '-';
            }
            $result .= strtolower($word{$i});
        }
        return $result;
    }
}