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

ClientsTableFactory::createService()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 9
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 9
loc 9
ccs 0
cts 7
cp 0
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
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\Clients;
24
use Admin\Model\ClientsTable;
25
26
/**
27
 * Class Admin\Model\ClientsTableFactory
28
 *
29
 * @package Admin\Factory\ClientsTableFactory
30
 */
31 View Code Duplication
class ClientsTableFactory 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\ClientsTable
39
     */
40
    public function createService(ServiceLocatorInterface $serviceLocator)
41
    {
42
        $dbAdapter            = $serviceLocator->get('Zend\Db\Adapter\Adapter');
43
        $resultSetPrototype    = new ResultSet();
44
        $resultSetPrototype->setArrayObjectPrototype(new Clients());
0 ignored issues
show
Documentation introduced by
new \Admin\Model\Clients() is of type object<Admin\Model\Clients>, 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('clients', $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 ClientsTable($tableGateway);
47
        return $table;
48
    }
49
}