{"action":"created","issue":{"url":"https://api.github.com/repos/websharks/comet-cache-pro/issues/222","repository_url":"https://api.github.com/repos/websharks/comet-cache-pro","labels_url":"https://api.github.com/repos/websharks/comet-cache-pro/issues/222/labels{/name}","comments_url":"https://api.github.com/repos/websharks/comet-cache-pro/issues/222/comments","events_url":"https://api.github.com/repos/websharks/comet-cache-pro/issues/222/events","html_url":"https://github.com/websharks/comet-cache-pro/pull/222","id":136990093,"number":222,"title":"Convert to PHP Traits","user":{"login":"raamdev","id":53005,"avatar_url":"https://avatars.githubusercontent.com/u/53005?v=3","gravatar_id":"","url":"https://api.github.com/users/raamdev","html_url":"https://github.com/raamdev","followers_url":"https://api.github.com/users/raamdev/followers","following_url":"https://api.github.com/users/raamdev/following{/other_user}","gists_url":"https://api.github.com/users/raamdev/gists{/gist_id}","starred_url":"https://api.github.com/users/raamdev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/raamdev/subscriptions","organizations_url":"https://api.github.com/users/raamdev/orgs","repos_url":"https://api.github.com/users/raamdev/repos","events_url":"https://api.github.com/users/raamdev/events{/privacy}","received_events_url":"https://api.github.com/users/raamdev/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2016-02-28T01:26:06Z","updated_at":"2016-02-28T11:39:10Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/websharks/comet-cache-pro/pulls/222","html_url":"https://github.com/websharks/comet-cache-pro/pull/222","diff_url":"https://github.com/websharks/comet-cache-pro/pull/222.diff","patch_url":"https://github.com/websharks/comet-cache-pro/pull/222.patch"},"body":"See websharks/comet-cache#635\r\n\r\n---\r\n\r\n## Converting Closures to Traits (Step 1 of 2)\r\n\r\nIn this step we will convert Closure files into Traits. The codebase will _not_ function with these changes alone. In step 2 of 2 (later) we will implement the new Traits and be ready then. I will outline that soon.\r\n\r\n### Outline for Step 1\r\n\r\n- [x] Rename [this directory](https://github.com/websharks/comet-cache-pro/tree/000000-dev/src/includes/closures) to `traits`.\r\n\r\n- [ ] Convert each file in the `traits` directory into a Trait.\r\n\r\n  - [Example file](https://github.com/websharks/comet-cache-pro/blob/000000-dev/src/includes/closures/Plugin/WcpUtils.php) converted to a Trait. Converted (in part, as an example): https://gist.github.com/jaswsinc/a175d369dfb0f17c876a\r\n\r\n#### Converting Closures into Traits\r\n\r\nFollowing the example above, here are some things to be aware of.\r\n\r\n- [x] `$self->property = value;` becomes `public $property = value;`\r\n- [ ] `$self->functionName` becomes `public function functionName`\r\n- [x] Ditch `use($self)`.\r\n- [x] Change `$self` references inside a method into `$this`.\r\n- [x] Change `};` ending a Closure into just `}`.\r\n- [x] Wrap all of the properties/methods into a Trait with the same name as the file they live in; i.e., `trait WcpUtils {}` as seen in the example above.\r\n- [x] Change the namespace in the file by adding `\\Traits\\Ac|Plugin|Shared` (depending on the main folder).\r\n\r\n## Converting Closures into Traits (Step 1.3 of 2, lol)\r\n\r\n- [ ] Alter the namespace in these files by appending `\\Classes` to the existing namespace. https://github.com/websharks/comet-cache-pro/tree/000000-dev/src/includes/classes\r\n\r\n- [ ] In `composer.json`, replace [this line](https://github.com/websharks/comet-cache-pro/blob/160227/composer.json#L46) with the following:\r\n\r\n  ```json\r\n  \"WebSharks\\\\CometCache\\\\Pro\\\\Classes\\\\\": \"src/includes/classes/\"\r\n  \"WebSharks\\\\CometCache\\\\Pro\\\\Traits\\\\\": \"src/includes/traits/\"\r\n  ```\r\n\r\n- [ ] At the top of each Trait file, add a blank line, and then the following after the namespace.\r\n\r\n  ```php\r\n  use WebSharks\\CometCache\\Pro\\Classes;\r\n  ```\r\n\r\n- [ ] In each Trait file, search for instances of `new ClassName` and prepend those with `Classes\\`; i.e., `new Classes\\ClassName` so that it can be resolved properly from inside the Trait.\r\n\r\n- [ ] Do the same thing for static calls; i.e., look for instances of `ClassName::` and change that to `Classes\\ClassName::` instead, so that it will resolve properly from inside the Trait."},"comment":{"url":"https://api.github.com/repos/websharks/comet-cache-pro/issues/comments/189849068","html_url":"https://github.com/websharks/comet-cache-pro/pull/222#issuecomment-189849068","issue_url":"https://api.github.com/repos/websharks/comet-cache-pro/issues/222","id":189849068,"user":{"login":"jaswsinc","id":1563559,"avatar_url":"https://avatars.githubusercontent.com/u/1563559?v=3","gravatar_id":"","url":"https://api.github.com/users/jaswsinc","html_url":"https://github.com/jaswsinc","followers_url":"https://api.github.com/users/jaswsinc/followers","following_url":"https://api.github.com/users/jaswsinc/following{/other_user}","gists_url":"https://api.github.com/users/jaswsinc/gists{/gist_id}","starred_url":"https://api.github.com/users/jaswsinc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jaswsinc/subscriptions","organizations_url":"https://api.github.com/users/jaswsinc/orgs","repos_url":"https://api.github.com/users/jaswsinc/repos","events_url":"https://api.github.com/users/jaswsinc/events{/privacy}","received_events_url":"https://api.github.com/users/jaswsinc/received_events","type":"User","site_admin":false},"created_at":"2016-02-28T11:39:10Z","updated_at":"2016-02-28T11:39:10Z","body":"> $this->{'http_status'}\r\n> Is that correct? Or should it be $this->http_status?\r\n\r\nEither of those are correct; i.e., they both reference a property in `$this` class. However, I agree with you, it should be `$this->http_status` for clarity. I'm not sure why I have `{}` brackets there. The only time those are really needed is when a property breaks the rules in some way; e.g., if the property starts with a number or with another character that is not valid variable syntax, strictly speaking.\r\n\r\nAnother example of when `{}` brackets are helpful, is when you are building the property name out of another variable; e.g., `$this->{$dynamic.'_property_name'} = 'hello world';`. That may have been the case in this part of the code in the past. So this could be a remnant from something in the past that required the `{}` brackets. I don't see any reason to keep them moving forward though."}}