-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from sensiolabs-de/feature/methodname-collector
method collector
- Loading branch information
Showing
16 changed files
with
230 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
paths: ["./examples/MethodNames1/"] | ||
exclude_files: [] | ||
layers: | ||
- name: SomeA | ||
collectors: | ||
- type: method | ||
name: SomeA | ||
- name: SomeB | ||
collectors: | ||
- type: method | ||
name: SomeB | ||
ruleset: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
class ClassA | ||
{ | ||
public function getSomeA() { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
class ClassB | ||
{ | ||
public function getSomeB() { | ||
|
||
new ClassA(); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace SensioLabs\Deptrac\Collector; | ||
|
||
use SensioLabs\AstRunner\AstMap; | ||
use SensioLabs\AstRunner\AstParser\AstClassReferenceInterface; | ||
use SensioLabs\AstRunner\AstParser\AstParserInterface; | ||
use SensioLabs\AstRunner\AstParser\NikicPhpParser\NikicPhpParser; | ||
use SensioLabs\Deptrac\CollectorFactory; | ||
use PhpParser\Node\Stmt\ClassMethod; | ||
|
||
class MethodCollector | ||
{ | ||
public function getType() | ||
{ | ||
return 'method'; | ||
} | ||
|
||
private function getMethodNameRegexByConfiguration(array $configuration) | ||
{ | ||
if (!isset($configuration['name'])) { | ||
throw new \LogicException('MethodCollector needs the name configuration.'); | ||
} | ||
|
||
return $configuration['name']; | ||
} | ||
|
||
public function satisfy( | ||
array $configuration, | ||
AstClassReferenceInterface $classReference, | ||
AstMap $astMap, | ||
CollectorFactory $collectorFactory, | ||
AstParserInterface $astParser | ||
) { | ||
|
||
if (!$astParser instanceof NikicPhpParser) { | ||
return false; | ||
} | ||
|
||
$ast = $astParser->getAstForClassname($classReference->getClassName()); | ||
|
||
/** @var $classMethods ClassMethod[] */ | ||
$classMethods = $astParser->findNodesOfType($ast, ClassMethod::class); | ||
|
||
foreach ($classMethods as $classMethod) { | ||
if (preg_match( | ||
'/'.$this->getMethodNameRegexByConfiguration($configuration).'/i', | ||
$classMethod->name, | ||
$collectorFactory | ||
)) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.