@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | self::$tags = Collection::from([]); |
46 | 46 | } |
47 | 47 | |
48 | - public function createPostHeader(CreateNewTagsPostHeaderDto $newPostHeader): void |
|
48 | + public function createPostHeader(CreateNewTagsPostHeaderDto $newPostHeader): void |
|
49 | 49 | { |
50 | 50 | self::$postHeaders = self::$postHeaders->append(new InMemoryTagPostHeader( |
51 | 51 | $newPostHeader->getId(), |
@@ -59,29 +59,29 @@ discard block |
||
59 | 59 | )); |
60 | 60 | } |
61 | 61 | |
62 | - public function updatePostHeader(UpdateExistingTagsPostHeaderDto $updatedPostHeader): void |
|
62 | + public function updatePostHeader(UpdateExistingTagsPostHeaderDto $updatedPostHeader): void |
|
63 | 63 | { |
64 | 64 | foreach (self::$postHeaders |
65 | - ->filter(function ($header) use ($updatedPostHeader) { |
|
66 | - return $header->getId() == $updatedPostHeader->getId() && $header->getVersion() <= $updatedPostHeader->getVersion(); |
|
67 | - }) |
|
68 | - ->toArray() as $header) { |
|
65 | + ->filter(function ($header) use ($updatedPostHeader) { |
|
66 | + return $header->getId() == $updatedPostHeader->getId() && $header->getVersion() <= $updatedPostHeader->getVersion(); |
|
67 | + }) |
|
68 | + ->toArray() as $header) { |
|
69 | 69 | $header->setTitle($updatedPostHeader->getTitle()); |
70 | 70 | $header->setSummary($updatedPostHeader->getSummary()); |
71 | 71 | $header->setVersion($updatedPostHeader->getVersion()); |
72 | 72 | } |
73 | 73 | } |
74 | 74 | |
75 | - public function deletePostHeader(DeleteExistingTagsPostHeaderDto $deletedPostHeader): void |
|
75 | + public function deletePostHeader(DeleteExistingTagsPostHeaderDto $deletedPostHeader): void |
|
76 | 76 | { |
77 | 77 | self::$postHeaders = self::$postHeaders->filter( |
78 | - function ($header) use ($deletedPostHeader) { |
|
78 | + function ($header) use ($deletedPostHeader) { |
|
79 | 79 | return $header->getId() != $deletedPostHeader->getId(); |
80 | 80 | } |
81 | 81 | )->realize(); |
82 | 82 | } |
83 | 83 | |
84 | - public function findPostHeaders(): array |
|
84 | + public function findPostHeaders(): array |
|
85 | 85 | { |
86 | 86 | return self::$postHeaders |
87 | 87 | ->map(function ($header) { |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | public function updatePostHeader(UpdateExistingTagsPostHeaderDto $updatedPostHeader): void |
63 | 63 | { |
64 | 64 | foreach (self::$postHeaders |
65 | - ->filter(function ($header) use ($updatedPostHeader) { |
|
65 | + ->filter(function($header) use ($updatedPostHeader) { |
|
66 | 66 | return $header->getId() == $updatedPostHeader->getId() && $header->getVersion() <= $updatedPostHeader->getVersion(); |
67 | 67 | }) |
68 | 68 | ->toArray() as $header) { |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | public function deletePostHeader(DeleteExistingTagsPostHeaderDto $deletedPostHeader): void |
76 | 76 | { |
77 | 77 | self::$postHeaders = self::$postHeaders->filter( |
78 | - function ($header) use ($deletedPostHeader) { |
|
78 | + function($header) use ($deletedPostHeader) { |
|
79 | 79 | return $header->getId() != $deletedPostHeader->getId(); |
80 | 80 | } |
81 | 81 | )->realize(); |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | public function findPostHeaders(): array |
85 | 85 | { |
86 | 86 | return self::$postHeaders |
87 | - ->map(function ($header) { |
|
87 | + ->map(function($header) { |
|
88 | 88 | return new TagsPostHeaderDto( |
89 | 89 | $header->getId(), |
90 | 90 | $header->getTitle(), |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | $header->getVersion(), |
96 | 96 | $header->getCommentsCount(), |
97 | 97 | Collection::from($header->getTags()) |
98 | - ->map(function ($tag) { |
|
98 | + ->map(function($tag) { |
|
99 | 99 | return $tag->getTag(); |
100 | 100 | }) |
101 | 101 | ->toArray() |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | { |
109 | 109 | $usedTagIds = $this->findUsedTagIds(); |
110 | 110 | self::$tags = self::$tags |
111 | - ->filter(function ($tag) use ($usedTagIds) { |
|
111 | + ->filter(function($tag) use ($usedTagIds) { |
|
112 | 112 | return $usedTagIds->contains($tag->getTag()); |
113 | 113 | })->realize(); |
114 | 114 | } |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | private function findUsedTagIds(): ArrayCollection |
117 | 117 | { |
118 | 118 | $usedTags = new ArrayCollection(); |
119 | - self::$postHeaders->each(function ($post) use ($usedTags) { |
|
119 | + self::$postHeaders->each(function($post) use ($usedTags) { |
|
120 | 120 | foreach ($post->getTags() as $tag) { |
121 | 121 | $usedTags->add($tag->getTag()); |
122 | 122 | } |
@@ -126,14 +126,14 @@ discard block |
||
126 | 126 | |
127 | 127 | public function addPostToTag(string $tag, Ulid $postId): void |
128 | 128 | { |
129 | - $tagObj = self::$tags->find(function ($tagObj) use ($tag) { |
|
129 | + $tagObj = self::$tags->find(function($tagObj) use ($tag) { |
|
130 | 130 | return $tagObj->getTag() == $tag; |
131 | 131 | }); |
132 | 132 | if ($tagObj == null) { |
133 | 133 | $tagObj = new InMemoryTag(new Ulid(), $tag); |
134 | 134 | self::$tags = self::$tags->append($tagObj); |
135 | 135 | } |
136 | - $post = self::$postHeaders->find(function ($post) use ($postId) { |
|
136 | + $post = self::$postHeaders->find(function($post) use ($postId) { |
|
137 | 137 | return $post->getId() == $postId; |
138 | 138 | }); |
139 | 139 | if ($post != null) { |
@@ -141,15 +141,15 @@ discard block |
||
141 | 141 | array_push($tags, $tagObj); |
142 | 142 | $post->setTags($tags); |
143 | 143 | } else { |
144 | - throw new \RuntimeException("No Post Header: " . $postId); |
|
144 | + throw new \RuntimeException("No Post Header: ".$postId); |
|
145 | 145 | } |
146 | 146 | } |
147 | 147 | |
148 | 148 | public function findTags(): array |
149 | 149 | { |
150 | - return array_values(self::$tags->map(function ($tag) { |
|
150 | + return array_values(self::$tags->map(function($tag) { |
|
151 | 151 | return new TagDto($tag->getTag(), $this->countPosts($tag)); |
152 | - })->sort(function ($tag1, $tag2) { |
|
152 | + })->sort(function($tag1, $tag2) { |
|
153 | 153 | return $tag1->getPostsCount() > $tag2->getPostsCount(); |
154 | 154 | })->toArray()); |
155 | 155 | } |
@@ -159,23 +159,23 @@ discard block |
||
159 | 159 | $from = ($pageNo - 1) * self::PAGE_SIZE; |
160 | 160 | $to = $from + self::PAGE_SIZE; |
161 | 161 | $size = self::$postHeaders |
162 | - ->filter(function ($post) use ($tag) { |
|
162 | + ->filter(function($post) use ($tag) { |
|
163 | 163 | return Collection::from($post->getTags()) |
164 | - ->filter(function ($postTag) use ($tag) { |
|
164 | + ->filter(function($postTag) use ($tag) { |
|
165 | 165 | return $postTag->getTag() == $tag->getTag(); |
166 | 166 | }) |
167 | 167 | ->size() > 0; |
168 | 168 | })->size(); |
169 | 169 | $data = array_values(self::$postHeaders |
170 | - ->filter(function ($post) use ($tag) { |
|
170 | + ->filter(function($post) use ($tag) { |
|
171 | 171 | return Collection::from($post->getTags()) |
172 | - ->filter(function ($postTag) use ($tag) { |
|
172 | + ->filter(function($postTag) use ($tag) { |
|
173 | 173 | return $postTag->getTag() == $tag->getTag(); |
174 | 174 | }) |
175 | 175 | ->size() > 0; |
176 | 176 | }) |
177 | 177 | ->slice($from, $to) |
178 | - ->map(function ($header) { |
|
178 | + ->map(function($header) { |
|
179 | 179 | return new TagsPostHeaderDto( |
180 | 180 | $header->getId(), |
181 | 181 | $header->getTitle(), |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | $header->getVersion(), |
187 | 187 | $header->getCommentsCount(), |
188 | 188 | Collection::from($header->getTags()) |
189 | - ->map(function ($tag) { |
|
189 | + ->map(function($tag) { |
|
190 | 190 | return $tag->getTag(); |
191 | 191 | }) |
192 | 192 | ->toArray() |
@@ -199,9 +199,9 @@ discard block |
||
199 | 199 | private function countPosts(InMemoryTag $tag): int |
200 | 200 | { |
201 | 201 | return self::$postHeaders |
202 | - ->filter(function ($post) use ($tag) { |
|
202 | + ->filter(function($post) use ($tag) { |
|
203 | 203 | return Collection::from($post->getTags()) |
204 | - ->filter(function ($postTag) use ($tag) { |
|
204 | + ->filter(function($postTag) use ($tag) { |
|
205 | 205 | return $postTag->getTag() == $tag->getTag(); |
206 | 206 | }) |
207 | 207 | ->size() > 0; |
@@ -212,10 +212,10 @@ discard block |
||
212 | 212 | public function removePostFromTags(Ulid $postId): void |
213 | 213 | { |
214 | 214 | self::$postHeaders |
215 | - ->filter(function ($post) use ($postId) { |
|
215 | + ->filter(function($post) use ($postId) { |
|
216 | 216 | return $post->getId() == $postId; |
217 | 217 | }) |
218 | - ->each(function ($post) { |
|
218 | + ->each(function($post) { |
|
219 | 219 | $post->setTags([]); |
220 | 220 | })->realize(); |
221 | 221 | } |
@@ -223,10 +223,10 @@ discard block |
||
223 | 223 | public function updatePostCommentsCount(UpdatePostsCommentsCountDto $commentsCount): void |
224 | 224 | { |
225 | 225 | self::$postHeaders |
226 | - ->filter(function ($header) use ($commentsCount) { |
|
226 | + ->filter(function($header) use ($commentsCount) { |
|
227 | 227 | return $header->getId() == $commentsCount->getPostId(); |
228 | 228 | }) |
229 | - ->each(function ($header) use ($commentsCount) { |
|
229 | + ->each(function($header) use ($commentsCount) { |
|
230 | 230 | $header->setCommentsCount($commentsCount->getCommentsCount()); |
231 | 231 | }) |
232 | 232 | ->realize(); |
@@ -235,10 +235,10 @@ discard block |
||
235 | 235 | public function updateUserName(UpdatedTagsPostHeadersUserNameDto $updatedUserName): void |
236 | 236 | { |
237 | 237 | self::$postHeaders |
238 | - ->filter(function ($post) use ($updatedUserName) { |
|
238 | + ->filter(function($post) use ($updatedUserName) { |
|
239 | 239 | return $post->getCreatedByName() == $updatedUserName->getOldUserName(); |
240 | 240 | }) |
241 | - ->each(function ($post) use ($updatedUserName) { |
|
241 | + ->each(function($post) use ($updatedUserName) { |
|
242 | 242 | $post->setCreatedByName($updatedUserName->getNewUserName()); |
243 | 243 | }) |
244 | 244 | ->realize(); |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | } |
42 | 42 | |
43 | 43 | |
44 | - public function createPost(CreateNewPostDto $newPost): Ulid |
|
44 | + public function createPost(CreateNewPostDto $newPost): Ulid |
|
45 | 45 | { |
46 | 46 | $id = new Ulid(); |
47 | 47 | self::$posts = self::$posts->append( |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | return $id; |
62 | 62 | } |
63 | 63 | |
64 | - public function deletePost(DeleteExistingPostDto $dto): void |
|
64 | + public function deletePost(DeleteExistingPostDto $dto): void |
|
65 | 65 | { |
66 | 66 | self::$posts = Collection::from( |
67 | 67 | self::$posts |
@@ -72,13 +72,13 @@ discard block |
||
72 | 72 | ); |
73 | 73 | } |
74 | 74 | |
75 | - public function updatePost(UpdateExistingPostDto $dto): void |
|
75 | + public function updatePost(UpdateExistingPostDto $dto): void |
|
76 | 76 | { |
77 | 77 | foreach (self::$posts |
78 | - ->filter(function ($post) use ($dto) { |
|
79 | - return $post->getId() == $dto->getId(); |
|
80 | - }) |
|
81 | - ->toArray() as $post) { |
|
78 | + ->filter(function ($post) use ($dto) { |
|
79 | + return $post->getId() == $dto->getId(); |
|
80 | + }) |
|
81 | + ->toArray() as $post) { |
|
82 | 82 | $post->setTitle($dto->getTitle()); |
83 | 83 | $post->setBody($dto->getBody()); |
84 | 84 | $post->setSummary($dto->getSummary()); |
@@ -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(); |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | ]); |
46 | 46 | } |
47 | 47 | |
48 | - public function createPostHeader(CreateNewUserPostHeaderDto $newPostHeader): void |
|
48 | + public function createPostHeader(CreateNewUserPostHeaderDto $newPostHeader): void |
|
49 | 49 | { |
50 | 50 | self::$postHeaders = self::$postHeaders->append(new InMemoryUserPostHeader( |
51 | 51 | $newPostHeader->getId(), |
@@ -59,13 +59,13 @@ discard block |
||
59 | 59 | )); |
60 | 60 | } |
61 | 61 | |
62 | - public function updatePostHeader(UpdateExistingUserPostHeaderDto $updatedPostHeader): void |
|
62 | + public function updatePostHeader(UpdateExistingUserPostHeaderDto $updatedPostHeader): void |
|
63 | 63 | { |
64 | 64 | foreach (self::$postHeaders |
65 | - ->filter(function ($header) use ($updatedPostHeader) { |
|
66 | - return $header->getId() == $updatedPostHeader->getId() && $header->getVersion() <= $updatedPostHeader->getVersion(); |
|
67 | - }) |
|
68 | - ->toArray() as $header) { |
|
65 | + ->filter(function ($header) use ($updatedPostHeader) { |
|
66 | + return $header->getId() == $updatedPostHeader->getId() && $header->getVersion() <= $updatedPostHeader->getVersion(); |
|
67 | + }) |
|
68 | + ->toArray() as $header) { |
|
69 | 69 | $header->setTitle($updatedPostHeader->getTitle()); |
70 | 70 | $header->setSummary($updatedPostHeader->getSummary()); |
71 | 71 | $header->setTags($updatedPostHeader->getTags()); |
@@ -73,16 +73,16 @@ discard block |
||
73 | 73 | } |
74 | 74 | } |
75 | 75 | |
76 | - public function deletePostHeader(DeleteExistingUserPostHeaderDto $deletedPostHeader): void |
|
76 | + public function deletePostHeader(DeleteExistingUserPostHeaderDto $deletedPostHeader): void |
|
77 | 77 | { |
78 | 78 | self::$postHeaders = self::$postHeaders->filter( |
79 | - function ($header) use ($deletedPostHeader) { |
|
79 | + function ($header) use ($deletedPostHeader) { |
|
80 | 80 | return $header->getId() != $deletedPostHeader->getId(); |
81 | 81 | } |
82 | 82 | )->realize(); |
83 | 83 | } |
84 | 84 | |
85 | - public function findPostHeaders(): array |
|
85 | + public function findPostHeaders(): array |
|
86 | 86 | { |
87 | 87 | return self::$postHeaders |
88 | 88 | ->map(function ($header) { |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | ->toArray(); |
102 | 102 | } |
103 | 103 | |
104 | - public function createUser(CreateNewUserDto $newUser): Ulid |
|
104 | + public function createUser(CreateNewUserDto $newUser): Ulid |
|
105 | 105 | { |
106 | 106 | $id = new Ulid(); |
107 | 107 | self::$users = self::$users->append(new InMemoryUser($id, $newUser->getLogin(), $newUser->getRoles(), 1)); |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | public function updatePostHeader(UpdateExistingUserPostHeaderDto $updatedPostHeader): void |
63 | 63 | { |
64 | 64 | foreach (self::$postHeaders |
65 | - ->filter(function ($header) use ($updatedPostHeader) { |
|
65 | + ->filter(function($header) use ($updatedPostHeader) { |
|
66 | 66 | return $header->getId() == $updatedPostHeader->getId() && $header->getVersion() <= $updatedPostHeader->getVersion(); |
67 | 67 | }) |
68 | 68 | ->toArray() as $header) { |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | public function deletePostHeader(DeleteExistingUserPostHeaderDto $deletedPostHeader): void |
77 | 77 | { |
78 | 78 | self::$postHeaders = self::$postHeaders->filter( |
79 | - function ($header) use ($deletedPostHeader) { |
|
79 | + function($header) use ($deletedPostHeader) { |
|
80 | 80 | return $header->getId() != $deletedPostHeader->getId(); |
81 | 81 | } |
82 | 82 | )->realize(); |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | public function findPostHeaders(): array |
86 | 86 | { |
87 | 87 | return self::$postHeaders |
88 | - ->map(function ($header) { |
|
88 | + ->map(function($header) { |
|
89 | 89 | return new UserPostHeaderDto( |
90 | 90 | $header->getId(), |
91 | 91 | $header->getTitle(), |
@@ -113,15 +113,15 @@ discard block |
||
113 | 113 | $from = ($pageNo - 1) * self::PAGE_SIZE; |
114 | 114 | $to = $from + self::PAGE_SIZE; |
115 | 115 | $size = self::$postHeaders |
116 | - ->filter(function ($header) use ($userId) { |
|
116 | + ->filter(function($header) use ($userId) { |
|
117 | 117 | return $header->getUser()->getId() == $userId; |
118 | 118 | })->size(); |
119 | 119 | $data = self::$postHeaders |
120 | - ->filter(function ($header) use ($userId) { |
|
120 | + ->filter(function($header) use ($userId) { |
|
121 | 121 | return $header->getUser()->getId() == $userId; |
122 | 122 | }) |
123 | 123 | ->slice($from, $to) |
124 | - ->map(function ($header) { |
|
124 | + ->map(function($header) { |
|
125 | 125 | return new UserPostHeaderDto( |
126 | 126 | $header->getId(), |
127 | 127 | $header->getTitle(), |
@@ -141,10 +141,10 @@ discard block |
||
141 | 141 | public function updatePostCommentsCount(UpdatePostsCommentsCountDto $commentsCount): void |
142 | 142 | { |
143 | 143 | self::$postHeaders |
144 | - ->filter(function ($header) use ($commentsCount) { |
|
144 | + ->filter(function($header) use ($commentsCount) { |
|
145 | 145 | return $header->getId() == $commentsCount->getPostId(); |
146 | 146 | }) |
147 | - ->each(function ($header) use ($commentsCount) { |
|
147 | + ->each(function($header) use ($commentsCount) { |
|
148 | 148 | $header->setCommentsCount($commentsCount->getCommentsCount()); |
149 | 149 | }) |
150 | 150 | ->realize(); |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | public function exists(string $login): bool |
154 | 154 | { |
155 | 155 | return self::$users |
156 | - ->filter(function ($user) use ($login) { |
|
156 | + ->filter(function($user) use ($login) { |
|
157 | 157 | return $user->getEmail() == $login; |
158 | 158 | }) |
159 | 159 | ->sizeIsGreaterThan(0); |
@@ -162,10 +162,10 @@ discard block |
||
162 | 162 | public function renameUser(RenameExistingUserDto $renamedUser): void |
163 | 163 | { |
164 | 164 | self::$users |
165 | - ->filter(function ($user) use ($renamedUser) { |
|
165 | + ->filter(function($user) use ($renamedUser) { |
|
166 | 166 | return $user->getEmail() == $renamedUser->getCurrentLogin(); |
167 | 167 | }) |
168 | - ->each(function ($user) use ($renamedUser) { |
|
168 | + ->each(function($user) use ($renamedUser) { |
|
169 | 169 | $user->setEmail($renamedUser->getNewLogin()); |
170 | 170 | }); |
171 | 171 | } |
@@ -60,10 +60,10 @@ discard block |
||
60 | 60 | public function updatePostHeader(UpdateExistingCommentsPostHeaderDto $updatedPostHeader): void |
61 | 61 | { |
62 | 62 | foreach (self::$postHeaders |
63 | - ->filter(function ($header) use ($updatedPostHeader) { |
|
64 | - return $header->getId() == $updatedPostHeader->getId() && $header->getVersion() <= $updatedPostHeader->getVersion(); |
|
65 | - }) |
|
66 | - ->toArray() as $header) { |
|
63 | + ->filter(function ($header) use ($updatedPostHeader) { |
|
64 | + return $header->getId() == $updatedPostHeader->getId() && $header->getVersion() <= $updatedPostHeader->getVersion(); |
|
65 | + }) |
|
66 | + ->toArray() as $header) { |
|
67 | 67 | $header->setTitle($updatedPostHeader->getTitle()); |
68 | 68 | $header->setSummary($updatedPostHeader->getSummary()); |
69 | 69 | $header->setTags($updatedPostHeader->getTags()); |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | public function deletePostHeader(DeleteExistingCommentsPostHeaderDto $deletedPostHeader): void |
75 | 75 | { |
76 | 76 | self::$postHeaders = self::$postHeaders->filter( |
77 | - function ($header) use ($deletedPostHeader) { |
|
77 | + function ($header) use ($deletedPostHeader) { |
|
78 | 78 | return $header->getId() != $deletedPostHeader->getId(); |
79 | 79 | } |
80 | 80 | )->realize(); |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | public function updatePostHeader(UpdateExistingCommentsPostHeaderDto $updatedPostHeader): void |
61 | 61 | { |
62 | 62 | foreach (self::$postHeaders |
63 | - ->filter(function ($header) use ($updatedPostHeader) { |
|
63 | + ->filter(function($header) use ($updatedPostHeader) { |
|
64 | 64 | return $header->getId() == $updatedPostHeader->getId() && $header->getVersion() <= $updatedPostHeader->getVersion(); |
65 | 65 | }) |
66 | 66 | ->toArray() as $header) { |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | public function deletePostHeader(DeleteExistingCommentsPostHeaderDto $deletedPostHeader): void |
75 | 75 | { |
76 | 76 | self::$postHeaders = self::$postHeaders->filter( |
77 | - function ($header) use ($deletedPostHeader) { |
|
77 | + function($header) use ($deletedPostHeader) { |
|
78 | 78 | return $header->getId() != $deletedPostHeader->getId(); |
79 | 79 | } |
80 | 80 | )->realize(); |
@@ -83,10 +83,10 @@ discard block |
||
83 | 83 | public function findPostHeaders(?\DateTime $from = null): array |
84 | 84 | { |
85 | 85 | return self::$postHeaders |
86 | - ->filter(function ($header) use ($from) { |
|
86 | + ->filter(function($header) use ($from) { |
|
87 | 87 | return $from == null || $header->getCreatedAt() >= $from; |
88 | 88 | }) |
89 | - ->map(function ($header) { |
|
89 | + ->map(function($header) { |
|
90 | 90 | return new CommentsPostHeaderDto( |
91 | 91 | $header->getId(), |
92 | 92 | $header->getTitle(), |
@@ -106,11 +106,11 @@ discard block |
||
106 | 106 | $id = new Ulid(); |
107 | 107 | $parentComment = null; |
108 | 108 | if ($newComment->getParentId() != null) { |
109 | - $parentComment = self::$comments->find(function ($comment) use ($newComment) { |
|
109 | + $parentComment = self::$comments->find(function($comment) use ($newComment) { |
|
110 | 110 | return $comment->getId() == $newComment->getParentId(); |
111 | 111 | }); |
112 | 112 | } |
113 | - $post = self::$postHeaders->find(function ($post) use ($newComment) { |
|
113 | + $post = self::$postHeaders->find(function($post) use ($newComment) { |
|
114 | 114 | return $post->getId() == $newComment->getPostId(); |
115 | 115 | }); |
116 | 116 | $comment = new InMemoryComment( |
@@ -131,10 +131,10 @@ discard block |
||
131 | 131 | public function getCommentsCount(Ulid $postId): int |
132 | 132 | { |
133 | 133 | return self::$postHeaders |
134 | - ->filter(function ($post) use ($postId) { |
|
134 | + ->filter(function($post) use ($postId) { |
|
135 | 135 | return $post->getId() == $postId; |
136 | 136 | }) |
137 | - ->map(function ($post) { |
|
137 | + ->map(function($post) { |
|
138 | 138 | return count($post->getComments()); |
139 | 139 | }) |
140 | 140 | ->first(); |
@@ -143,14 +143,14 @@ discard block |
||
143 | 143 | public function findCommentsByPostId(Ulid $postId): array |
144 | 144 | { |
145 | 145 | $post = self::$postHeaders |
146 | - ->find(function ($post) use ($postId) { |
|
146 | + ->find(function($post) use ($postId) { |
|
147 | 147 | return $post->getId() == $postId; |
148 | 148 | }); |
149 | 149 | if ($post == null) { |
150 | 150 | return []; |
151 | 151 | } |
152 | 152 | return Collection::from($post->getComments()) |
153 | - ->map(function ($comment) { |
|
153 | + ->map(function($comment) { |
|
154 | 154 | $parentId = $comment->getParentComment() != null ? $comment->getParentComment()->getId() : null; |
155 | 155 | return new CommentDto( |
156 | 156 | $comment->getId(), |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | $from = ($pageNo - 1) * self::PAGE_SIZE; |
168 | 168 | $to = $from + self::PAGE_SIZE; |
169 | 169 | $data = self::$comments |
170 | - ->map(function ($comment) { |
|
170 | + ->map(function($comment) { |
|
171 | 171 | $parentId = $comment->getParentComment() != null ? $comment->getParentComment()->getId() : null; |
172 | 172 | return new CommentWithPostDto( |
173 | 173 | $comment->getId(), |
@@ -179,14 +179,14 @@ discard block |
||
179 | 179 | $comment->getPost()->getTitle(), |
180 | 180 | $comment->getPost()->getSummary(), |
181 | 181 | self::$postHeaders |
182 | - ->filter(function ($post) use ($comment) { |
|
182 | + ->filter(function($post) use ($comment) { |
|
183 | 183 | return $post->getId() == $comment->getPost()->getId(); |
184 | 184 | })->size(), |
185 | 185 | $comment->getPost()->getTags(), |
186 | 186 | |
187 | 187 | ); |
188 | 188 | }) |
189 | - ->sort(function ($c1, $c2) { |
|
189 | + ->sort(function($c1, $c2) { |
|
190 | 190 | return $c1->getCreatedAt() < $c2->getCreatedAt() ? 1 : -1; |
191 | 191 | }) |
192 | 192 | ->slice($from, $to) |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | public function commentExists(Ulid $commentId): bool |
198 | 198 | { |
199 | 199 | return self::$comments |
200 | - ->filter(function ($comment) use ($commentId) { |
|
200 | + ->filter(function($comment) use ($commentId) { |
|
201 | 201 | return $comment->getId() == $commentId; |
202 | 202 | })->sizeIsGreaterThan(0); |
203 | 203 | } |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | public function postExists(Ulid $postId): bool |
206 | 206 | { |
207 | 207 | return self::$postHeaders |
208 | - ->filter(function ($post) use ($postId) { |
|
208 | + ->filter(function($post) use ($postId) { |
|
209 | 209 | return $post->getId() == $postId; |
210 | 210 | })->sizeIsGreaterThan(0); |
211 | 211 | } |
@@ -213,11 +213,11 @@ discard block |
||
213 | 213 | public function deleteCommentsForPost(Ulid $postId) |
214 | 214 | { |
215 | 215 | self::$comments = self::$comments |
216 | - ->filter(function ($comment) use ($postId) { |
|
216 | + ->filter(function($comment) use ($postId) { |
|
217 | 217 | return $comment->getPost()->getId() != $postId; |
218 | 218 | }) |
219 | 219 | ->realize(); |
220 | - $post = self::$postHeaders->find(function ($post) use ($postId) { |
|
220 | + $post = self::$postHeaders->find(function($post) use ($postId) { |
|
221 | 221 | $post->getId() == $postId; |
222 | 222 | }); |
223 | 223 | if ($post != null) { |
@@ -229,10 +229,10 @@ discard block |
||
229 | 229 | public function updateUserName(UpdatedCommentsPostHeadersUserNameDto $updatedUserName): void |
230 | 230 | { |
231 | 231 | self::$postHeaders |
232 | - ->filter(function ($post) use ($updatedUserName) { |
|
232 | + ->filter(function($post) use ($updatedUserName) { |
|
233 | 233 | return $post->getCreatedByName() == $updatedUserName->getOldUserName(); |
234 | 234 | }) |
235 | - ->each(function ($post) use ($updatedUserName) { |
|
235 | + ->each(function($post) use ($updatedUserName) { |
|
236 | 236 | $post->setCreatedByName($updatedUserName->getNewUserName()); |
237 | 237 | }) |
238 | 238 | ->realize(); |
@@ -8,7 +8,7 @@ |
||
8 | 8 | class InMemoryTransactionFactory implements TransactionFactoryInterface |
9 | 9 | { |
10 | 10 | |
11 | - public function createTransaction($func): TransactionInterface |
|
11 | + public function createTransaction($func): TransactionInterface |
|
12 | 12 | { |
13 | 13 | return new InMemoryTransaction($func); |
14 | 14 | } |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * @return mixed |
27 | 27 | * @throws \Exception |
28 | 28 | */ |
29 | - public function execute(): mixed |
|
29 | + public function execute(): mixed |
|
30 | 30 | { |
31 | 31 | try { |
32 | 32 | $handler = $this->func; |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * @param $func |
49 | 49 | * @return $this |
50 | 50 | */ |
51 | - public function afterCommit($func): TransactionInterface |
|
51 | + public function afterCommit($func): TransactionInterface |
|
52 | 52 | { |
53 | 53 | $this->afterCommit->add($func); |
54 | 54 | return $this; |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | * @param $func |
59 | 59 | * @return $this |
60 | 60 | */ |
61 | - public function afterRollback($func): TransactionInterface |
|
61 | + public function afterRollback($func): TransactionInterface |
|
62 | 62 | { |
63 | 63 | $this->afterRollback->add($func); |
64 | 64 | return $this; |
@@ -20,7 +20,7 @@ |
||
20 | 20 | } |
21 | 21 | |
22 | 22 | |
23 | - public function getUser(): LoggedInUser |
|
23 | + public function getUser(): LoggedInUser |
|
24 | 24 | { |
25 | 25 | return new LoggedInUser( |
26 | 26 | InMemoryLoggedInUserProvider::$USER_ID, |