Passed
Branch ops-updates (277b44)
by Björn
05:09
created

SettingsTableFactory::createService()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 8
ccs 0
cts 7
cp 0
crap 2
rs 10
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\Settings;
24
use Admin\Model\SettingsTable;
25
26
/**
27
 * Class Admin\Model\SettingsTableFactory
28
 *
29
 * @package Admin\Factory\SettingsTableFactory
30
 */
31
class SettingsTableFactory implements FactoryInterface
32
{
33
    /**
34
     * Create service
35
     *
36
     * @param ServiceLocatorInterface $serviceLocator
37
     *
38
     * @return Admin\Model\SettingsTable
0 ignored issues
show
Bug introduced by
The type Admin\Factory\Admin\Model\SettingsTable was not found. Did you mean Admin\Model\SettingsTable? If so, make sure to prefix the type with \.
Loading history...
39
     */
40
    public function createService(ServiceLocatorInterface $serviceLocator)
41
    {
42
        $dbAdapter            = $serviceLocator->get('Zend\Db\Adapter\Adapter');
43
        $resultSetPrototype    = new ResultSet();
44
        $resultSetPrototype->setArrayObjectPrototype(new Settings());
0 ignored issues
show
Bug introduced by
new Admin\Model\Settings() of type Admin\Model\Settings is incompatible with the type ArrayObject expected by parameter $arrayObjectPrototype of Zend\Db\ResultSet\Result...tArrayObjectPrototype(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

44
        $resultSetPrototype->setArrayObjectPrototype(/** @scrutinizer ignore-type */ new Settings());
Loading history...
45
        $tableGateway        = new TableGateway('settings', $dbAdapter, null, $resultSetPrototype);
0 ignored issues
show
Bug introduced by
It seems like $dbAdapter can also be of type array; however, parameter $adapter of Zend\Db\TableGateway\TableGateway::__construct() does only seem to accept Zend\Db\Adapter\AdapterInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

45
        $tableGateway        = new TableGateway('settings', /** @scrutinizer ignore-type */ $dbAdapter, null, $resultSetPrototype);
Loading history...
46
        $table                = new SettingsTable($tableGateway);
47
        return $table;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $table returns the type Admin\Model\SettingsTable which is incompatible with the documented return type Admin\Factory\Admin\Model\SettingsTable.
Loading history...
48
    }
49
}