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.

InstitutionRequests   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 4 1
A initFilters() 0 6 2
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\Example\TableExample;
10
11
use ZfTable\AbstractTable;
12
13
class InstitutionRequests extends AbstractTable
14
{
15
16
    protected $config = array(
17
        'name' => 'Institution Requests',
18
        'showPagination' => true,
19
        'showQuickSearch' => false,
20
        'showItemPerPage' => true,
21
        'itemCountPerPage' => 10,
22
        'showColumnFilters' => true,
23
    );
24
25
26
    /**
27
     * @var array Definition of headers
28
     */
29
    protected $headers = array(
30
        'address' => array('title' => 'Address' , 'filters' => 'text'),// from institution table
31
        'name' => array('title' => 'Name') ,// from user table
32
33
    );
34
35
    public function init()
36
    {
37
38
    }
39
40
    protected function initFilters($query)
41
    {
42
        if ($value = $this->getParamAdapter()->getValueOfFilter('address')) {
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface ZfTable\Params\AdapterInterface as the method getValueOfFilter() does only exist in the following implementations of said interface: ZfTable\Params\AdapterArrayObject.

Let’s take a look at an example:

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

class MyUser implements 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 implementation 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 interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
43
            $query->where("address like '%".$value."%' ");
44
        }
45
    }
46
}
47