Completed
Push — master ( 27cf3f...45554e )
by Aimeos
02:14
created

Base   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 183
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 0
dl 0
loc 183
rs 10
c 0
b 0
f 0

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A __call() 0 4 1
A addFilterAttribute() 0 4 1
A addFilterCategory() 0 5 1
A addFilterText() 0 4 1
A aggregate() 0 4 1
A createFilter() 0 4 1
A getItems() 0 4 1
A createTextFilter() 0 4 1
A getTextList() 0 4 1
A getContext() 0 4 1
A getController() 0 4 1
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2016
6
 * @package Controller
7
 * @subpackage Frontend
8
 */
9
10
11
namespace Aimeos\Controller\Frontend\Index\Decorator;
12
13
14
/**
15
 * Base for index frontend controller decorators
16
 *
17
 * @package Controller
18
 * @subpackage Frontend
19
 */
20
abstract class Base
21
	implements \Aimeos\Controller\Frontend\Common\Decorator\Iface
1 ignored issue
show
Coding Style introduced by
The implements keyword must be on the same line as the class name
Loading history...
22
{
23
	private $context;
24
	private $controller;
25
26
27
	/**
28
	 * Initializes the controller decorator.
29
	 *
30
	 * @param \Aimeos\Controller\Frontend\Iface $controller Controller object
31
	 * @param \Aimeos\MShop\Context\Item\Iface $context Context object with required objects
32
	 */
33
	public function __construct( \Aimeos\Controller\Frontend\Iface $controller, \Aimeos\MShop\Context\Item\Iface $context )
34
	{
35
		$this->context = $context;
36
		$this->controller = $controller;
37
	}
38
39
40
	/**
41
	 * Passes unknown methods to wrapped objects.
42
	 *
43
	 * @param string $name Name of the method
44
	 * @param array $param List of method parameter
45
	 * @return mixed Returns the value of the called method
46
	 * @throws \Aimeos\Controller\Frontend\Exception If method call failed
47
	 */
48
	public function __call( $name, array $param )
49
	{
50
		return call_user_func_array( array( $this->controller, $name ), $param );
51
	}
52
53
54
	/**
55
	 * Returns the given search filter with the conditions attached for filtering by attribute.
56
	 *
57
	 * @param \Aimeos\MW\Criteria\Iface $filter Criteria object used for product search
58
	 * @param array $attrIds List of attribute IDs for faceted search
59
	 * @param array $optIds List of OR-combined attribute IDs for faceted search
60
	 * @param array $attrIds Associative list of OR-combined attribute IDs per attribute type for faceted search
61
	 * @return \Aimeos\MW\Criteria\Iface Criteria object containing the conditions for searching
62
	 * @since 2017.03
63
	 */
64
	public function addFilterAttribute( \Aimeos\MW\Criteria\Iface $filter, array $attrIds, array $optIds, array $oneIds )
65
	{
66
		return $this->getController()->addFilterAttribute( $filter, $attrIds, $optIds, $oneIds );
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Aimeos\Controller\Frontend\Common\Iface as the method addFilterAttribute() does only exist in the following implementations of said interface: Aimeos\Controller\Frontend\Index\Standard.

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...
67
	}
68
69
70
	/**
71
	 * Returns the given search filter with the conditions attached for filtering by category.
72
	 *
73
	 * @param \Aimeos\MW\Criteria\Iface $filter Criteria object used for product search
74
	 * @param string|array $catId Selected category by the user
75
	 * @param integer $level Constant for current category only, categories of next level (LEVEL_LIST) or whole subtree (LEVEL_SUBTREE)
76
	 * @param string|null $sort Sortation of the product list like "name", "code", "price" and "position", null for no sortation
77
	 * @param string $direction Sort direction of the product list ("+", "-")
78
	 * @param string $listtype List type of the product associated to the category, usually "default"
79
	 * @return \Aimeos\MW\Criteria\Iface Criteria object containing the conditions for searching
80
	 * @since 2017.03
81
	 */
82
	public function addFilterCategory( \Aimeos\MW\Criteria\Iface $filter, $catId,
0 ignored issues
show
Unused Code introduced by
The parameter $filter 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...
Unused Code introduced by
The parameter $catId 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...
83
		$level = \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE, $sort = null, $direction = '+', $listtype = 'default' )
84
	{
85
		return $this->getController()->addFilterCategory( $search, $catid, $level, $sort, $direction, $listtype );
0 ignored issues
show
Bug introduced by
The variable $search does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $catid does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
It seems like you code against a concrete implementation and not the interface Aimeos\Controller\Frontend\Common\Iface as the method addFilterCategory() does only exist in the following implementations of said interface: Aimeos\Controller\Frontend\Index\Standard.

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...
86
	}
87
88
89
	/**
90
	 * Returns the given search filter with the conditions attached for filtering by text.
91
	 *
92
	 * @param \Aimeos\MW\Criteria\Iface $filter Criteria object used for product search
93
	 * @param string $input Search string entered by the user
94
	 * @param string|null $sort Sortation of the product list like "name", "code", "price" and "position", null for no sortation
95
	 * @param string $direction Sort direction of the product list ("+", "-")
96
	 * @param string $listtype List type of the text associated to the product, usually "default"
97
	 * @return \Aimeos\MW\Criteria\Iface Criteria object containing the conditions for searching
98
	 * @since 2017.03
99
	 */
100
	public function addFilterText( \Aimeos\MW\Criteria\Iface $filter, $input, $sort = null, $direction = '+', $listtype = 'default' )
0 ignored issues
show
Unused Code introduced by
The parameter $filter 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...
101
	{
102
		return $this->getController()->addIndexFilterText( $search, $input, $sort, $direction, $listtype );
0 ignored issues
show
Bug introduced by
The variable $search does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
It seems like you code against a concrete implementation and not the interface Aimeos\Controller\Frontend\Common\Iface as the method addIndexFilterText() does only exist in the following implementations of said interface: Aimeos\Controller\Frontend\Catalog\Standard.

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...
103
	}
104
105
106
	/**
107
	 * Returns the aggregated count of products from the index for the given key.
108
	 *
109
	 * @param \Aimeos\MW\Criteria\Iface $filter Critera object which contains the filter conditions
110
	 * @param string $key Search key to aggregate for, e.g. "index.attribute.id"
111
	 * @return array Associative list of key values as key and the product count for this key as value
112
	 * @since 2015.08
113
	 */
114
	public function aggregate( \Aimeos\MW\Criteria\Iface $filter, $key )
115
	{
116
		return $this->getController()->aggregate( $filter, $key );
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Aimeos\Controller\Frontend\Common\Iface as the method aggregate() does only exist in the following implementations of said interface: Aimeos\Controller\Frontend\Index\Standard.

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...
117
	}
118
119
120
	/**
121
	 * Returns the default index filter.
122
	 *
123
	 * @param string|null $sort Sortation of the product list like "name", "code", "price" and "position", null for no sortation
124
	 * @param string $direction Sort direction of the product list ("+", "-")
125
	 * @param integer $start Position in the list of found products where to begin retrieving the items
126
	 * @param integer $size Number of products that should be returned
127
	 * @param string $listtype Type of the product list, e.g. default, promotion, etc.
128
	 * @return \Aimeos\MW\Criteria\Iface Criteria object containing the conditions for searching
129
	 * @since 2015.08
130
	 */
131
	public function createFilter( $sort = null, $direction = '+', $start = 0, $size = 100, $listtype = 'default' )
132
	{
133
		return $this->getController()->createFilter( $sort, $direction, $start, $size, $listtype );
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Aimeos\Controller\Frontend\Common\Iface as the method createFilter() does only exist in the following implementations of said interface: Aimeos\Controller\Frontend\Index\Standard.

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...
134
	}
135
136
137
	/**
138
	 * Returns the products from the index filtered by the given criteria object.
139
	 *
140
	 * @param \Aimeos\MW\Criteria\Iface $filter Critera object which contains the filter conditions
141
	 * @param string[] $domains Domain names of items that are associated with the products and that should be fetched too
142
	 * @param integer &$total Parameter where the total number of found products will be stored in
143
	 * @return array Ordered list of product items implementing \Aimeos\MShop\Product\Item\Iface
144
	 * @since 2015.08
145
	 */
146
	public function getItems( \Aimeos\MW\Criteria\Iface $filter, array $domains = array( 'media', 'price', 'text' ), &$total = null )
147
	{
148
		return $this->getController()->getItems( $filter, $domains, $total );
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Aimeos\Controller\Frontend\Common\Iface as the method getItems() does only exist in the following implementations of said interface: Aimeos\Controller\Frontend\Index\Standard.

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...
149
	}
150
151
152
	/**
153
	 * Returns text filter for the given search string.
154
	 *
155
	 * @param string $input Search string entered by the user
156
	 * @param string|null $sort Sortation of the product list like "name" and "relevance", null for no sortation
157
	 * @param string $direction Sort direction of the product list ("+", "-")
158
	 * @param integer $start Position in the list of found products where to begin retrieving the items
159
	 * @param integer $size Number of products that should be returned
160
	 * @param string $listtype List type of the text associated to the product, usually "default"
161
	 * @param string $type Type of the text like "name", "short", "long", etc.
162
	 * @return \Aimeos\MW\Criteria\Iface Criteria object containing the conditions for searching
163
	 */
164
	public function createTextFilter( $input, $sort = null, $direction = '-', $start = 0, $size = 25, $listtype = 'default', $type = 'name' )
165
	{
166
		return $this->getController()->createTextFilter( $input, $sort, $direction, $start, $size, $listtype, $type );
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Aimeos\Controller\Frontend\Common\Iface as the method createTextFilter() does only exist in the following implementations of said interface: Aimeos\Controller\Frontend\Catalog\Standard, Aimeos\Controller\Frontend\Index\Standard.

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...
167
	}
168
169
170
	/**
171
	 * Returns an list of product text strings matched by the filter.
172
	 *
173
	 * @param \Aimeos\MW\Criteria\Iface $filter Critera object which contains the filter conditions
174
	 * @return array Associative list of the product ID as key and the product text as value
175
	 */
176
	public function getTextList( \Aimeos\MW\Criteria\Iface $filter )
177
	{
178
		return $this->getController()->getTextList( $filter );
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Aimeos\Controller\Frontend\Common\Iface as the method getTextList() does only exist in the following implementations of said interface: Aimeos\Controller\Frontend\Catalog\Standard, Aimeos\Controller\Frontend\Index\Standard.

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...
179
	}
180
181
182
	/**
183
	 * Returns the context item
184
	 *
185
	 * @return \Aimeos\MShop\Context\Item\Iface Context item object
186
	 */
187
	protected function getContext()
188
	{
189
		return $this->context;
190
	}
191
192
193
	/**
194
	 * Returns the frontend controller
195
	 *
196
	 * @return \Aimeos\Controller\Frontend\Common\Iface Frontend controller object
197
	 */
198
	protected function getController()
199
	{
200
		return $this->controller;
201
	}
202
}
203