Skip to content
This repository has been archived by the owner on Jul 18, 2024. It is now read-only.

Commit

Permalink
[TASK] Convert to PSR-2 and shorthand array syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
NamelessCoder committed Oct 17, 2016
1 parent 2eadb45 commit 68318f1
Show file tree
Hide file tree
Showing 7 changed files with 402 additions and 378 deletions.
104 changes: 53 additions & 51 deletions src/ClassFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,61 @@
/**
* Class ClassFinder
*/
class ClassFinder {
class ClassFinder
{

/**
* @param $packagePaths
* @param $phpNamespace
*/
public function getClassNamesInPackages(array $packagePaths) {
$classNames = array();
foreach ($packagePaths as $namespace => $classesPath) {
$classNames = array_replace($classNames, $this->getClassNamesInPackage($classesPath, $namespace));
if (count($classNames) === 0) {
throw new \RuntimeException(sprintf('No ViewHelpers found in path "%s"', $classesPath), 1330029328);
}
}
return $classNames;
}
/**
* @param $packagePaths
* @param $phpNamespace
*/
public function getClassNamesInPackages(array $packagePaths)
{
$classNames = [];
foreach ($packagePaths as $namespace => $classesPath) {
$classNames = array_replace($classNames, $this->getClassNamesInPackage($classesPath, $namespace));
if (count($classNames) === 0) {
throw new \RuntimeException(sprintf('No ViewHelpers found in path "%s"', $classesPath), 1330029328);
}
}
return $classNames;
}

/**
* Get all class names inside this namespace and return them as array.
* To generate a merged namespace simply provide multiple paths (with
* comma as separator) as $packagePaths argument value.
*
* @param string $packagePath
* @param string $phpNamespace
* @return array
*/
public function getClassNamesInPackage($packagePath, $phpNamespace) {
$allViewHelperClassNames = array();
$affectedViewHelperClassNames = array();
/**
* Get all class names inside this namespace and return them as array.
* To generate a merged namespace simply provide multiple paths (with
* comma as separator) as $packagePaths argument value.
*
* @param string $packagePath
* @param string $phpNamespace
* @return array
*/
public function getClassNamesInPackage($packagePath, $phpNamespace)
{
$allViewHelperClassNames = [];
$affectedViewHelperClassNames = [];

$packagePath = rtrim($packagePath, '/') . '/';
$filesInPath = new \RecursiveDirectoryIterator($packagePath, \RecursiveDirectoryIterator::SKIP_DOTS);
$packagePathLength = strlen($packagePath);
foreach ($filesInPath as $filePathAndFilename) {
$relativePath = substr($filePathAndFilename, $packagePathLength, -4);
$classLocation = str_replace('/', '\\', $relativePath);
$className = $phpNamespace . $classLocation;
if (class_exists($className)) {
$parent = $className;
while ($parent = get_parent_class($parent)) {
array_push($allViewHelperClassNames, $className);
}
}
}
foreach ($allViewHelperClassNames as $viewHelperClassName) {
$classReflection = new \ReflectionClass($viewHelperClassName);
if ($classReflection->isAbstract() === FALSE) {
$affectedViewHelperClassNames[] = $viewHelperClassName;
}
}

sort($affectedViewHelperClassNames);
return $affectedViewHelperClassNames;
}
$packagePath = rtrim($packagePath, '/') . '/';
$filesInPath = new \RecursiveDirectoryIterator($packagePath, \RecursiveDirectoryIterator::SKIP_DOTS);
$packagePathLength = strlen($packagePath);
foreach ($filesInPath as $filePathAndFilename) {
$relativePath = substr($filePathAndFilename, $packagePathLength, -4);
$classLocation = str_replace('/', '\\', $relativePath);
$className = $phpNamespace . $classLocation;
if (class_exists($className)) {
$parent = $className;
while ($parent = get_parent_class($parent)) {
array_push($allViewHelperClassNames, $className);
}
}
}
foreach ($allViewHelperClassNames as $viewHelperClassName) {
$classReflection = new \ReflectionClass($viewHelperClassName);
if ($classReflection->isAbstract() === false) {
$affectedViewHelperClassNames[] = $viewHelperClassName;
}
}

sort($affectedViewHelperClassNames);
return $affectedViewHelperClassNames;
}
}
47 changes: 24 additions & 23 deletions src/DocCommentParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,29 @@
/**
* A little parser which creates tag objects from doc comments
*/
class DocCommentParser {

/**
* Parses the given doc comment and saves the result (description and
* tags) in the parser's object. They can be retrieved by the
* getTags() getTagValues() and getDescription() methods.
*
* @param string $docComment A doc comment as returned by the reflection getDocComment() method
* @return void
*/
public function parseDocComment($docComment) {
$parsedDocComment = '';
$lines = explode(chr(10), $docComment);
foreach ($lines as $line) {
if (strlen($line) > 0 && strpos($line, '@') !== FALSE) {
continue;
} else {
$parsedDocComment .= preg_replace('/\\s*\\/?[\\\\*]*(.*)$/', '$1', $line) . chr(10);
}
}
$parsedDocComment = trim($parsedDocComment);
return $parsedDocComment;
}
class DocCommentParser
{

/**
* Parses the given doc comment and saves the result (description and
* tags) in the parser's object. They can be retrieved by the
* getTags() getTagValues() and getDescription() methods.
*
* @param string $docComment A doc comment as returned by the reflection getDocComment() method
* @return void
*/
public function parseDocComment($docComment)
{
$parsedDocComment = '';
$lines = explode(chr(10), $docComment);
foreach ($lines as $line) {
if (strlen($line) > 0 && strpos($line, '@') !== false) {
continue;
} else {
$parsedDocComment .= preg_replace('/\\s*\\/?[\\\\*]*(.*)$/', '$1', $line) . chr(10);
}
}
$parsedDocComment = trim($parsedDocComment);
return $parsedDocComment;
}
}
Loading

0 comments on commit 68318f1

Please sign in to comment.