GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

AbstractSource   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 70
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
order() 0 1 ?
A getParamAdapter() 0 7 2
A getData() 0 5 1
A initQuery() 0 5 1
A initPaginator() 0 5 1
A setPaginator() 0 4 1
A setParamAdapter() 0 4 1
1
<?php
2
/**
3
 * ZfTable ( Module for Zend Framework 2)
4
 *
5
 * @copyright Copyright (c) 2013 Piotr Duda [email protected]
6
 * @license   MIT License
7
 */
8
9
namespace ZfTable\Source;
10
11
use ZfTable\AbstractCommon;
12
use ZfTable\Source\SourceInterface;
13
14
abstract class AbstractSource extends AbstractCommon implements SourceInterface
15
{
16
17
    /**
18
     *
19
     * @var \ZfTable\Params\AdapterInterface
20
     */
21
    protected $paramAdapter;
22
23
24
    abstract protected function order();
25
26
    /**
27
     * @return \ZfTable\Params\AdapterInterface
28
     */
29
    public function getParamAdapter()
30
    {
31
        if (!$this->paramAdapter) {
32
            $this->paramAdapter = $this->getTable()->getParamAdapter();
33
        }
34
        return $this->paramAdapter;
35
    }
36
37
    /**
38
     *
39
     * @return \Zend\Paginator\Paginator
40
     */
41
    public function getData()
42
    {
43
        $paginator = $this->getPaginator();
44
        return $paginator;
45
    }
46
47
48
    /**
49
     * Init query like ordering and quick searching
50
     */
51
    protected function initQuery()
52
    {
53
        $this->order();
54
        $this->quickSearch();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class ZfTable\Source\AbstractSource as the method quickSearch() does only exist in the following sub-classes of ZfTable\Source\AbstractSource: ZfTable\Source\SqlSelect. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
55
    }
56
57
    /**
58
     * Init paginator
59
     */
60
    protected function initPaginator()
61
    {
62
        $this->paginator->setItemCountPerPage($this->getParamAdapter()->getItemCountPerPage());
0 ignored issues
show
Bug introduced by
The property paginator does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
63
        $this->paginator->setCurrentPageNumber($this->getParamAdapter()->getPage());
64
    }
65
66
    /**
67
     *
68
     * @param \Zend\Paginator\Paginator $paginator
69
     */
70
    public function setPaginator(\Zend\Paginator\Paginator $paginator)
71
    {
72
        $this->paginator = $paginator;
73
    }
74
75
    /**
76
     *
77
     * @param \ZfTable\Params\AdapterInterface $paramAdapter
78
     */
79
    public function setParamAdapter(\ZfTable\Params\AdapterInterface $paramAdapter)
80
    {
81
        $this->paramAdapter = $paramAdapter;
82
    }
83
}
84