FormFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 47.73 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 21
loc 44
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A createEditPostForm() 7 7 1
A createCreatePostForm() 7 7 1
A createCommentForm() 7 7 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Explicit Architecture POC,
7
 * which is created on top of the Symfony Demo application.
8
 *
9
 * (c) Herberto Graça <[email protected]>
10
 *
11
 * For the full copyright and license information, please view the LICENSE
12
 * file that was distributed with this source code.
13
 */
14
15
namespace Acme\App\Presentation\Web\Infrastructure\Form\Symfony;
16
17
use Acme\App\Presentation\Web\Core\Port\Form\FormFactoryInterface;
18
use Acme\App\Presentation\Web\Core\Port\Form\FormInterface;
19
use Acme\App\Presentation\Web\Infrastructure\Form\Symfony\Form\CommentForm;
20
use Acme\App\Presentation\Web\Infrastructure\Form\Symfony\Form\CreatePostForm;
21
use Acme\App\Presentation\Web\Infrastructure\Form\Symfony\Form\EditPostForm;
22
use Symfony\Bridge\PsrHttpMessage\HttpFoundationFactoryInterface;
23
use Symfony\Component\Form\Form as SymfonyForm;
24
use Symfony\Component\Form\FormFactoryInterface as SymfonyFormFactoryInterface;
25
26
final class FormFactory implements FormFactoryInterface
27
{
28
    /**
29
     * @var SymfonyFormFactoryInterface
30
     */
31
    private $symfonyFormFactory;
32
33
    /**
34
     * @var HttpFoundationFactoryInterface
35
     */
36
    private $symfonyResponseFactory;
37
38
    public function __construct(
39
        HttpFoundationFactoryInterface $symfonyResponseFactory,
40
        SymfonyFormFactoryInterface $symfonyFormFactory
41
    ) {
42
        $this->symfonyResponseFactory = $symfonyResponseFactory;
43
        $this->symfonyFormFactory = $symfonyFormFactory;
44
    }
45
46 View Code Duplication
    public function createEditPostForm($data = null, array $options = []): FormInterface
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...
47
    {
48
        /** @var SymfonyForm $form */
49
        $form = $this->symfonyFormFactory->create(EditPostForm::class, $data, $options);
50
51
        return new Form($this->symfonyResponseFactory, $form);
52
    }
53
54 View Code Duplication
    public function createCreatePostForm($data = null, array $options = []): FormInterface
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...
55
    {
56
        /** @var SymfonyForm $form */
57
        $form = $this->symfonyFormFactory->create(CreatePostForm::class, $data, $options);
58
59
        return new Form($this->symfonyResponseFactory, $form);
60
    }
61
62 View Code Duplication
    public function createCommentForm($data = null, array $options = []): FormInterface
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...
63
    {
64
        /** @var SymfonyForm $form */
65
        $form = $this->symfonyFormFactory->create(CommentForm::class, $data, $options);
66
67
        return new Form($this->symfonyResponseFactory, $form);
68
    }
69
}
70