Skip to content

Commit 70be34c

Browse files
committed
MC-25111: SVC false-positive: method return typing changed
1 parent d9b8505 commit 70be34c

File tree

11 files changed

+143
-5
lines changed

11 files changed

+143
-5
lines changed

src/Analyzer/ClassMethodAnalyzer.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,10 @@ private function getDocReturnDeclaration(ClassMethod $method)
430430
if ($methodClass) {
431431
$ancestors = [];
432432
if (!empty($methodClass->extends)) {
433-
$ancestors[] = $methodClass->extends;
433+
$ancestors = $this->addAncestorsToArray($ancestors, $methodClass->extends);
434434
}
435435
if (!empty($methodClass->implements)) {
436-
$ancestors = array_merge($ancestors, $methodClass->implements);
436+
$ancestors = $this->addAncestorsToArray($ancestors, $methodClass->implements);
437437
}
438438
/** @var Name $ancestor */
439439
foreach ($ancestors as $ancestor) {
@@ -455,6 +455,26 @@ private function getDocReturnDeclaration(ClassMethod $method)
455455
return ' ';
456456
}
457457

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;
476+
}
477+
458478
/**
459479
* Checks changed constructor parameters.
460480
*

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function create(DependencyGraph $dependencyGraph = null): AnalyzerInterfa
2929
{
3030
$analyzers = [
3131
new ClassAnalyzer(null, null, null, $dependencyGraph),
32-
new InterfaceAnalyzer(),
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)

tests/Unit/Console/Command/CompareSourceCommandNonApiInterfacesTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,14 @@ public function changesDataProvider()
153153
],
154154
'Patch change is detected.'
155155
],
156+
'docblock-return-type-not-changed' => [
157+
$pathToFixtures . '/docblock-return-type-not-changed/source-code-before',
158+
$pathToFixtures . '/docblock-return-type-not-changed/source-code-after',
159+
[
160+
'Suggested semantic versioning change: NONE'
161+
],
162+
'Patch change is detected.'
163+
],
156164
];
157165
}
158166
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Test\Vcs\Parent;
7+
8+
interface ParentTestInterface
9+
{
10+
/**
11+
* @return null|int|\Test\Vcs\Path\TestClass2
12+
*/
13+
public function testMethodInherited();
14+
15+
/**
16+
* @return null|int|\Test\Vcs\Path\TestClass2
17+
*/
18+
public function testMethodInherited2();
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Test\Vcs\Path;
7+
8+
class TestClass2
9+
{
10+
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Test\Vcs;
7+
8+
use Test\Vcs\Path\TestClass2;
9+
10+
interface TestInterface extends \Test\Vcs\Parent\ParentTestInterface
11+
{
12+
/**
13+
* @return $this
14+
*/
15+
public function testMethod();
16+
17+
/**
18+
* @return TestClass2
19+
*/
20+
public function testMethod2();
21+
22+
/**
23+
* @inheritDoc
24+
*/
25+
public function testMethodInherited();
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Test\Vcs\Parent;
7+
8+
interface ParentTestInterface
9+
{
10+
/**
11+
* @return null|int|\Test\Vcs\Path\TestClass2
12+
*/
13+
public function testMethodInherited();
14+
15+
/**
16+
* @return null|int|\Test\Vcs\Path\TestClass2
17+
*/
18+
public function testMethodInherited2();
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Test\Vcs\Path;
7+
8+
class TestClass2
9+
{
10+
11+
}

0 commit comments

Comments
 (0)