AbstractDatagrid::createService()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace ZfcDatagrid\Service;
4
5
use Interop\Container\ContainerInterface;
6
use InvalidArgumentException;
7
use Zend\ServiceManager\FactoryInterface;
8
use Zend\ServiceManager\ServiceLocatorInterface;
9
use ZfcDatagrid\Datagrid;
10
11
abstract class AbstractDatagrid extends Datagrid implements FactoryInterface
0 ignored issues
show
Deprecated Code introduced by
The interface Zend\ServiceManager\FactoryInterface has been deprecated with message: Use Zend\ServiceManager\Factory\FactoryInterface instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
12
{
13
    /**
14
     * @param ContainerInterface $container
15
     * @param string             $requestedName
16
     * @param array|null         $options
17
     *
18
     * @return $this
19
     */
20
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
21
    {
22
        $this->setServiceLocator($container);
23
        $config = $container->get('config');
24
25
        if (!isset($config['ZfcDatagrid'])) {
26
            throw new InvalidArgumentException('Config key "ZfcDatagrid" is missing');
27
        }
28
29
        /* @var $application \Zend\Mvc\Application */
30
        $application = $container->get('application');
31
32
        parent::setOptions($config['ZfcDatagrid']);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (setOptions() instead of __invoke()). Are you sure this is correct? If so, you might want to change this to $this->setOptions().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
33
        parent::setMvcEvent($application->getMvcEvent());
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (setMvcEvent() instead of __invoke()). Are you sure this is correct? If so, you might want to change this to $this->setMvcEvent().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
34
35
        if ($container->has('translator') === true) {
36
            parent::setTranslator($container->get('translator'));
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (setTranslator() instead of __invoke()). Are you sure this is correct? If so, you might want to change this to $this->setTranslator().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
37
        }
38
39
        parent::setRendererService($container->get('zfcDatagrid.renderer.'.parent::getRendererName()));
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getRendererName() instead of __invoke()). Are you sure this is correct? If so, you might want to change this to $this->getRendererName().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
Comprehensibility Bug introduced by
It seems like you call parent on a different method (setRendererService() instead of __invoke()). Are you sure this is correct? If so, you might want to change this to $this->setRendererService().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
40
        parent::init();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (init() instead of __invoke()). Are you sure this is correct? If so, you might want to change this to $this->init().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
41
42
        return $this;
43
    }
44
45
    /**
46
     * @param ServiceLocatorInterface $serviceLocator
47
     *
48
     * @return Datagrid
49
     */
50
    public function createService(ServiceLocatorInterface $serviceLocator)
51
    {
52
        return $this($serviceLocator, Datagrid::class);
53
    }
54
55
    /**
56
     * Call initGrid on rendering.
57
     */
58
    public function render()
59
    {
60
        $this->initGrid();
61
62
        parent::render();
63
    }
64
65
    abstract public function initGrid();
66
}
67