{"action":"created","comment":{"url":"https://api.github.com/repos/refinery29/solr-annotations/pulls/comments/49732712","id":49732712,"diff_hunk":"@@ -0,0 +1,151 @@\n+<?php\n+\n+/*\n+ * Copyright (c) 2016 Refinery29, Inc.\n+ *\n+ * For the full copyright and license information, please view\n+ * the LICENSE file that was distributed with this source code.\n+ */\n+\n+namespace Refinery29\\SolrAnnotations\\Annotation;\n+\n+use Doctrine\\Common\\Annotations\\AnnotationReader;\n+use Doctrine\\Common\\Annotations\\AnnotationRegistry;\n+use Refinery29\\SolrAnnotations\\Annotation\\Document as DocumentAnnotation;\n+use ReflectionClass;\n+\n+class Parser\n+{\n+    /**\n+     * @var AnnotationReader\n+     */\n+    private $reader;\n+\n+    /**\n+     * @param AnnotationReader $reader\n+     */\n+    public function __construct(AnnotationReader $reader = null)\n+    {\n+        self::registerAnnotations();\n+        $this->reader = $reader ?: new AnnotationReader();\n+    }\n+\n+    /**\n+     * @param ReflectionClass $class\n+     *\n+     * @throws \\Exception\n+     *\n+     * @return mixed\n+     */\n+    public function validateClassAnnotation(ReflectionClass $class)\n+    {\n+        /** @var DocumentAnnotation $classAnnotation */\n+        $classAnnotation = $this->reader->getClassAnnotation($class, DocumentAnnotation::class);\n+\n+        if (empty($classAnnotation)) {\n+            throw new \\Exception(DocumentAnnotation::class . ' is required');\n+        }\n+\n+        return $classAnnotation;\n+    }\n+\n+    /**\n+     * @param ReflectionClass $class\n+     *\n+     * @throws \\Exception\n+     *\n+     * @return null|object\n+     */\n+    public function getDocumentName(ReflectionClass $class)\n+    {\n+        return $this->validateClassAnnotation($class)->getName();\n+    }\n+\n+    /**\n+     * @param ReflectionClass $class\n+     *\n+     * @return array\n+     */\n+    public function getProperties(ReflectionClass $class)\n+    {\n+        $properties = $class->getProperties();\n+\n+        $propertyAnnotations = [];\n+        foreach ($properties as $property) {\n+            $annotationName = $this->reader\n+                ->getPropertyAnnotation($property, Field::class);\n+\n+            if ($annotationName) {\n+                $annotationName = $annotationName->getName();\n+                $propertyAnnotations[$property->getName()] = $annotationName;\n+            }\n+        }\n+\n+        return array_flip($propertyAnnotations);\n+    }\n+\n+    /**\n+     * @param ReflectionClass $class\n+     *\n+     * @return array\n+     */\n+    public function getPropertyTypes(\\ReflectionClass $class)\n+    {\n+        $properties = $class->getProperties();\n+\n+        $propertyTypes = [];\n+        foreach ($properties as $property) {\n+            $propertyDoc = $property->getDocComment();\n+            $propertyType = 'string';\n+\n+            if (strpos($propertyDoc, '@var ') !== false) {\n+                $length = strlen($propertyDoc);\n+                $varDefinition = substr($propertyDoc, strpos($propertyDoc, '@var'), $length - 1);\n+\n+                $propertyType = trim(trim($varDefinition, '@var\\n/*'));","path":"src/Annotation/Parser.php","position":105,"original_position":105,"commit_id":"88e001e7f4c0571710d6a9df39781f1f63f4951d","original_commit_id":"88e001e7f4c0571710d6a9df39781f1f63f4951d","user":{"login":"settermjd","id":196801,"avatar_url":"https://avatars.githubusercontent.com/u/196801?v=3","gravatar_id":"","url":"https://api.github.com/users/settermjd","html_url":"https://github.com/settermjd","followers_url":"https://api.github.com/users/settermjd/followers","following_url":"https://api.github.com/users/settermjd/following{/other_user}","gists_url":"https://api.github.com/users/settermjd/gists{/gist_id}","starred_url":"https://api.github.com/users/settermjd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/settermjd/subscriptions","organizations_url":"https://api.github.com/users/settermjd/orgs","repos_url":"https://api.github.com/users/settermjd/repos","events_url":"https://api.github.com/users/settermjd/events{/privacy}","received_events_url":"https://api.github.com/users/settermjd/received_events","type":"User","site_admin":false},"body":"Is there a need to trim 2x?","created_at":"2016-01-14T14:39:15Z","updated_at":"2016-01-14T14:39:15Z","html_url":"https://github.com/refinery29/solr-annotations/pull/16#discussion_r49732712","pull_request_url":"https://api.github.com/repos/refinery29/solr-annotations/pulls/16","_links":{"self":{"href":"https://api.github.com/repos/refinery29/solr-annotations/pulls/comments/49732712"},"html":{"href":"https://github.com/refinery29/solr-annotations/pull/16#discussion_r49732712"},"pull_request":{"href":"https://api.github.com/repos/refinery29/solr-annotations/pulls/16"}}},"pull_request":{"url":"https://api.github.com/repos/refinery29/solr-annotations/pulls/16","id":55989769,"html_url":"https://github.com/refinery29/solr-annotations/pull/16","diff_url":"https://github.com/refinery29/solr-annotations/pull/16.diff","patch_url":"https://github.com/refinery29/solr-annotations/pull/16.patch","issue_url":"https://api.github.com/repos/refinery29/solr-annotations/issues/16","number":16,"state":"open","locked":false,"title":"Enhancement: Introduce Parser","user":{"login":"kayladnls","id":1276798,"avatar_url":"https://avatars.githubusercontent.com/u/1276798?v=3","gravatar_id":"","url":"https://api.github.com/users/kayladnls","html_url":"https://github.com/kayladnls","followers_url":"https://api.github.com/users/kayladnls/followers","following_url":"https://api.github.com/users/kayladnls/following{/other_user}","gists_url":"https://api.github.com/users/kayladnls/gists{/gist_id}","starred_url":"https://api.github.com/users/kayladnls/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kayladnls/subscriptions","organizations_url":"https://api.github.com/users/kayladnls/orgs","repos_url":"https://api.github.com/users/kayladnls/repos","events_url":"https://api.github.com/users/kayladnls/events{/privacy}","received_events_url":"https://api.github.com/users/kayladnls/received_events","type":"User","site_admin":false},"body":"This PR: \r\n- [x] abstracts parsing logic out of Hydrator and Schema Builder\r\n- [x] creates dedicated parser class","created_at":"2016-01-14T03:49:53Z","updated_at":"2016-01-14T14:39:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a064c33d61f2190f091ea95bdf69b47f581f5db1","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/refinery29/solr-annotations/pulls/16/commits","review_comments_url":"https://api.github.com/repos/refinery29/solr-annotations/pulls/16/comments","review_comment_url":"https://api.github.com/repos/refinery29/solr-annotations/pulls/comments{/number}","comments_url":"https://api.github.com/repos/refinery29/solr-annotations/issues/16/comments","statuses_url":"https://api.github.com/repos/refinery29/solr-annotations/statuses/88e001e7f4c0571710d6a9df39781f1f63f4951d","head":{"label":"refinery29:parser","ref":"parser","sha":"88e001e7f4c0571710d6a9df39781f1f63f4951d","user":{"login":"refinery29","id":821624,"avatar_url":"https://avatars.githubusercontent.com/u/821624?v=3","gravatar_id":"","url":"https://api.github.com/users/refinery29","html_url":"https://github.com/refinery29","followers_url":"https://api.github.com/users/refinery29/followers","following_url":"https://api.github.com/users/refinery29/following{/other_user}","gists_url":"https://api.github.com/users/refinery29/gists{/gist_id}","starred_url":"https://api.github.com/users/refinery29/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/refinery29/subscriptions","organizations_url":"https://api.github.com/users/refinery29/orgs","repos_url":"https://api.github.com/users/refinery29/repos","events_url":"https://api.github.com/users/refinery29/events{/privacy}","received_events_url":"https://api.github.com/users/refinery29/received_events","type":"Organization","site_admin":false},"repo":{"id":49174993,"name":"solr-annotations","full_name":"refinery29/solr-annotations","owner":{"login":"refinery29","id":821624,"avatar_url":"https://avatars.githubusercontent.com/u/821624?v=3","gravatar_id":"","url":"https://api.github.com/users/refinery29","html_url":"https://github.com/refinery29","followers_url":"https://api.github.com/users/refinery29/followers","following_url":"https://api.github.com/users/refinery29/following{/other_user}","gists_url":"https://api.github.com/users/refinery29/gists{/gist_id}","starred_url":"https://api.github.com/users/refinery29/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/refinery29/subscriptions","organizations_url":"https://api.github.com/users/refinery29/orgs","repos_url":"https://api.github.com/users/refinery29/repos","events_url":"https://api.github.com/users/refinery29/events{/privacy}","received_events_url":"https://api.github.com/users/refinery29/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/refinery29/solr-annotations","description":":sun_with_face: Annotations to power Solr Documents","fork":false,"url":"https://api.github.com/repos/refinery29/solr-annotations","forks_url":"https://api.github.com/repos/refinery29/solr-annotations/forks","keys_url":"https://api.github.com/repos/refinery29/solr-annotations/keys{/key_id}","collaborators_url":"https://api.github.com/repos/refinery29/solr-annotations/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/refinery29/solr-annotations/teams","hooks_url":"https://api.github.com/repos/refinery29/solr-annotations/hooks","issue_events_url":"https://api.github.com/repos/refinery29/solr-annotations/issues/events{/number}","events_url":"https://api.github.com/repos/refinery29/solr-annotations/events","assignees_url":"https://api.github.com/repos/refinery29/solr-annotations/assignees{/user}","branches_url":"https://api.github.com/repos/refinery29/solr-annotations/branches{/branch}","tags_url":"https://api.github.com/repos/refinery29/solr-annotations/tags","blobs_url":"https://api.github.com/repos/refinery29/solr-annotations/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/refinery29/solr-annotations/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/refinery29/solr-annotations/git/refs{/sha}","trees_url":"https://api.github.com/repos/refinery29/solr-annotations/git/trees{/sha}","statuses_url":"https://api.github.com/repos/refinery29/solr-annotations/statuses/{sha}","languages_url":"https://api.github.com/repos/refinery29/solr-annotations/languages","stargazers_url":"https://api.github.com/repos/refinery29/solr-annotations/stargazers","contributors_url":"https://api.github.com/repos/refinery29/solr-annotations/contributors","subscribers_url":"https://api.github.com/repos/refinery29/solr-annotations/subscribers","subscription_url":"https://api.github.com/repos/refinery29/solr-annotations/subscription","commits_url":"https://api.github.com/repos/refinery29/solr-annotations/commits{/sha}","git_commits_url":"https://api.github.com/repos/refinery29/solr-annotations/git/commits{/sha}","comments_url":"https://api.github.com/repos/refinery29/solr-annotations/comments{/number}","issue_comment_url":"https://api.github.com/repos/refinery29/solr-annotations/issues/comments{/number}","contents_url":"https://api.github.com/repos/refinery29/solr-annotations/contents/{+path}","compare_url":"https://api.github.com/repos/refinery29/solr-annotations/compare/{base}...{head}","merges_url":"https://api.github.com/repos/refinery29/solr-annotations/merges","archive_url":"https://api.github.com/repos/refinery29/solr-annotations/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/refinery29/solr-annotations/downloads","issues_url":"https://api.github.com/repos/refinery29/solr-annotations/issues{/number}","pulls_url":"https://api.github.com/repos/refinery29/solr-annotations/pulls{/number}","milestones_url":"https://api.github.com/repos/refinery29/solr-annotations/milestones{/number}","notifications_url":"https://api.github.com/repos/refinery29/solr-annotations/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/refinery29/solr-annotations/labels{/name}","releases_url":"https://api.github.com/repos/refinery29/solr-annotations/releases{/id}","created_at":"2016-01-07T02:15:31Z","updated_at":"2016-01-12T03:05:19Z","pushed_at":"2016-01-14T04:12:16Z","git_url":"git://github.com/refinery29/solr-annotations.git","ssh_url":"git@github.com:refinery29/solr-annotations.git","clone_url":"https://github.com/refinery29/solr-annotations.git","svn_url":"https://github.com/refinery29/solr-annotations","homepage":"","size":41,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"refinery29:master","ref":"master","sha":"9f95a37bc048c32d392127ce0bf69f4c1cd20b08","user":{"login":"refinery29","id":821624,"avatar_url":"https://avatars.githubusercontent.com/u/821624?v=3","gravatar_id":"","url":"https://api.github.com/users/refinery29","html_url":"https://github.com/refinery29","followers_url":"https://api.github.com/users/refinery29/followers","following_url":"https://api.github.com/users/refinery29/following{/other_user}","gists_url":"https://api.github.com/users/refinery29/gists{/gist_id}","starred_url":"https://api.github.com/users/refinery29/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/refinery29/subscriptions","organizations_url":"https://api.github.com/users/refinery29/orgs","repos_url":"https://api.github.com/users/refinery29/repos","events_url":"https://api.github.com/users/refinery29/events{/privacy}","received_events_url":"https://api.github.com/users/refinery29/received_events","type":"Organization","site_admin":false},"repo":{"id":49174993,"name":"solr-annotations","full_name":"refinery29/solr-annotations","owner":{"login":"refinery29","id":821624,"avatar_url":"https://avatars.githubusercontent.com/u/821624?v=3","gravatar_id":"","url":"https://api.github.com/users/refinery29","html_url":"https://github.com/refinery29","followers_url":"https://api.github.com/users/refinery29/followers","following_url":"https://api.github.com/users/refinery29/following{/other_user}","gists_url":"https://api.github.com/users/refinery29/gists{/gist_id}","starred_url":"https://api.github.com/users/refinery29/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/refinery29/subscriptions","organizations_url":"https://api.github.com/users/refinery29/orgs","repos_url":"https://api.github.com/users/refinery29/repos","events_url":"https://api.github.com/users/refinery29/events{/privacy}","received_events_url":"https://api.github.com/users/refinery29/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/refinery29/solr-annotations","description":":sun_with_face: Annotations to power Solr Documents","fork":false,"url":"https://api.github.com/repos/refinery29/solr-annotations","forks_url":"https://api.github.com/repos/refinery29/solr-annotations/forks","keys_url":"https://api.github.com/repos/refinery29/solr-annotations/keys{/key_id}","collaborators_url":"https://api.github.com/repos/refinery29/solr-annotations/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/refinery29/solr-annotations/teams","hooks_url":"https://api.github.com/repos/refinery29/solr-annotations/hooks","issue_events_url":"https://api.github.com/repos/refinery29/solr-annotations/issues/events{/number}","events_url":"https://api.github.com/repos/refinery29/solr-annotations/events","assignees_url":"https://api.github.com/repos/refinery29/solr-annotations/assignees{/user}","branches_url":"https://api.github.com/repos/refinery29/solr-annotations/branches{/branch}","tags_url":"https://api.github.com/repos/refinery29/solr-annotations/tags","blobs_url":"https://api.github.com/repos/refinery29/solr-annotations/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/refinery29/solr-annotations/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/refinery29/solr-annotations/git/refs{/sha}","trees_url":"https://api.github.com/repos/refinery29/solr-annotations/git/trees{/sha}","statuses_url":"https://api.github.com/repos/refinery29/solr-annotations/statuses/{sha}","languages_url":"https://api.github.com/repos/refinery29/solr-annotations/languages","stargazers_url":"https://api.github.com/repos/refinery29/solr-annotations/stargazers","contributors_url":"https://api.github.com/repos/refinery29/solr-annotations/contributors","subscribers_url":"https://api.github.com/repos/refinery29/solr-annotations/subscribers","subscription_url":"https://api.github.com/repos/refinery29/solr-annotations/subscription","commits_url":"https://api.github.com/repos/refinery29/solr-annotations/commits{/sha}","git_commits_url":"https://api.github.com/repos/refinery29/solr-annotations/git/commits{/sha}","comments_url":"https://api.github.com/repos/refinery29/solr-annotations/comments{/number}","issue_comment_url":"https://api.github.com/repos/refinery29/solr-annotations/issues/comments{/number}","contents_url":"https://api.github.com/repos/refinery29/solr-annotations/contents/{+path}","compare_url":"https://api.github.com/repos/refinery29/solr-annotations/compare/{base}...{head}","merges_url":"https://api.github.com/repos/refinery29/solr-annotations/merges","archive_url":"https://api.github.com/repos/refinery29/solr-annotations/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/refinery29/solr-annotations/downloads","issues_url":"https://api.github.com/repos/refinery29/solr-annotations/issues{/number}","pulls_url":"https://api.github.com/repos/refinery29/solr-annotations/pulls{/number}","milestones_url":"https://api.github.com/repos/refinery29/solr-annotations/milestones{/number}","notifications_url":"https://api.github.com/repos/refinery29/solr-annotations/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/refinery29/solr-annotations/labels{/name}","releases_url":"https://api.github.com/repos/refinery29/solr-annotations/releases{/id}","created_at":"2016-01-07T02:15:31Z","updated_at":"2016-01-12T03:05:19Z","pushed_at":"2016-01-14T04:12:16Z","git_url":"git://github.com/refinery29/solr-annotations.git","ssh_url":"git@github.com:refinery29/solr-annotations.git","clone_url":"https://github.com/refinery29/solr-annotations.git","svn_url":"https://github.com/refinery29/solr-annotations","homepage":"","size":41,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/refinery29/solr-annotations/pulls/16"},"html":{"href":"https://github.com/refinery29/solr-annotations/pull/16"},"issue":{"href":"https://api.github.com/repos/refinery29/solr-annotations/issues/16"},"comments":{"href":"https://api.github.com/repos/refinery29/solr-annotations/issues/16/comments"},"review_comments":{"href":"https://api.github.com/repos/refinery29/solr-annotations/pulls/16/comments"},"review_comment":{"href":"https://api.github.com/repos/refinery29/solr-annotations/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/refinery29/solr-annotations/pulls/16/commits"},"statuses":{"href":"https://api.github.com/repos/refinery29/solr-annotations/statuses/88e001e7f4c0571710d6a9df39781f1f63f4951d"}}}}