Completed
Push — master ( 749edd...721fe7 )
by Park Jong-Hun
10:14
created

Comment::edit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 1
eloc 7
nc 1
nop 5
1
<?php
2
3
namespace App\Controller;
4
5
use Core\ViewModel;
6
use Core\Application;
7
use App\Entity\Comment as CommentModel;
8
use App\Entity\User as UserModel;
9
use App\Auth\LoginManagerInterface;
10
use Doctrine\ORM\EntityManagerInterface;
11
use \DateTime;
12
13
class Comment
14
{
15
    public function showEditForm($id, EntityManagerInterface $entityManager, ViewModel $viewModel)
16
    {
17
        $viewModel->set('comment', $entityManager->getRepository(CommentModel::class)->find($id));
18
19
        return 'default/commentForm';
20
    }
21
22
    public function edit($id, $parsedBody, EntityManagerInterface $entityManager, LoginManagerInterface $loginManager, ViewModel $viewModel)
0 ignored issues
show
Unused Code introduced by
The parameter $viewModel is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
23
    {
24
        /** @var CommentModel */
25
        $comment = $entityManager->getRepository(CommentModel::class)->find($id);
26
        $comment->setContent($parsedBody['content']);
27
        $comment->setUpdatedAt(new DateTime());
28
        $this->fillUserInfomanionByLoginAccount($comment, $parsedBody, $loginManager, $entityManager);
29
30
        $entityManager->flush();
31
32
        return 'redirect: ' . Application::getUrl('/post/' . $comment->getPost()->getId());
33
    }
34
35 View Code Duplication
    private function fillUserInfomanionByLoginAccount($userContent, $parsedBody, LoginManagerInterface $loginManager, EntityManagerInterface $entityManager)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
    {
37
        if ($loginManager->getLoggedAccountId()) {
38
            /** @var UserModel */
39
            $user = $entityManager->getRepository(UserModel::class)
40
                        ->findOneBy(['accountId' => $loginManager->getLoggedAccountId()]);
41
42
            $userContent->setUser($user);
43
            $userContent->setAuthor($user->getNickname());
44
            $userContent->setPassword($user->getPassword());
45
        } else {
46
            $userContent->setAuthor($parsedBody['author']);
47
            $userContent->setPassword($parsedBody['password']);
48
        }
49
    }
50
}
51