{"action":"created","issue":{"url":"https://api.github.com/repos/snowio/magento2-data-model/issues/14","repository_url":"https://api.github.com/repos/snowio/magento2-data-model","labels_url":"https://api.github.com/repos/snowio/magento2-data-model/issues/14/labels{/name}","comments_url":"https://api.github.com/repos/snowio/magento2-data-model/issues/14/comments","events_url":"https://api.github.com/repos/snowio/magento2-data-model/issues/14/events","html_url":"https://github.com/snowio/magento2-data-model/issues/14","id":317654975,"node_id":"MDU6SXNzdWUzMTc2NTQ5NzU=","number":14,"title":"Use magic methods for simple withers and getters","user":{"login":"nei","id":33385,"node_id":"MDQ6VXNlcjMzMzg1","avatar_url":"https://avatars0.githubusercontent.com/u/33385?v=4","gravatar_id":"","url":"https://api.github.com/users/nei","html_url":"https://github.com/nei","followers_url":"https://api.github.com/users/nei/followers","following_url":"https://api.github.com/users/nei/following{/other_user}","gists_url":"https://api.github.com/users/nei/gists{/gist_id}","starred_url":"https://api.github.com/users/nei/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nei/subscriptions","organizations_url":"https://api.github.com/users/nei/orgs","repos_url":"https://api.github.com/users/nei/repos","events_url":"https://api.github.com/users/nei/events{/privacy}","received_events_url":"https://api.github.com/users/nei/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2018-04-25T14:31:43Z","updated_at":"2018-12-12T12:07:32Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"As discussed here https://github.com/snowio/magento2-data-model/pull/13 we should think about using magic method for this getters.  having hundreds of lines of code is not really nice.\r\n\r\nLets try a POC"},"comment":{"url":"https://api.github.com/repos/snowio/magento2-data-model/issues/comments/446565535","html_url":"https://github.com/snowio/magento2-data-model/issues/14#issuecomment-446565535","issue_url":"https://api.github.com/repos/snowio/magento2-data-model/issues/14","id":446565535,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0NjU2NTUzNQ==","user":{"login":"joshdifabio","id":5609851,"node_id":"MDQ6VXNlcjU2MDk4NTE=","avatar_url":"https://avatars1.githubusercontent.com/u/5609851?v=4","gravatar_id":"","url":"https://api.github.com/users/joshdifabio","html_url":"https://github.com/joshdifabio","followers_url":"https://api.github.com/users/joshdifabio/followers","following_url":"https://api.github.com/users/joshdifabio/following{/other_user}","gists_url":"https://api.github.com/users/joshdifabio/gists{/gist_id}","starred_url":"https://api.github.com/users/joshdifabio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joshdifabio/subscriptions","organizations_url":"https://api.github.com/users/joshdifabio/orgs","repos_url":"https://api.github.com/users/joshdifabio/repos","events_url":"https://api.github.com/users/joshdifabio/events{/privacy}","received_events_url":"https://api.github.com/users/joshdifabio/received_events","type":"User","site_admin":false},"created_at":"2018-12-12T12:07:32Z","updated_at":"2018-12-12T12:07:32Z","author_association":"CONTRIBUTOR","body":"Personally I would use AutoValue, because it was created by Google to solve this problem. It seems like you are in danger of reinventing the wheel here (as I have done so many times in the past), with all the costs that come with this.\r\n\r\nRegarding abstract methods vs. doc block annotations; you have to define the properties and their types somehow, you can either do that using PHP language features using AutoValue, e.g.\r\n\r\n```php\r\nabstract class PaymentData\r\n{\r\n    abstract function baseAmountAuthorized(): ?string;\r\n    // or the following -- but this means lots of redundant keywords\r\n    abstract function getBaseAmountAuthorized(): ?string;\r\n}\r\n```\r\n\r\n_or_ you can use extralinguistic features like `@method` annotations.\r\n\r\nIf you use languages features then you get type safety, plus things like JSON serialization for free because you can use existing libraries, e.g. symfony/serializer.\r\n\r\nIn many cases you will also want builders, e.g. where a value has many required properties. If you don't implement builders, the alternative is either a) having a constructor with lots of parameters or b) allowing a value to be constructed in an invalid state without required properties. AutoValue makes it fairly easy to generate builders, which are the best solution to this problem.\r\n\r\nWe are using AutoValue and symfony/serializer to serialize to JSON and this has eliminated most of the boilerplate for us. (You can use the normalization functionality of symfony/serializer to create JSON object-like arrays which is what your `toJson()` methods do.) No hand-writing equals methods, serialization logic or builders, plus you get type safety and you can make the most of existing tooling and libraries because you're just writing PHP.\r\n\r\nWhatever you do I'd suggest using an existing solution to this problem. I personally think Google's approach to this is the best one (AutoValue), which is why we ported it to PHP."}}
{"actor":{"display_login":"joshdifabio"}}