Completed
Push — master ( 3c1fe9...eb8828 )
by Ivannis Suárez
08:56
created

DocumentRepositoryFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A create() 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
/**
4
 * This file is part of the Cubiche package.
5
 *
6
 * Copyright (c) Cubiche
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Cubiche\Infrastructure\Repository\Doctrine\ODM\MongoDB;
13
14
use Doctrine\ODM\MongoDB\DocumentManager;
15
16
/**
17
 * DocumentRepositoryFactory class.
18
 *
19
 * @author Ivannis Suárez Jerez <[email protected]>
20
 */
21 View Code Duplication
class DocumentRepositoryFactory implements DocumentRepositoryFactoryInterface
0 ignored issues
show
Duplication introduced by
This class 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...
22
{
23
    /**
24
     * @var DocumentManager
25
     */
26
    protected $documentManager;
27
28
    /**
29
     * @var DocumentDataSourceFactory
30
     */
31
    protected $documentDatasourceFactory;
32
33
    /**
34
     * DocumentRepositoryFactory constructor.
35
     *
36
     * @param DocumentManager           $documentManager
37
     * @param DocumentDataSourceFactory $documentDatasourceFactory
38
     */
39
    public function __construct(DocumentManager $documentManager, DocumentDataSourceFactory $documentDatasourceFactory)
40
    {
41
        $this->documentManager = $documentManager;
42
        $this->documentDatasourceFactory = $documentDatasourceFactory;
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function create($documentName)
49
    {
50
        return new DocumentRepository(
51
            $this->documentManager->getRepository($documentName),
52
            $this->documentDatasourceFactory
0 ignored issues
show
Unused Code introduced by
The call to DocumentRepository::__construct() has too many arguments starting with $this->documentDatasourceFactory.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
53
        );
54
    }
55
}
56