diff --git a/old/src/PointToolsBundle/Service/Factory/Blogs/CommentFactory.php b/old/src/PointToolsBundle/Service/Factory/Blogs/CommentFactory.php deleted file mode 100644 index 01026d7..0000000 --- a/old/src/PointToolsBundle/Service/Factory/Blogs/CommentFactory.php +++ /dev/null @@ -1,30 +0,0 @@ -userFactory = $userFactory; - $this->commentRepository = $commentRepository; - $this->postRepository = $postRepository; - } -} \ No newline at end of file diff --git a/src/Factory/Blog/CommentFactory.php b/src/Factory/Blog/CommentFactory.php new file mode 100644 index 0000000..0db3a32 --- /dev/null +++ b/src/Factory/Blog/CommentFactory.php @@ -0,0 +1,21 @@ +fileRepository = $fileRepository; } /** @@ -42,39 +39,17 @@ class FileFactory extends AbstractFactory return $files; } - /** - * @param string $url - * - * @return File - * - * @throws InvalidResponseException - */ public function createFromUrl(string $url): File { - $this->validateData($url); - // Replacing HTTP with HTTPS $url = str_replace('http://', 'https://', $url); if (null === ($file = $this->fileRepository->findOneBy(['remoteUrl' => $url]))) { // Creating new file $file = new File($url); - $this->fileRepository->add($file); + $this->fileRepository->save($file); } return $file; } - - /** - * @param $data - * - * @throws InvalidResponseException - */ - private function validateData($data): void - { - if (!is_string($data)) { - // @todo Change exception - throw new InvalidResponseException('File data must be a string'); - } - } -} \ No newline at end of file +} diff --git a/old/src/PointToolsBundle/Service/Factory/Blogs/PostFactory.php b/src/Factory/Blog/PostFactory.php similarity index 66% rename from old/src/PointToolsBundle/Service/Factory/Blogs/PostFactory.php rename to src/Factory/Blog/PostFactory.php index e36f4ae..1a83f67 100644 --- a/old/src/PointToolsBundle/Service/Factory/Blogs/PostFactory.php +++ b/src/Factory/Blog/PostFactory.php @@ -1,60 +1,31 @@ em = $em; - $this->postRepository = $postRepository; - $this->userFactory = $userFactory; - $this->fileFactory = $fileFactory; - $this->commentFactory = $commentFactory; - $this->tagFactory = $tagFactory; } /** @@ -148,7 +119,7 @@ class PostFactory extends AbstractFactory new \DateTime($postData->getCreated()), $postData->getType() ?: Post::TYPE_POST ); - $this->postRepository->add($post); + $this->postRepository->save($post); } $post @@ -159,10 +130,7 @@ class PostFactory extends AbstractFactory return $post; } - /** - * @param Post $post - * @param string[] $tagsStrings - */ + /** @param string[] $tagsStrings */ private function updatePostTags(Post $post, array $tagsStrings): void { $tags = $this->tagFactory->createFromStringsArray($tagsStrings); @@ -170,41 +138,37 @@ class PostFactory extends AbstractFactory // Hashing tags strings $tagStringsHash = []; foreach ($tagsStrings as $tagsString) { - $tagStringsHash[mb_strtolower($tagsString)] = $tagsString; + $tagStringsHash[\mb_strtolower($tagsString)] = $tagsString; } // Hashing current post tags $newTagsHash = []; foreach ($tags as $tag) { - $newTagsHash[mb_strtolower($tag->getText())] = $tag; + $newTagsHash[\mb_strtolower($tag->getText())] = $tag; } // Hashing old post tags (from DB) $oldTagsHash = []; foreach ($post->getPostTags() as $postTag) { - $oldTagsHash[mb_strtolower($postTag->getOriginalTagText())] = $postTag; + $oldTagsHash[\mb_strtolower($postTag->getOriginalTagText())] = $postTag; } // Adding missing tags foreach ($tags as $tag) { - if (!array_key_exists(mb_strtolower($tag->getText()), $oldTagsHash)) { - $tmpPostTag = new PostTag($post, $tag, $tagStringsHash[mb_strtolower($tag->getText())]); + if (!array_key_exists(\mb_strtolower($tag->getText()), $oldTagsHash)) { + $tmpPostTag = new PostTag($post, $tag, $tagStringsHash[\mb_strtolower($tag->getText())]); $post->addPostTag($tmpPostTag); } } // Removing deleted tags foreach ($post->getPostTags() as $postTag) { - if (!array_key_exists(mb_strtolower($postTag->getOriginalTagText()), $newTagsHash)) { + if (!array_key_exists(\mb_strtolower($postTag->getOriginalTagText()), $newTagsHash)) { $post->removePostTag($postTag); } } } - /** - * @param Post $post - * @param array $urls - */ private function updatePostFiles(Post $post, array $urls): void { $files = $this->fileFactory->createFromUrlsArray($urls); diff --git a/old/src/PointToolsBundle/Service/Factory/Blogs/TagFactory.php b/src/Factory/Blog/TagFactory.php similarity index 67% rename from old/src/PointToolsBundle/Service/Factory/Blogs/TagFactory.php rename to src/Factory/Blog/TagFactory.php index c7386b4..2de3da2 100644 --- a/old/src/PointToolsBundle/Service/Factory/Blogs/TagFactory.php +++ b/src/Factory/Blog/TagFactory.php @@ -1,23 +1,20 @@ tagRepository = $tagRepository; } /** @@ -47,7 +44,7 @@ class TagFactory extends AbstractFactory if (null === ($tag = $this->tagRepository->findOneByLowerText($text))) { // Creating new tag $tag = new Tag($text); - $this->tagRepository->add($tag); + $this->tagRepository->save($tag); } return $tag; diff --git a/src/Service/Api/PostApi.php b/src/Service/Api/PostApi.php index 69fcd0a..a41ee73 100644 --- a/src/Service/Api/PostApi.php +++ b/src/Service/Api/PostApi.php @@ -5,7 +5,7 @@ namespace App\Service\Api; use JMS\Serializer\SerializerInterface; use Psr\Log\LoggerInterface; -use App\Service\Factory\Blogs\PostFactory; +use App\Factory\Blog\PostFactory; use Symfony\Contracts\HttpClient\HttpClientInterface; /** Basic Point.im user API functions from /api/post */ @@ -15,7 +15,7 @@ class PostApi extends AbstractApi HttpClientInterface $pointApiClient, SerializerInterface $serializer, LoggerInterface $logger, - private readonly PostFactory $postFactory + private readonly PostFactory $postFactory, ) { parent::__construct($pointApiClient, $logger, $serializer); } diff --git a/src/Service/Api/UserApi.php b/src/Service/Api/UserApi.php index bed80bb..e5f24c7 100644 --- a/src/Service/Api/UserApi.php +++ b/src/Service/Api/UserApi.php @@ -10,7 +10,7 @@ use App\Exception\Api\{ForbiddenException, NotFoundException, UserNotFoundException }; -use App\Service\Factory\UserFactory; +use App\Factory\UserFactory; use JMS\Serializer\{DeserializationContext, SerializerInterface}; use Psr\Log\LoggerInterface; use Symfony\Contracts\HttpClient\HttpClientInterface;