@@ -14,7 +14,7 @@ |
||
14 | 14 | if ($body === null) { |
15 | 15 | return ""; |
16 | 16 | } |
17 | - $short = strlen($body) - 1 < $maxLength ? $body : trim(substr($body, 0, $maxLength)). "..."; |
|
18 | - return strip_tags($short) ;; |
|
17 | + $short = strlen($body) - 1 < $maxLength ? $body : trim(substr($body, 0, $maxLength))."..."; |
|
18 | + return strip_tags($short); ; |
|
19 | 19 | } |
20 | 20 | } |
21 | 21 | \ No newline at end of file |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | */ |
39 | 39 | private function validatePostExists(Ulid $postId): void |
40 | 40 | { |
41 | - if(!$this->postHeadersFindingRepository->postExists($postId)) { |
|
41 | + if (!$this->postHeadersFindingRepository->postExists($postId)) { |
|
42 | 42 | throw new BadRequestHttpException("Requested Post doesn't exist"); |
43 | 43 | } |
44 | 44 | } |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | */ |
49 | 49 | private function validateCommentExists(Ulid $commentId): void |
50 | 50 | { |
51 | - if(!$this->commentsFindingRepository->commentExists($commentId)) { |
|
51 | + if (!$this->commentsFindingRepository->commentExists($commentId)) { |
|
52 | 52 | throw new BadRequestHttpException("Requested Parent Comment doesn't exist"); |
53 | 53 | } |
54 | 54 | } |
@@ -31,7 +31,7 @@ |
||
31 | 31 | public function findPostByTag(FindPostsByTagQuery $query): Page |
32 | 32 | { |
33 | 33 | $client = $this->getClient(); |
34 | - $client->request('GET', '/api/tags/' . $query->getTag()); |
|
34 | + $client->request('GET', '/api/tags/'.$query->getTag()); |
|
35 | 35 | return $this->responseObject($client, Page::class); |
36 | 36 | } |
37 | 37 |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | { |
66 | 66 | self::$posts = Collection::from( |
67 | 67 | self::$posts |
68 | - ->filter(function ($post) use ($dto) { |
|
68 | + ->filter(function($post) use ($dto) { |
|
69 | 69 | return $post->getId() != $dto->getId(); |
70 | 70 | }) |
71 | 71 | ->toArray() |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | public function updatePost(UpdateExistingPostDto $dto): void |
76 | 76 | { |
77 | 77 | foreach (self::$posts |
78 | - ->filter(function ($post) use ($dto) { |
|
78 | + ->filter(function($post) use ($dto) { |
|
79 | 79 | return $post->getId() == $dto->getId(); |
80 | 80 | }) |
81 | 81 | ->toArray() as $post) { |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | |
91 | 91 | public function findPost(Ulid $id): ?PostDto |
92 | 92 | { |
93 | - $found = self::$posts->find(function ($post) use ($id) { |
|
93 | + $found = self::$posts->find(function($post) use ($id) { |
|
94 | 94 | return $post->getId() == $id; |
95 | 95 | }); |
96 | 96 | return $found == null ? null : new PostDto( |
@@ -130,13 +130,13 @@ discard block |
||
130 | 130 | |
131 | 131 | public function updateAllComments(UpdatePostCommentsDto $updatedComments, bool $append = true): void |
132 | 132 | { |
133 | - $post = self::$posts->find(function ($post) use ($updatedComments) { |
|
133 | + $post = self::$posts->find(function($post) use ($updatedComments) { |
|
134 | 134 | return $post->getId() == $updatedComments->getPostId(); |
135 | 135 | }); |
136 | 136 | if ($post == null) { |
137 | 137 | throw new \RuntimeException("Unable to Find Post For Comment"); |
138 | 138 | } |
139 | - if($append) { |
|
139 | + if ($append) { |
|
140 | 140 | $data = $post->getComments(); |
141 | 141 | foreach ($updatedComments->getComments() as $newComment) { |
142 | 142 | array_push($data, $newComment); |
@@ -163,10 +163,10 @@ discard block |
||
163 | 163 | public function updateUserName(UpdatedPostsUserNameDto $updatedUserName): void |
164 | 164 | { |
165 | 165 | self::$posts |
166 | - ->filter(function ($post) use ($updatedUserName) { |
|
166 | + ->filter(function($post) use ($updatedUserName) { |
|
167 | 167 | return $post->getCreatedByName() == $updatedUserName->getOldUserName(); |
168 | 168 | }) |
169 | - ->each(function ($post) use ($updatedUserName) { |
|
169 | + ->each(function($post) use ($updatedUserName) { |
|
170 | 170 | $post->setCreatedByName($updatedUserName->getNewUserName()); |
171 | 171 | }) |
172 | 172 | ->realize(); |
@@ -26,25 +26,25 @@ |
||
26 | 26 | |
27 | 27 | public function updatePost(UpdatePostCommand $command): void |
28 | 28 | { |
29 | - $this->getClient()->request('PUT', '/api/admin/posts/' . $command->getId(), [], [], [], $this->json($command)); |
|
29 | + $this->getClient()->request('PUT', '/api/admin/posts/'.$command->getId(), [], [], [], $this->json($command)); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | public function deletePost(DeletePostCommand $command): void |
33 | 33 | { |
34 | - $this->getClient()->request('DELETE', '/api/admin/posts/' . $command->getId()); |
|
34 | + $this->getClient()->request('DELETE', '/api/admin/posts/'.$command->getId()); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | public function findAllPosts(FindAllPostsQuery $query): Page |
38 | 38 | { |
39 | 39 | $client = $this->getClient(); |
40 | - $client->request('GET', '/api/posts/?pageNo=' . $query->getPageNo()); |
|
40 | + $client->request('GET', '/api/posts/?pageNo='.$query->getPageNo()); |
|
41 | 41 | return $this->responseObject($client, Page::class); |
42 | 42 | } |
43 | 43 | |
44 | 44 | public function findPostById(FindPostByIdQuery $query): FindPostQueryResponse |
45 | 45 | { |
46 | 46 | $client = $this->getClient(); |
47 | - $client->request('GET', '/api/posts/' . $query->getId()); |
|
47 | + $client->request('GET', '/api/posts/'.$query->getId()); |
|
48 | 48 | return $this->responseObject($client, FindPostQueryResponse::class); |
49 | 49 | } |
50 | 50 |
@@ -20,7 +20,7 @@ |
||
20 | 20 | public function findPostsByUserId(FindPostsByUserIdQuery $query): Page |
21 | 21 | { |
22 | 22 | $client = $this->getClient(); |
23 | - $client->request('GET', '/api/security/' . $query->getUserId()); |
|
23 | + $client->request('GET', '/api/security/'.$query->getUserId()); |
|
24 | 24 | return $this->responseObject($client, Page::class); |
25 | 25 | } |
26 | 26 |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | public function findLatestComments(FindLatestCommentsQuery $query): Page |
30 | 30 | { |
31 | 31 | $client = $this->getClient(); |
32 | - $client->request('GET', '/api/comments/?pageNo=' . $query->getPageNo()); |
|
32 | + $client->request('GET', '/api/comments/?pageNo='.$query->getPageNo()); |
|
33 | 33 | return $this->responseObject($client, Page::class); |
34 | 34 | } |
35 | 35 | |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | public function findCommentsForPost(FindCommentsByPostIdQuery $query): array |
41 | 41 | { |
42 | 42 | $client = $this->getClient(); |
43 | - $client->request('GET', '/api/comments/' . $query->getPostId()); |
|
43 | + $client->request('GET', '/api/comments/'.$query->getPostId()); |
|
44 | 44 | return $this->responseObjects($client, FindCommentsByPostIdQueryResponse::class); |
45 | 45 | } |
46 | 46 |
@@ -31,7 +31,7 @@ |
||
31 | 31 | |
32 | 32 | protected function getContractsPath(): string |
33 | 33 | { |
34 | - return dirname(__FILE__) . '/../../../contracts'; |
|
34 | + return dirname(__FILE__).'/../../../contracts'; |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | public static abstract function fail(string $message); |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | public function updatePostHeader(UpdateExistingCommentsPostHeaderDto $updatedPostHeader): void |
56 | 56 | { |
57 | 57 | foreach (self::$postHeaders |
58 | - ->filter(function ($header) use ($updatedPostHeader) { |
|
58 | + ->filter(function($header) use ($updatedPostHeader) { |
|
59 | 59 | return $header->getId() == $updatedPostHeader->getId() && $header->getVersion() <= $updatedPostHeader->getVersion(); |
60 | 60 | }) |
61 | 61 | ->toArray() as $header) { |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | public function deletePostHeader(DeleteExistingCommentsPostHeaderDto $deletedPostHeader): void |
69 | 69 | { |
70 | 70 | self::$postHeaders = self::$postHeaders->filter( |
71 | - function ($header) use ($deletedPostHeader) { |
|
71 | + function($header) use ($deletedPostHeader) { |
|
72 | 72 | return $header->getId() != $deletedPostHeader->getId(); |
73 | 73 | } |
74 | 74 | )->realize(); |
@@ -77,10 +77,10 @@ discard block |
||
77 | 77 | public function findPostHeaders(?\DateTime $from = null): array |
78 | 78 | { |
79 | 79 | return self::$postHeaders |
80 | - ->filter(function ($header) use ($from) { |
|
80 | + ->filter(function($header) use ($from) { |
|
81 | 81 | return $from == null || $header->getCreatedAt() >= $from; |
82 | 82 | }) |
83 | - ->map(function ($header) { |
|
83 | + ->map(function($header) { |
|
84 | 84 | return new CommentsPostHeaderDto( |
85 | 85 | $header->getId(), |
86 | 86 | $header->getTitle(), |
@@ -96,11 +96,11 @@ discard block |
||
96 | 96 | $id = new Ulid(); |
97 | 97 | $parentComment = null; |
98 | 98 | if ($newComment->getParentId() != null) { |
99 | - $parentComment = self::$comments->find(function ($comment) use ($newComment) { |
|
99 | + $parentComment = self::$comments->find(function($comment) use ($newComment) { |
|
100 | 100 | return $comment->getId() == $newComment->getParentId(); |
101 | 101 | }); |
102 | 102 | } |
103 | - $post = self::$postHeaders->find(function ($post) use ($newComment) { |
|
103 | + $post = self::$postHeaders->find(function($post) use ($newComment) { |
|
104 | 104 | return $post->getId() == $newComment->getPostId(); |
105 | 105 | }); |
106 | 106 | $comment = new InMemoryComment( |
@@ -121,10 +121,10 @@ discard block |
||
121 | 121 | public function getCommentsCount(Ulid $postId): int |
122 | 122 | { |
123 | 123 | return self::$postHeaders |
124 | - ->filter(function ($post) use ($postId) { |
|
124 | + ->filter(function($post) use ($postId) { |
|
125 | 125 | return $post->getId() == $postId; |
126 | 126 | }) |
127 | - ->map(function ($post) { |
|
127 | + ->map(function($post) { |
|
128 | 128 | return count($post->getComments()); |
129 | 129 | }) |
130 | 130 | ->first(); |
@@ -133,14 +133,14 @@ discard block |
||
133 | 133 | public function findCommentsByPostId(Ulid $postId): array |
134 | 134 | { |
135 | 135 | $post = self::$postHeaders |
136 | - ->find(function ($post) use ($postId) { |
|
136 | + ->find(function($post) use ($postId) { |
|
137 | 137 | return $post->getId() == $postId; |
138 | 138 | }); |
139 | 139 | if ($post == null) { |
140 | 140 | return []; |
141 | 141 | } |
142 | 142 | return Collection::from($post->getComments()) |
143 | - ->map(function ($comment) { |
|
143 | + ->map(function($comment) { |
|
144 | 144 | $parentId = $comment->getParentComment() != null ? $comment->getParentComment()->getId() : null; |
145 | 145 | return new CommentDto( |
146 | 146 | $comment->getId(), |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | $from = ($pageNo - 1) * self::PAGE_SIZE; |
158 | 158 | $to = $from + self::PAGE_SIZE; |
159 | 159 | $data = self::$comments |
160 | - ->map(function ($comment) { |
|
160 | + ->map(function($comment) { |
|
161 | 161 | $parentId = $comment->getParentComment() != null ? $comment->getParentComment()->getId() : null; |
162 | 162 | return new CommentWithPostDto( |
163 | 163 | $comment->getId(), |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | |
172 | 172 | ); |
173 | 173 | }) |
174 | - ->sort(function ($c1, $c2) { |
|
174 | + ->sort(function($c1, $c2) { |
|
175 | 175 | return $c1->getCreatedAt() < $c2->getCreatedAt() ? 1 : -1; |
176 | 176 | }) |
177 | 177 | ->slice($from, $to) |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | public function commentExists(Ulid $commentId): bool |
183 | 183 | { |
184 | 184 | return self::$comments |
185 | - ->filter(function ($comment) use ($commentId) { |
|
185 | + ->filter(function($comment) use ($commentId) { |
|
186 | 186 | return $comment->getId() == $commentId; |
187 | 187 | })->sizeIsGreaterThan(0); |
188 | 188 | } |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | public function postExists(Ulid $postId): bool |
191 | 191 | { |
192 | 192 | return self::$postHeaders |
193 | - ->filter(function ($post) use ($postId) { |
|
193 | + ->filter(function($post) use ($postId) { |
|
194 | 194 | return $post->getId() == $postId; |
195 | 195 | })->sizeIsGreaterThan(0); |
196 | 196 | } |
@@ -198,11 +198,11 @@ discard block |
||
198 | 198 | public function deleteCommentsForPost(Ulid $postId) |
199 | 199 | { |
200 | 200 | self::$comments = self::$comments |
201 | - ->filter(function ($comment) use ($postId) { |
|
201 | + ->filter(function($comment) use ($postId) { |
|
202 | 202 | return $comment->getPost()->getId() != $postId; |
203 | 203 | }) |
204 | 204 | ->realize(); |
205 | - $post = self::$postHeaders->find(function ($post) use ($postId) { |
|
205 | + $post = self::$postHeaders->find(function($post) use ($postId) { |
|
206 | 206 | $post->getId() == $postId; |
207 | 207 | }); |
208 | 208 | if ($post != null) { |