builder_call_vocabulary()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 0
loc 6
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php defined('SYSPATH') OR die('No direct script access.');
2
3
/**
4
 * @author     Ivan Kerin <[email protected]>
5
 * @copyright  (c) 2014 Clippings Ltd.
6
 * @license    http://spdx.org/licenses/BSD-3-Clause
7
 */
8
class Kohana_Jam_Behavior_Term extends Jam_Behavior
9
{
10
	public function builder_call_vocabulary(Database_Query_Builder $query, Jam_Event_Data $data, $name)
0 ignored issues
show
Unused Code introduced by
The parameter $data is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
11
	{
12
		$query
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Database_Query_Builder as the method join() does only exist in the following sub-classes of Database_Query_Builder: Database_Query_Builder_Select, Jam_Query_Builder_Collection, Jam_Query_Builder_Join, Jam_Query_Builder_Select, Kohana_Database_Query_Builder_Select, Kohana_Jam_Query_Builder_Collection, Kohana_Jam_Query_Builder_Join, Kohana_Jam_Query_Builder_Select, Model_Collection_Test_Author. 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...
13
			->join('vocabulary')
14
			->where('vocabulary.:name_key', 'IN', (array) $name);
15
	}
16
17
	public function builder_call_visible(Database_Query_Builder $query, Jam_Event_Data $data, $is_visible = TRUE)
0 ignored issues
show
Unused Code introduced by
The parameter $data is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
18
	{
19
		$query->where('is_hidden', '=', ! $is_visible);
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Database_Query_Builder as the method where() does only exist in the following sub-classes of Database_Query_Builder: Database_Query_Builder_Delete, Database_Query_Builder_Select, Database_Query_Builder_Update, Database_Query_Builder_Where, Jam_Query_Builder_Collection, Jam_Query_Builder_Delete, Jam_Query_Builder_Select, Jam_Query_Builder_Update, Kohana_Database_Query_Builder_Delete, Kohana_Database_Query_Builder_Select, Kohana_Database_Query_Builder_Update, Kohana_Database_Query_Builder_Where, Kohana_Jam_Query_Builder_Collection, Kohana_Jam_Query_Builder_Delete, Kohana_Jam_Query_Builder_Select, Kohana_Jam_Query_Builder_Update, Model_Collection_Test_Author. 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...
20
	}
21
22
	public static function builder_call_slugs_children(Database_Query_Builder $builder, Jam_Event_Data $data, $slugs)
0 ignored issues
show
Unused Code introduced by
The parameter $data is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
23
	{
24
		 $builder
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Database_Query_Builder as the method join() does only exist in the following sub-classes of Database_Query_Builder: Database_Query_Builder_Select, Jam_Query_Builder_Collection, Jam_Query_Builder_Join, Jam_Query_Builder_Select, Kohana_Database_Query_Builder_Select, Kohana_Jam_Query_Builder_Collection, Kohana_Jam_Query_Builder_Join, Kohana_Jam_Query_Builder_Select, Model_Collection_Test_Author. 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...
25
			->join(array('parent', 'parent'), 'LEFT')
26
			->where_open()
27
				->or_where('term.slug', 'IN', (array) $slugs)
28
				->or_where('parent.slug', 'IN', (array) $slugs)
29
			->where_close();
30
	}
31
}
32