Permalink
Browse files

Moved class name to file name logic into the PSR-0 Scanner to be able…

… to use it with a phpCS rule set
  • Loading branch information...
lapistano committed Oct 29, 2011
1 parent 1f1d1ae commit 89ef3a5968f1d4cbacf20e9d881b140244878641
Showing with 27 additions and 30 deletions.
  1. +3 −29 accepted/tests/Psr0_CompatibilityTest.php
  2. +24 −1 accepted/tests/Psr0_Scanner.php
@@ -12,32 +12,6 @@
class psr0_CompatibilityTest extends \PHPUnit_Framework_TestCase
{
-
- /**
- * Translates a classname to a filename according to the rules of PSR-0.
- *
- * This method is a clone of the autoload() function accepted to be the reference
- * implementation to autoload classes following the PSR-0 FIG standard.
- *
- * @param string $className
- * @return string
- * @link https://github.com/php-fig/fig-standards
- */
- protected function translateClassToFilename($className)
- {
- $className = ltrim($className, '\\');
- $fileName = '';
- $namespace = '';
- if ($lastNsPos = strripos($className, '\\')) {
- $namespace = substr($className, 0, $lastNsPos);
- $className = substr($className, $lastNsPos + 1);
- $fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
- }
- $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
- return $fileName;
- }
-
-
/**
* @dataProvider psr0CompatibilityDataprovider
*/
@@ -48,7 +22,7 @@ public function testPsr0Compatability($filename, $classname)
$this->assertEquals(
$filename,
- $this->translateClassToFilename($classname),
+ Psr0_Scanner::translateClassToFilename($classname),
'The classname does not translate correctly into a PSR-0 compatible filename.'
);
}
@@ -67,8 +41,8 @@ public static function psr0CompatibilityDataprovider()
{
// preparations
$psr0 = new Psr0_Scanner(
- Psr0_ScannerInclude,
- Psr0_ScannerExclude
+ defined(Psr0_ScannerInclude) ? Psr0_ScannerInclude : '',
+ defined(Psr0_ScannerExclude) ? Psr0_ScannerExclude : ''
);
return $psr0->scan(Psr0_ScannerStartDir);
@@ -16,7 +16,7 @@ class Psr0_Scanner
protected $registry = array();
protected $errors = array();
- public function __construct($includes, $excludes)
+ public function __construct($includes = '' , $excludes = '')
{
$this->includes = $includes;
$this->excludes = $excludes;
@@ -62,6 +62,29 @@ public function getErrors()
return $this->errors;
}
+ /**
+ * Translates a classname to a filename according to the rules of PSR-0.
+ *
+ * This method is a clone of the autoload() function accepted to be the reference
+ * implementation to autoload classes following the PSR-0 FIG standard.
+ *
+ * @param string $className
+ * @return string
+ * @link https://github.com/php-fig/fig-standards
+ */
+ public static function translateClassToFilename($className)
+ {
+ $className = ltrim($className, '\\');
+ $fileName = '';
+ $namespace = '';
+ if ($lastNsPos = strripos($className, '\\')) {
+ $namespace = substr($className, 0, $lastNsPos);
+ $className = substr($className, $lastNsPos + 1);
+ $fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
+ }
+ $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
+ return $fileName;
+
/**
* Greps namespaces and classnames from the given file

0 comments on commit 89ef3a5

Please sign in to comment.