Completed
Push — master ( 45554e...1a0e9a )
by Aimeos
02:10
created

Base::aggregate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
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 product for the given product ID from the index
139
	 *
140
	 * @param string $productId Unique product ID
141
	 * @param string[] $domains Domain names of items that are associated with the products and that should be fetched too
142
	 * @return \Aimeos\MShop\Product\Item\Iface Product item including the referenced domains items
143
	 * @since 2017.03
144
	 */
145
	public function getItem( $productId, array $domains = array( 'attribute', 'media', 'price', 'product', 'product/property', 'text' ) )
146
	{
147
		return $this->getController()->getItem( $productId, $domains );
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 getItem() 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...
148
	}
149
150
151
	/**
152
	 * Returns the products from the index filtered by the given criteria object.
153
	 *
154
	 * @param \Aimeos\MW\Criteria\Iface $filter Critera object which contains the filter conditions
155
	 * @param string[] $domains Domain names of items that are associated with the products and that should be fetched too
156
	 * @param integer &$total Parameter where the total number of found products will be stored in
157
	 * @return array Ordered list of product items implementing \Aimeos\MShop\Product\Item\Iface
158
	 * @since 2015.08
159
	 */
160
	public function getItems( \Aimeos\MW\Criteria\Iface $filter, array $domains = array( 'media', 'price', 'text' ), &$total = null )
161
	{
162
		return $this->getController()->searchItems( $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 searchItems() 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...
163
	}
164
165
166
	/**
167
	 * Returns the context item
168
	 *
169
	 * @return \Aimeos\MShop\Context\Item\Iface Context item object
170
	 */
171
	protected function getContext()
172
	{
173
		return $this->context;
174
	}
175
176
177
	/**
178
	 * Returns the frontend controller
179
	 *
180
	 * @return \Aimeos\Controller\Frontend\Common\Iface Frontend controller object
181
	 */
182
	protected function getController()
183
	{
184
		return $this->controller;
185
	}
186
}
187