|
9 | 9 |
|
10 | 10 | namespace Magento\SemanticVersionChecker\Analyzer; |
11 | 11 |
|
| 12 | +use Magento\SemanticVersionChecker\ClassHierarchy\Entity; |
12 | 13 | use Magento\SemanticVersionChecker\Comparator\Visibility; |
13 | 14 | use Magento\SemanticVersionChecker\Operation\PropertyMoved; |
| 15 | +use Magento\SemanticVersionChecker\Operation\PropertyOverwriteAdded; |
14 | 16 | use Magento\SemanticVersionChecker\Operation\Visibility\PropertyDecreased as VisibilityPropertyDecreased; |
15 | 17 | use Magento\SemanticVersionChecker\Operation\Visibility\PropertyIncreased as VisibilityPropertyIncreased; |
16 | 18 | use PhpParser\Node; |
@@ -62,9 +64,53 @@ protected function getNodeClass() |
62 | 64 | */ |
63 | 65 | protected function reportAddedNode($report, $fileAfter, $classAfter, $propertyAfter) |
64 | 66 | { |
| 67 | + if ($this->dependencyGraph !== null) { |
| 68 | + $class = $this->dependencyGraph->findEntityByName((string)$classAfter->namespacedName); |
| 69 | + if ($class !== null) { |
| 70 | + $propertyOverwritten = $this->searchPropertyExistsRecursive( |
| 71 | + $class, |
| 72 | + $propertyAfter->props[0]->name->toString() |
| 73 | + ); |
| 74 | + if ($propertyOverwritten) { |
| 75 | + $report->add( |
| 76 | + $this->context, |
| 77 | + new PropertyOverwriteAdded($this->context, $fileAfter, $classAfter, $propertyAfter) |
| 78 | + ); |
| 79 | + |
| 80 | + return; |
| 81 | + } |
| 82 | + } |
| 83 | + } |
| 84 | + |
65 | 85 | $report->add($this->context, new PropertyAdded($this->context, $fileAfter, $classAfter, $propertyAfter)); |
66 | 86 | } |
67 | 87 |
|
| 88 | + /** |
| 89 | + * Check if there is such property in class inheritance chain. |
| 90 | + * |
| 91 | + * @param Entity $class |
| 92 | + * @param string $propertyName |
| 93 | + * @return boolean |
| 94 | + */ |
| 95 | + private function searchPropertyExistsRecursive($class, $propertyName) |
| 96 | + { |
| 97 | + /** @var Entity $entity */ |
| 98 | + foreach ($class->getExtends() as $entity) { |
| 99 | + $properties = $entity->getPropertyList(); |
| 100 | + // checks if the property is already exiting in parent class |
| 101 | + if (isset($properties[$propertyName])) { |
| 102 | + return true; |
| 103 | + } |
| 104 | + |
| 105 | + $result = $this->searchPropertyExistsRecursive($entity, $propertyName); |
| 106 | + if ($result) { |
| 107 | + return true; |
| 108 | + } |
| 109 | + } |
| 110 | + |
| 111 | + return false; |
| 112 | + } |
| 113 | + |
68 | 114 | /** |
69 | 115 | * Create and report a PropertyRemoved operation |
70 | 116 | * |
|
0 commit comments