Completed
Pull Request — develop (#241)
by ANTHONIUS
08:03
created

PaginatorFactoryAbstract::createService()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 13
Ratio 100 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 13
loc 13
rs 9.4285
cc 1
eloc 9
nc 1
nop 1
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de)
6
 * @license   MIT
7
 */
8
9
namespace Solr\Paginator;
10
11
use Core\Paginator\PaginatorService;
12
use Solr\Paginator\Adapter\SolrAdapter;
13
use Zend\Paginator\Paginator;
14
use Zend\ServiceManager\FactoryInterface;
15
use Zend\ServiceManager\MutableCreationOptionsInterface;
16
use Zend\ServiceManager\ServiceLocatorInterface;
17
18 View Code Duplication
abstract class PaginatorFactoryAbstract implements FactoryInterface,MutableCreationOptionsInterface
0 ignored issues
show
Coding Style introduced by
PaginatorFactoryAbstract does not seem to conform to the naming convention (^Abstract|Factory$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
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...
Coding Style introduced by
Expected 1 space before "MutableCreationOptionsInterface"; 0 found
Loading history...
19
{
20
    protected $options = [];
21
22
    /**
23
     * Set creation options
24
     *
25
     * @param  array $options
26
     *
27
     * @return void
28
     */
29
    public function setCreationOptions(array $options)
30
    {
31
        $this->options = $options;
32
    }
33
34
    public function getCreationOptions()
35
    {
36
        return $this->options;
37
    }
38
39
    /**
40
     * @param ServiceLocatorInterface $serviceLocator
41
     * @return mixed|Paginator
42
     */
43
    public function createService(ServiceLocatorInterface $serviceLocator)
44
    {
45
        /* @var PaginatorService $serviceLocator */
46
        $filter             = $serviceLocator->getServiceLocator()->get('filterManager')->get($this->getFilter());
47
        $connectPath        = $this->getConnectPath();
48
        $solrClient         = $serviceLocator->getServiceLocator()->get('Solr/Manager')->getClient($connectPath);
49
        $resultConverter    = $serviceLocator->getServiceLocator()->get('Solr/ResultConverter');
50
        $adapter            = new SolrAdapter($solrClient,$filter,$resultConverter,$this->options);
0 ignored issues
show
Documentation introduced by
$resultConverter is of type object|array, but the function expects a object<Solr\Bridge\ResultConverter>.

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...
51
        $service            = new Paginator($adapter);
52
53
        $this->setCreationOptions([]);
54
        return $service;
55
    }
56
57
    /**
58
     * pagination service name
59
     *
60
     * @return string
61
     */
62
    abstract protected function getFilter();
63
64
    /**
65
     * Get Solr Connect Path for this paginator
66
     *
67
     * @return string
68
     */
69
    abstract protected function getConnectPath();
70
}