fucongcong/framework

View on GitHub
core/Group/Common/ClassMap.php

Summary

Maintainability
A
2 hrs
Test Coverage
<?php
 
namespace Group\Common;
 
use Group\Exceptions\NotFoundException;
 
PHP keywords must be lowercase; expected "class" but found "Class"
Class ClassMap
{
protected $dir;
 
public function __construct($dir = ['src/Services'])
{
$this ->dir = $dir;
}
 
Scope keyword "public" must be followed by a single space
public function doSearch()
{
$data = array();
 
Avoid unused local variables such as '$key'.
foreach ($this->dir as $key => $value) {
$data = $this->searchClass($value, $data);
}
 
return $data;
}
 
Function `searchClass` has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Incorrect spacing between argument "$data" and equals sign; expected 1 but found 0
Scope keyword "private" must be followed by a single space
Incorrect spacing between default value and equals sign for argument "$data"; expected 1 but found 0
private function searchClass($fileDir, $data=[])
{
if (is_dir(__ROOT__.$fileDir)) {
$dir = opendir(__ROOT__.$fileDir);
 
Expected 1 space after closing parenthesis; found 13
while (($file = readdir($dir)) !== false)
{
$file = explode(".", $file);
$fileName = $file[0];
 
Blank line found at start of control structure
if ($fileName && isset($file[1]) && $file[1] =="php" && substr($fileName, -4) == "Impl") {
 
$model = explode("/", $fileDir);
$model = $model[2];
 
$class = $fileDir."/".$fileName;
$class = str_replace("/", "\\", $class);
 
if (!class_exists($class)) {
throw new NotFoundException("Class ".$class." not found !");
}
 
$name = substr($fileName, 0, -4);
$data[] = [$class, $model."_".$name];
Blank line found at end of control structure
 
Expected 1 space after closing brace; 0 found
Usage of ELSE IF is discouraged; use ELSEIF instead
}else if ($fileName) {
$data = $this->searchClass($fileDir."/".$fileName, $data);
}
}
closedir($dir);
}
return $data;
}
}