diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/Di/CompilerTest.php b/dev/tests/static/testsuite/Magento/Test/Integrity/Di/CompilerTest.php index f8b15c268f4da..9b59d73cad38e 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/Di/CompilerTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/Di/CompilerTest.php @@ -101,7 +101,6 @@ protected function setUp() ); $this->_validator = new \Magento\Framework\Code\Validator(); $this->_validator->add(new \Magento\Framework\Code\Validator\ConstructorIntegrity()); - $this->_validator->add(new \Magento\Framework\Code\Validator\ContextAggregation()); $this->_validator->add(new \Magento\Framework\Code\Validator\TypeDuplication()); $this->_validator->add(new \Magento\Framework\Code\Validator\ArgumentSequence()); $this->_validator->add(new \Magento\Framework\Code\Validator\ConstructorArgumentTypes()); diff --git a/lib/internal/Magento/Framework/Code/Test/Unit/Validator/ContextAggregationTest.php b/lib/internal/Magento/Framework/Code/Test/Unit/Validator/ContextAggregationTest.php deleted file mode 100644 index 6a630747747c9..0000000000000 --- a/lib/internal/Magento/Framework/Code/Test/Unit/Validator/ContextAggregationTest.php +++ /dev/null @@ -1,59 +0,0 @@ -_model = new \Magento\Framework\Code\Validator\ContextAggregation(); - $this->_fixturePath = str_replace('\\', '/', realpath(__DIR__) . '/_files/ClassesForContextAggregation.php'); - } - - public function testClassArgumentAlreadyInjectedIntoContext() - { - $message = 'Incorrect dependency in class ClassArgumentAlreadyInjectedInContext in ' . - $this->_fixturePath . - PHP_EOL . - '\ClassFirst already exists in context object'; - - $this->setExpectedException(\Magento\Framework\Exception\ValidatorException::class, $message); - $this->_model->validate('ClassArgumentAlreadyInjectedInContext'); - } - - public function testClassArgumentWithInterfaceImplementation() - { - $this->assertTrue($this->_model->validate('ClassArgumentWithInterfaceImplementation')); - } - - public function testClassArgumentWithInterface() - { - $this->assertTrue($this->_model->validate('ClassArgumentWithInterface')); - } - - public function testClassArgumentWithAlreadyInjectedInterface() - { - $message = 'Incorrect dependency in class ClassArgumentWithAlreadyInjectedInterface in ' . - $this->_fixturePath . - PHP_EOL . - '\\InterfaceFirst already exists in context object'; - - $this->setExpectedException(\Magento\Framework\Exception\ValidatorException::class, $message); - $this->_model->validate('ClassArgumentWithAlreadyInjectedInterface'); - } -} diff --git a/lib/internal/Magento/Framework/Code/Test/Unit/Validator/_files/ClassesForContextAggregation.php b/lib/internal/Magento/Framework/Code/Test/Unit/Validator/_files/ClassesForContextAggregation.php deleted file mode 100644 index c2af1e87e8098..0000000000000 --- a/lib/internal/Magento/Framework/Code/Test/Unit/Validator/_files/ClassesForContextAggregation.php +++ /dev/null @@ -1,169 +0,0 @@ -_exA = $exA; - $this->_exB = $exB; - $this->_exC = $exC; - $this->_interfaceA = $interfaceA; - $this->_implOfBInterface = $implOfBInterface; - } -} -class ClassArgumentAlreadyInjectedInContext -{ - /** - * @var ContextFirst - */ - protected $_context; - - /** - * @var ClassFirst - */ - protected $_exA; - - /** - * @param ContextFirst $context - * @param ClassFirst $exA - */ - public function __construct(\ContextFirst $context, \ClassFirst $exA) - { - $this->_context = $context; - $this->_exA = $exA; - } -} -class ClassArgumentWithInterfaceImplementation -{ - /** - * @var ContextFirst - */ - protected $_context; - - /** - * @var ImplementationOfInterfaceFirst - */ - protected $_exA; - - /** - * @param ContextFirst $context - * @param ImplementationOfInterfaceFirst $exA - */ - public function __construct(\ContextFirst $context, \ImplementationOfInterfaceFirst $exA) - { - $this->_context = $context; - $this->_exA = $exA; - } -} -class ClassArgumentWithInterface -{ - /** - * @var ContextFirst - */ - protected $_context; - - /** - * @var InterfaceSecond - */ - protected $_exB; - - /** - * @param ContextFirst $context - * @param InterfaceSecond $exB - */ - public function __construct(\ContextFirst $context, \InterfaceSecond $exB) - { - $this->_context = $context; - $this->_exB = $exB; - } -} -class ClassArgumentWithAlreadyInjectedInterface -{ - /** - * @var ContextFirst - */ - protected $_context; - - /** - * @var InterfaceFirst - */ - protected $_exA; - - /** - * @param ContextFirst $context - * @param InterfaceFirst $exA - */ - public function __construct(\ContextFirst $context, \InterfaceFirst $exA) - { - $this->_context = $context; - $this->_exA = $exA; - } -} diff --git a/lib/internal/Magento/Framework/Code/Validator/ContextAggregation.php b/lib/internal/Magento/Framework/Code/Validator/ContextAggregation.php deleted file mode 100644 index ec4a8af26defc..0000000000000 --- a/lib/internal/Magento/Framework/Code/Validator/ContextAggregation.php +++ /dev/null @@ -1,98 +0,0 @@ -_argumentsReader = $argumentsReader ?: new \Magento\Framework\Code\Reader\ArgumentsReader(); - } - - /** - * Validate class. Check declaration of dependencies that already declared in context object - * - * @param string $className - * @return bool - * @throws \Magento\Framework\Exception\ValidatorException - */ - public function validate($className) - { - $class = new \ReflectionClass($className); - $classArguments = $this->_argumentsReader->getConstructorArguments($class); - - $errors = []; - $contextDependencies = []; - - $actualDependencies = $this->_getObjectArguments($classArguments); - - foreach ($actualDependencies as $type) { - /** Check if argument is context object */ - if (is_subclass_of($type, \Magento\Framework\ObjectManager\ContextInterface::class)) { - $contextDependencies = array_merge( - $contextDependencies, - $this->_argumentsReader->getConstructorArguments(new \ReflectionClass($type), false, true) - ); - } - } - - $contextDependencyTypes = $this->_getObjectArguments($contextDependencies); - - foreach ($actualDependencies as $type) { - if (in_array($type, $contextDependencyTypes)) { - $errors[] = $type . ' already exists in context object'; - } - } - - if (false == empty($errors)) { - $classPath = str_replace('\\', '/', $class->getFileName()); - throw new \Magento\Framework\Exception\ValidatorException( - new \Magento\Framework\Phrase( - 'Incorrect dependency in class %1 in %2%3%4', - [ - $className, - $classPath, - PHP_EOL, - implode(PHP_EOL, $errors) - ] - ) - ); - } - return true; - } - - /** - * Get arguments with object types - * - * @param array $arguments - * @return array - */ - protected function _getObjectArguments(array $arguments) - { - $output = []; - foreach ($arguments as $argument) { - $type = $argument['type']; - if (!$type || $type == 'array') { - continue; - } - $output[] = $type; - } - - return $output; - } -} diff --git a/setup/src/Magento/Setup/Module/Di/Code/Reader/Decorator/Interceptions.php b/setup/src/Magento/Setup/Module/Di/Code/Reader/Decorator/Interceptions.php index 87db2563528ba..a1f8d77ca77d3 100644 --- a/setup/src/Magento/Setup/Module/Di/Code/Reader/Decorator/Interceptions.php +++ b/setup/src/Magento/Setup/Module/Di/Code/Reader/Decorator/Interceptions.php @@ -40,7 +40,6 @@ class Interceptions implements \Magento\Setup\Module\Di\Code\Reader\ClassesScann * @param \Magento\Framework\Code\Reader\ClassReader $classReader * @param \Magento\Framework\Code\Validator $validator * @param \Magento\Framework\Code\Validator\ConstructorIntegrity $constructorIntegrityValidator - * @param \Magento\Framework\Code\Validator\ContextAggregation $contextAggregationValidator * @param Log $log */ public function __construct( @@ -48,7 +47,6 @@ public function __construct( \Magento\Framework\Code\Reader\ClassReader $classReader, \Magento\Framework\Code\Validator $validator, \Magento\Framework\Code\Validator\ConstructorIntegrity $constructorIntegrityValidator, - \Magento\Framework\Code\Validator\ContextAggregation $contextAggregationValidator, Log $log ) { $this->classReader = $classReader; @@ -57,7 +55,6 @@ public function __construct( $this->log = $log; $this->validator->add($constructorIntegrityValidator); - $this->validator->add($contextAggregationValidator); } /** diff --git a/setup/src/Magento/Setup/Test/Unit/Module/Di/Code/Reader/InstancesNamesList/InterceptionsTest.php b/setup/src/Magento/Setup/Test/Unit/Module/Di/Code/Reader/InstancesNamesList/InterceptionsTest.php index bbb3dd587bf75..b6fa3f869e2e2 100644 --- a/setup/src/Magento/Setup/Test/Unit/Module/Di/Code/Reader/InstancesNamesList/InterceptionsTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Module/Di/Code/Reader/InstancesNamesList/InterceptionsTest.php @@ -69,7 +69,6 @@ protected function setUp() $this->classReaderMock, $this->validatorMock, new \Magento\Framework\Code\Validator\ConstructorIntegrity(), - new \Magento\Framework\Code\Validator\ContextAggregation(), $this->logMock ); }