Skip to content

Commit 916d4de

Browse files
authored
Merge pull request #15 from magento-commerce/9.0.0-RC
[Pangolin] SVC 9.0.0
2 parents 4b4974d + 1f286fb commit 916d4de

33 files changed

+685
-42
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "magento/magento-semver",
33
"description": "Magento Semantic Version Checker",
4-
"version": "8.0.0",
4+
"version": "9.0.0",
55
"license": [
66
"OSL-3.0",
77
"AFL-3.0"

composer.lock

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Analyzer/ClassAnalyzer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace Magento\SemanticVersionChecker\Analyzer;
1111

12+
use Magento\SemanticVersionChecker\ClassHierarchy\DependencyGraph;
1213
use PhpParser\Node\Stmt\Class_;
1314
use PHPSemVerChecker\Operation\ClassAdded;
1415
use PHPSemVerChecker\Operation\ClassRemoved;

src/Analyzer/ClassMethodAnalyzer.php

Lines changed: 57 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
use Magento\SemanticVersionChecker\Operation\Visibility\MethodDecreased as VisibilityMethodDecreased;
2525
use Magento\SemanticVersionChecker\Operation\Visibility\MethodIncreased as VisibilityMethodIncreased;
2626
use PhpParser\Node\NullableType;
27-
use PhpParser\Node\Stmt;
27+
use PhpParser\Node\Name;
28+
use PhpParser\Node\Stmt\Class_;
2829
use PhpParser\Node\Stmt\ClassLike;
2930
use PhpParser\Node\Stmt\ClassMethod;
3031
use PHPSemVerChecker\Comparator\Implementation;
@@ -38,12 +39,6 @@
3839
use PHPSemVerChecker\Operation\ClassMethodParameterTypingRemoved;
3940
use PHPSemVerChecker\Operation\ClassMethodRemoved;
4041
use PHPSemVerChecker\Report\Report;
41-
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
42-
use PHPStan\PhpDocParser\Lexer\Lexer;
43-
use PHPStan\PhpDocParser\Parser\ConstExprParser;
44-
use PHPStan\PhpDocParser\Parser\PhpDocParser;
45-
use PHPStan\PhpDocParser\Parser\TokenIterator;
46-
use PHPStan\PhpDocParser\Parser\TypeParser;
4742

4843
/**
4944
* Class method analyzer.
@@ -422,20 +417,62 @@ private function isReturnsEqualByNullability(ClassMethod $before, ClassMethod $a
422417
*/
423418
private function getDocReturnDeclaration(ClassMethod $method)
424419
{
425-
if ($method->getDocComment() !== null) {
426-
$lexer = new Lexer();
427-
$typeParser = new TypeParser();
428-
$constExprParser = new ConstExprParser();
429-
$phpDocParser = new PhpDocParser($typeParser, $constExprParser);
430-
431-
$tokens = $lexer->tokenize((string)$method->getDocComment());
432-
$tokenIterator = new TokenIterator($tokens);
433-
$phpDocNode = $phpDocParser->parse($tokenIterator);
434-
$tags = $phpDocNode->getTagsByName('@return');
435-
/** @var PhpDocTagNode $tag */
436-
$tag = array_shift($tags);
420+
if (
421+
($parsedComment = $method->getAttribute('docCommentParsed'))
422+
&& isset($parsedComment['return'])
423+
) {
424+
$result = implode('|', $parsedComment['return']);
425+
426+
return $result;
427+
} elseif ($this->dependencyGraph !== null) {
428+
/** @var Class_ $methodClass */
429+
$methodClass = $method->getAttribute('parent');
430+
if ($methodClass) {
431+
$ancestors = [];
432+
if (!empty($methodClass->extends)) {
433+
$ancestors = $this->addAncestorsToArray($ancestors, $methodClass->extends);
434+
}
435+
if (!empty($methodClass->implements)) {
436+
$ancestors = $this->addAncestorsToArray($ancestors, $methodClass->implements);
437+
}
438+
/** @var Name $ancestor */
439+
foreach ($ancestors as $ancestor) {
440+
$ancestorClass = $this->dependencyGraph->findEntityByName($ancestor->toString());
441+
if ($ancestorClass) {
442+
foreach ($ancestorClass->getMethodList() as $methodItem) {
443+
if ($method->name->toString() == $methodItem->name->toString()) {
444+
$result = $this->getDocReturnDeclaration($methodItem);
445+
if (!empty(trim($result))) {
446+
return $result;
447+
}
448+
}
449+
}
450+
}
451+
}
452+
}
437453
}
438-
return isset($tag) ? (string)$tag->value : ' ';
454+
455+
return ' ';
456+
}
457+
458+
/**
459+
* Add ancestors to array
460+
*
461+
* @param array $ancestors
462+
* @param array|Name $toAdd
463+
* @return array
464+
*/
465+
private function addAncestorsToArray(array $ancestors, $toAdd)
466+
{
467+
if (!empty($toAdd)) {
468+
if (is_array($toAdd)) {
469+
$ancestors = array_merge($ancestors, $toAdd);
470+
} else {
471+
$ancestors[] = $toAdd;
472+
}
473+
}
474+
475+
return $ancestors;
439476
}
440477

441478
/**

src/Analyzer/Factory/AnalyzerFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function create(DependencyGraph $dependencyGraph = null): AnalyzerInterfa
3030
{
3131
$analyzers = [
3232
new ClassAnalyzer(null, null, null, $dependencyGraph),
33-
new InterfaceAnalyzer(),
33+
new InterfaceAnalyzer(null, null, null, $dependencyGraph),
3434
new TraitAnalyzer(),
3535
];
3636

src/Analyzer/Factory/NonApiAnalyzerFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ class NonApiAnalyzerFactory implements AnalyzerFactoryInterface
2828
public function create(DependencyGraph $dependencyGraph = null): AnalyzerInterface
2929
{
3030
$analyzers = [
31-
new ClassAnalyzer(),
32-
new InterfaceAnalyzer(),
31+
new ClassAnalyzer(null, null, null, $dependencyGraph),
32+
new InterfaceAnalyzer(null, null, null, $dependencyGraph),
3333
new TraitAnalyzer(),
3434
];
3535

src/Analyzer/InterfaceAnalyzer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ protected function reportChanged($report, $registryBefore, $registryAfter, $toVe
139139
protected function getContentAnalyzers($context, $fileBefore, $fileAfter)
140140
{
141141
return [
142-
new ClassMethodAnalyzer($context, $fileBefore, $fileAfter),
142+
new ClassMethodAnalyzer($context, $fileBefore, $fileAfter, $this->dependencyGraph),
143143
new ClassConstantAnalyzer($context, $fileBefore, $fileAfter),
144144
new ClassMethodExceptionAnalyzer($context, $fileBefore, $fileAfter),
145145
new InterfaceExtendsAnalyzer($context, $fileBefore, $fileAfter)

src/Analyzer/MethodDocBlockAnalyzer.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@
3535
* - method param typehint moved from in-line to doc block
3636
* - method return typehint moved from doc block to in-line
3737
* - method return typehint moved from in-line to doc block
38+
*
39+
* TODO: this class should be rewritten using new possibility added by
40+
* Magento\SemanticVersionChecker\Visitor\NameResolver
41+
* Now all information (and resolved typed) about DocBlock params and return type exists in
42+
* method node 'docCommentParsed' attribute
3843
*/
3944
class MethodDocBlockAnalyzer
4045
{

src/ClassHierarchy/StaticAnalyzerFactory.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
namespace Magento\SemanticVersionChecker\ClassHierarchy;
1111

1212
use Magento\SemanticVersionChecker\Helper\Node as NodeHelper;
13+
use Magento\SemanticVersionChecker\Visitor\ParentConnector;
1314
use PhpParser\NodeTraverser;
14-
use PhpParser\NodeVisitor\NameResolver;
15+
use Magento\SemanticVersionChecker\Visitor\NameResolver;
1516
use PhpParser\ParserFactory;
1617

1718
/**
@@ -31,6 +32,7 @@ public function create(): StaticAnalyzer
3132
);
3233
$nodeTraverser = new NodeTraverser();
3334

35+
$nodeTraverser->addVisitor(new ParentConnector());
3436
$nodeTraverser->addVisitor(new NameResolver());
3537

3638
return new StaticAnalyzer($parser, $dependencyInspectionVisitor, $nodeTraverser);

src/Operation/Mftf/Suite/SuiteBeforeAfterActionGroupRefChanged.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class SuiteBeforeAfterActionGroupRefChanged extends MftfOperation
2121
* Operation Severity
2222
* @var int
2323
*/
24-
protected $level = Level::MAJOR;
24+
protected $level = Level::MINOR;
2525

2626
/**
2727
* Operation message.

0 commit comments

Comments
 (0)