Completed
Pull Request — develop (#241)
by ANTHONIUS
07:36
created

PaginatorFactoryAbstract::getCreationOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 4
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de)
7
 * @license   MIT
8
 */
9
10
namespace Solr\Paginator;
11
12
use Core\Paginator\PaginatorService;
13
use Solr\Paginator\Adapter\SolrAdapter;
14
use Zend\Paginator\Paginator;
15
use Zend\ServiceManager\FactoryInterface;
16
use Zend\ServiceManager\MutableCreationOptionsInterface;
17
use Zend\ServiceManager\ServiceLocatorInterface;
18
19
/**
20
 * Abstract class for Solr paginator factory
21
 *
22
 * @author  Anthonius Munthi <[email protected]>
23
 * @since   0.27
24
 * @package Solr\Paginator
25
 */
26 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...
27
{
28
    /**
29
     * @var array
30
     */
31
    protected $options = [];
32
33
    /**
34
     * Set creation options
35
     *
36
     * @param  array $options
37
     *
38
     * @return void
39
     */
40
    public function setCreationOptions(array $options)
41
    {
42
        $this->options = $options;
43
    }
44
45
    /**
46
     * @return array
47
     */
48
    public function getCreationOptions()
49
    {
50
        return $this->options;
51
    }
52
53
    /**
54
     * @param ServiceLocatorInterface $serviceLocator
55
     * @return mixed|Paginator
56
     */
57
    public function createService(ServiceLocatorInterface $serviceLocator)
58
    {
59
        /* @var PaginatorService $serviceLocator */
60
        $filter             = $serviceLocator->getServiceLocator()->get('filterManager')->get($this->getFilter());
61
        $connectPath        = $this->getConnectPath();
62
        $solrClient         = $serviceLocator->getServiceLocator()->get('Solr/Manager')->getClient($connectPath);
63
        $resultConverter    = $serviceLocator->getServiceLocator()->get('Solr/ResultConverter');
64
        $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...
65
        $service            = new Paginator($adapter);
66
67
        $this->setCreationOptions([]);
68
        return $service;
69
    }
70
71
    /**
72
     * pagination service name
73
     *
74
     * @return string
75
     */
76
    abstract protected function getFilter();
77
78
    /**
79
     * Get Solr Connect Path for this paginator
80
     *
81
     * @return string
82
     */
83
    abstract protected function getConnectPath();
84
}