Passed
Push — master ( 700b0f...aafb0a )
by Björn
18:25 queued 10s
created

UserProfileTableFactory   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 19
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 5
dl 19
loc 19
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A createService() 9 9 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
 * BB's Zend Framework 2 Components
4
 *
5
 * AdminModule
6
 *
7
 * @package   [MyApplication]
8
 * @package   BB's Zend Framework 2 Components
9
 * @package   AdminModule
10
 * @author    Björn Bartels <[email protected]>
11
 * @link      https://gitlab.bjoernbartels.earth/groups/zf2
12
 * @license   http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
13
 * @copyright copyright (c) 2016 Björn Bartels <[email protected]>
14
 */
15
16
namespace Admin\Factory;
17
18
use Zend\Db\ResultSet\ResultSet;
19
use Zend\Db\TableGateway\TableGateway;
20
use Zend\ServiceManager\FactoryInterface;
21
use Zend\ServiceManager\ServiceLocatorInterface;
22
23
use Admin\Model\UserProfile;
24
use Admin\Model\UserProfileTable;
25
26
/**
27
 * Class Admin\Model\UserProfileTableFactory
28
 *
29
 * @package Admin\Factory\UserProfileTableFactory
30
 */
31 View Code Duplication
class UserProfileTableFactory implements FactoryInterface
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...
32
{
33
    /**
34
     * Create service
35
     *
36
     * @param ServiceLocatorInterface $serviceLocator
37
     *
38
     * @return Admin\Model\UserProfileTable
39
     */
40
    public function createService(ServiceLocatorInterface $serviceLocator)
41
    {
42
        $dbAdapter            = $serviceLocator->get('Zend\Db\Adapter\Adapter');
43
        $resultSetPrototype    = new ResultSet();
44
        $resultSetPrototype->setArrayObjectPrototype(new UserProfile());
0 ignored issues
show
Documentation introduced by
new \Admin\Model\UserProfile() is of type object<Admin\Model\UserProfile>, but the function expects a object<ArrayObject>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
45
        $tableGateway        = new TableGateway('userprofile', $dbAdapter, null, $resultSetPrototype);
0 ignored issues
show
Documentation introduced by
$dbAdapter is of type object|array, but the function expects a object<Zend\Db\Adapter\AdapterInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
46
        $table                = new UserProfileTable($tableGateway);
47
        return $table;
48
    }
49
}