{"action":"created","issue":{"url":"https://api.github.com/repos/magento/magento2/issues/2451","repository_url":"https://api.github.com/repos/magento/magento2","labels_url":"https://api.github.com/repos/magento/magento2/issues/2451/labels{/name}","comments_url":"https://api.github.com/repos/magento/magento2/issues/2451/comments","events_url":"https://api.github.com/repos/magento/magento2/issues/2451/events","html_url":"https://github.com/magento/magento2/pull/2451","id":118124701,"number":2451,"title":"Add type declaration to setter methods of generated ExtensionAttribute classes","user":{"login":"erikhansen","id":129031,"avatar_url":"https://avatars.githubusercontent.com/u/129031?v=3","gravatar_id":"","url":"https://api.github.com/users/erikhansen","html_url":"https://github.com/erikhansen","followers_url":"https://api.github.com/users/erikhansen/followers","following_url":"https://api.github.com/users/erikhansen/following{/other_user}","gists_url":"https://api.github.com/users/erikhansen/gists{/gist_id}","starred_url":"https://api.github.com/users/erikhansen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/erikhansen/subscriptions","organizations_url":"https://api.github.com/users/erikhansen/orgs","repos_url":"https://api.github.com/users/erikhansen/repos","events_url":"https://api.github.com/users/erikhansen/events{/privacy}","received_events_url":"https://api.github.com/users/erikhansen/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/magento/magento2/labels/accept","name":"accept","color":"009800"},{"url":"https://api.github.com/repos/magento/magento2/labels/acknowledged","name":"acknowledged","color":"02d7e1"},{"url":"https://api.github.com/repos/magento/magento2/labels/needs%20update","name":"needs update","color":"eb6420"},{"url":"https://api.github.com/repos/magento/magento2/labels/PS","name":"PS","color":"fad8c7"}],"state":"open","locked":false,"assignee":{"login":"okorshenko","id":7325075,"avatar_url":"https://avatars.githubusercontent.com/u/7325075?v=3","gravatar_id":"","url":"https://api.github.com/users/okorshenko","html_url":"https://github.com/okorshenko","followers_url":"https://api.github.com/users/okorshenko/followers","following_url":"https://api.github.com/users/okorshenko/following{/other_user}","gists_url":"https://api.github.com/users/okorshenko/gists{/gist_id}","starred_url":"https://api.github.com/users/okorshenko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/okorshenko/subscriptions","organizations_url":"https://api.github.com/users/okorshenko/orgs","repos_url":"https://api.github.com/users/okorshenko/repos","events_url":"https://api.github.com/users/okorshenko/events{/privacy}","received_events_url":"https://api.github.com/users/okorshenko/received_events","type":"User","site_admin":false},"milestone":null,"comments":9,"created_at":"2015-11-20T20:59:07Z","updated_at":"2016-03-22T02:20:47Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/magento/magento2/pulls/2451","html_url":"https://github.com/magento/magento2/pull/2451","diff_url":"https://github.com/magento/magento2/pull/2451.diff","patch_url":"https://github.com/magento/magento2/pull/2451.patch"},"body":"The code that generates the classes that implement the `\\Magento\\Framework\\Api\\ExtensionAttributesInterface` interface were doing so in a way that did not add type declarations to the setter methods. This pull request adds functionality to add type declarations, but *only* for types that are valid type declarations. It is important to have type declarations added to the setter methods of ExtensionAttribute classes as it ensures that the getter methods will always return objects of the proper interface/class.\r\n\r\nSummary of changes:\r\n\r\n* Modified `\\Magento\\Framework\\Api\\Code\\Generator\\ExtensionAttributesGenerator::_getClassMethods` method to add type declaration to method, as long as type is a valid (e.g. not a primitive type or an array of classes/interfaces).\r\n* Added isValidTypeDeclaration method to \\Magento\\Framework\\Reflection\\TypeProcessor to centralize the logic for determining whether a string is valid as a type declaration. When and if Magento 2 supports PHP 7, the logic of this method should be changed to support primitive types. I referenced the [PHP Type Declaration](http://php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration) section when writing the `\\Magento\\Framework\\Reflection\\Test\\Unit\\TypeProcessorTest::testIsValidTypeDeclaration` test. I wrote what I believe to be a very comprehensive set of true and false assertions.\r\n\r\nHere is an example of how this auto-generated file changes: `var/generation/Magento/Catalog/Api/Data/ProductAttributeMediaGalleryEntryExtension.php`. \r\n\r\n## Before pull request\r\n\r\n```php\r\n<?php\r\nnamespace Magento\\Catalog\\Api\\Data;\r\n\r\n/**\r\n * Extension class for @see\r\n * \\Magento\\Catalog\\Api\\Data\\ProductAttributeMediaGalleryEntryInterface\r\n */\r\nclass ProductAttributeMediaGalleryEntryExtension extends \\Magento\\Framework\\Api\\AbstractSimpleObject implements \\Magento\\Catalog\\Api\\Data\\ProductAttributeMediaGalleryEntryExtensionInterface\r\n{\r\n    /**\r\n     * @return \\Magento\\Framework\\Api\\Data\\VideoContentInterface|null\r\n     */\r\n    public function getVideoContent()\r\n    {\r\n        return $this->_get('video_content');\r\n    }\r\n\r\n    /**\r\n     * @param \\Magento\\Framework\\Api\\Data\\VideoContentInterface $videoContent\r\n     * @return $this\r\n     */\r\n    public function setVideoContent($videoContent)\r\n    {\r\n        $this->setData('video_content', $videoContent);\r\n        return $this;\r\n    }\r\n}\r\n```\r\n\r\n## After pull request\r\n\r\nYou'll notice that the `setVideoContent` method has a `\\Magento\\Framework\\Api\\Data\\VideoContentInterface` type declaration.\r\n\r\n```php\r\n<?php\r\nnamespace Magento\\Catalog\\Api\\Data;\r\n\r\n/**\r\n * Extension class for @see\r\n * \\Magento\\Catalog\\Api\\Data\\ProductAttributeMediaGalleryEntryInterface\r\n */\r\nclass ProductAttributeMediaGalleryEntryExtension extends \\Magento\\Framework\\Api\\AbstractSimpleObject implements \\Magento\\Catalog\\Api\\Data\\ProductAttributeMediaGalleryEntryExtensionInterface\r\n{\r\n    /**\r\n     * @return \\Magento\\Framework\\Api\\Data\\VideoContentInterface|null\r\n     */\r\n    public function getVideoContent()\r\n    {\r\n        return $this->_get('video_content');\r\n    }\r\n\r\n    /**\r\n     * @param \\Magento\\Framework\\Api\\Data\\VideoContentInterface $videoContent\r\n     * @return $this\r\n     */\r\n    public function setVideoContent(\\Magento\\Framework\\Api\\Data\\VideoContentInterface $videoContent)\r\n    {\r\n        $this->setData('video_content', $videoContent);\r\n        return $this;\r\n    }\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/magento/magento2/issues/comments/199588228","html_url":"https://github.com/magento/magento2/pull/2451#issuecomment-199588228","issue_url":"https://api.github.com/repos/magento/magento2/issues/2451","id":199588228,"user":{"login":"erikhansen","id":129031,"avatar_url":"https://avatars.githubusercontent.com/u/129031?v=3","gravatar_id":"","url":"https://api.github.com/users/erikhansen","html_url":"https://github.com/erikhansen","followers_url":"https://api.github.com/users/erikhansen/followers","following_url":"https://api.github.com/users/erikhansen/following{/other_user}","gists_url":"https://api.github.com/users/erikhansen/gists{/gist_id}","starred_url":"https://api.github.com/users/erikhansen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/erikhansen/subscriptions","organizations_url":"https://api.github.com/users/erikhansen/orgs","repos_url":"https://api.github.com/users/erikhansen/repos","events_url":"https://api.github.com/users/erikhansen/events{/privacy}","received_events_url":"https://api.github.com/users/erikhansen/received_events","type":"User","site_admin":false},"created_at":"2016-03-22T02:20:47Z","updated_at":"2016-03-22T02:20:47Z","body":"@okorshenko I just fixed the issue with the test that failed back in January. I'll see what additional tests fail and resolve those issue, assuming the fixes are not too intensive."}}