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.

Doctrine::init()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.6
c 0
b 0
f 0
cc 2
nc 1
nop 0
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 Doctrine extends AbstractTable
14
{
15
16
    protected $config = array(
17
        'name' => 'Doctrine 2',
18
        'showPagination' => true,
19
        'showQuickSearch' => false,
20
        'showItemPerPage' => true,
21
        'showColumnFilters' => true,
22
    );
23
24
    /**
25
     * @var array Definition of headers
26
     */
27
    protected $headers = array(
28
        'idcustomer' =>     array('tableAlias' => 'q', 'title' => 'Id', 'width' => '50') ,
29
        'doctrine' =>       array(
30
            'tableAlias' => 'q',
31
            'title' => 'Doctrine closure' ,
32
            'filters' => 'text',
33
            'sortable' => false
34
        ),
35
        'product' =>        array('tableAlias' => 'p', 'title' => 'Product', 'filters' => 'text'),
36
        'name' =>           array('tableAlias' => 'q', 'title' => 'Name', 'filters' => 'text') ,
37
        'surname' =>        array('tableAlias' => 'q', 'title' => 'Surname', 'filters' => 'text'),
38
        'street' =>         array('tableAlias' => 'q', 'title' => 'Street', 'filters' => 'text'),
39
        'city' =>           array('tableAlias' => 'q', 'title' => 'City', 'filters' => 'text'),
40
        'active' =>         array('tableAlias' => 'q', 'title' => 'Active', 'width' => 100 ),
41
    );
42
43
    public function init()
44
    {
45
        $this->getHeader('doctrine')->getCell()->addDecorator('callable', array(
46
            'callable' => function ($context, $record) {
47
                return $record->name . ' ' . $record->surname;
48
            }
49
        ));
50
51
52
        $this->getHeader('product')->getCell()->addDecorator('callable', array(
53
            'callable' => function ($context, $record) {
54
55
                if (is_object($record->product)) {
56
                    return $record->product->product;
57
                } else {
58
                    return '';
59
                }
60
            }
61
        ));
62
    }
63
64
    //The filters could also be done with a parametrised query
65
    protected function initFilters($query)
66
    {
67 View Code Duplication
        if ($value = $this->getParamAdapter()->getValueOfFilter('name')) {
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...
Duplication introduced by
This code seems to be duplicated across 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...
68
            $query->where($query->expr()->like('q.name', '?1'))->setParameter('1', '%' . $value . '%');
69
        }
70
71 View Code Duplication
        if ($value = $this->getParamAdapter()->getValueOfFilter('surname')) {
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...
Duplication introduced by
This code seems to be duplicated across 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...
72
            $query->where($query->expr()->like('q.surname', '?1'))->setParameter('1', '%' . $value . '%');
73
        }
74
75
        if ($value = $this->getParamAdapter()->getValueOfFilter('doctrine')) {
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...
76
            $query->where("q.name like '%".$value."%' OR q.surname like '%".$value."%' ");
77
            $expr = $query->expr();
78
            $query->where($expr->orX($expr->like('q.name', '?1'), $expr->like('q.surname', '?2')))
79
                ->setParameter('1', '%' . $value . '%')
80
                ->setParameter('2', '%' . $value . '%');
81
        }
82
83 View Code Duplication
        if ($value = $this->getParamAdapter()->getValueOfFilter('street')) {
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...
Duplication introduced by
This code seems to be duplicated across 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...
84
            $query->where($query->expr()->like('q.street', '?1'))->setParameter('1', '%' . $value . '%');
85
        }
86
87 View Code Duplication
        if ($value = $this->getParamAdapter()->getValueOfFilter('city')) {
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...
Duplication introduced by
This code seems to be duplicated across 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...
88
            $query->where($query->expr()->like('q.city', '?1'))->setParameter('1', '%' . $value . '%');
89
        }
90
91 View Code Duplication
        if ($value = $this->getParamAdapter()->getValueOfFilter('product')) {
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...
Duplication introduced by
This code seems to be duplicated across 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...
92
            $query->where($query->expr()->like('q.product', '?1'))->setParameter('1', '%' . $value . '%');
93
        }
94
    }
95
}
96