Completed
Push — master ( 31faa3...626087 )
by Aimeos
02:18
created

Base   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 178
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 2
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 getItem() 0 4 1
A getItems() 0 4 1
A searchItems() 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\Product\Decorator;
12
13
14
/**
15
 * Base for product frontend controller decorators
16
 *
17
 * @package Controller
18
 * @subpackage Frontend
19
 */
20
abstract class Base
21
	extends \Aimeos\Controller\Frontend\Base
2 ignored issues
show
Coding Style introduced by
The extends keyword must be on the same line as the class name
Loading history...
Coding Style introduced by
Expected 0 spaces between "Base" and comma; 1 found
Loading history...
22
	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...
23
{
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
		$iface = '\Aimeos\Controller\Frontend\Product\Iface';
36
		if( !( $controller instanceof $iface ) )
37
		{
38
			$msg = sprintf( 'Class "%1$s" does not implement interface "%2$s"', get_class( $controller ), $iface );
39
			throw new \Aimeos\Controller\Frontend\Exception( $msg );
40
		}
41
42
		$this->controller = $controller;
43
44
		parent::__construct( $context );
45
	}
46
47
48
	/**
49
	 * Passes unknown methods to wrapped objects.
50
	 *
51
	 * @param string $name Name of the method
52
	 * @param array $param List of method parameter
53
	 * @return mixed Returns the value of the called method
54
	 * @throws \Aimeos\Controller\Frontend\Exception If method call failed
55
	 */
56
	public function __call( $name, array $param )
57
	{
58
		return @call_user_func_array( array( $this->controller, $name ), $param );
59
	}
60
61
62
	/**
63
	 * Returns the given search filter with the conditions attached for filtering by attribute.
64
	 *
65
	 * @param \Aimeos\MW\Criteria\Iface $filter Criteria object used for product search
66
	 * @param array $attrIds List of attribute IDs for faceted search
67
	 * @param array $optIds List of OR-combined attribute IDs for faceted search
68
	 * @param array $attrIds Associative list of OR-combined attribute IDs per attribute type for faceted search
69
	 * @return \Aimeos\MW\Criteria\Iface Criteria object containing the conditions for searching
70
	 * @since 2017.03
71
	 */
72
	public function addFilterAttribute( \Aimeos\MW\Criteria\Iface $filter, array $attrIds, array $optIds, array $oneIds )
73
	{
74
		return $this->controller->addFilterAttribute( $filter, $attrIds, $optIds, $oneIds );
1 ignored issue
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Aimeos\Controller\Frontend\Iface as the method addFilterAttribute() does only exist in the following implementations of said interface: Aimeos\Controller\Frontend\Product\Decorator\Base, Aimeos\Controller\Frontend\Product\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...
75
	}
76
77
78
	/**
79
	 * Returns the given search filter with the conditions attached for filtering by category.
80
	 *
81
	 * @param \Aimeos\MW\Criteria\Iface $filter Criteria object used for product search
82
	 * @param string|array $catId Selected category by the user
83
	 * @param integer $level Constant for current category only, categories of next level (LEVEL_LIST) or whole subtree (LEVEL_SUBTREE)
84
	 * @param string|null $sort Sortation of the product list like "name", "code", "price" and "position", null for no sortation
85
	 * @param string $direction Sort direction of the product list ("+", "-")
86
	 * @param string $listtype List type of the product associated to the category, usually "default"
87
	 * @return \Aimeos\MW\Criteria\Iface Criteria object containing the conditions for searching
88
	 * @since 2017.03
89
	 */
90
	public function addFilterCategory( \Aimeos\MW\Criteria\Iface $filter, $catId,
91
		$level = \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE, $sort = null, $direction = '+', $listtype = 'default' )
92
	{
93
		return $this->controller->addFilterCategory( $filter, $catId, $level, $sort, $direction, $listtype );
1 ignored issue
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Aimeos\Controller\Frontend\Iface as the method addFilterCategory() does only exist in the following implementations of said interface: Aimeos\Controller\Frontend\Product\Decorator\Base, Aimeos\Controller\Frontend\Product\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...
94
	}
95
96
97
	/**
98
	 * Returns the given search filter with the conditions attached for filtering by text.
99
	 *
100
	 * @param \Aimeos\MW\Criteria\Iface $filter Criteria object used for product search
101
	 * @param string $input Search string entered by the user
102
	 * @param string|null $sort Sortation of the product list like "name", "code", "price" and "position", null for no sortation
103
	 * @param string $direction Sort direction of the product list ("+", "-")
104
	 * @param string $listtype List type of the text associated to the product, usually "default"
105
	 * @return \Aimeos\MW\Criteria\Iface Criteria object containing the conditions for searching
106
	 * @since 2017.03
107
	 */
108
	public function addFilterText( \Aimeos\MW\Criteria\Iface $filter, $input, $sort = null, $direction = '+', $listtype = 'default' )
109
	{
110
		return $this->controller->addFilterText( $filter, $input, $sort, $direction, $listtype );
1 ignored issue
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Aimeos\Controller\Frontend\Iface as the method addFilterText() does only exist in the following implementations of said interface: Aimeos\Controller\Frontend\Product\Decorator\Base, Aimeos\Controller\Frontend\Product\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...
111
	}
112
113
114
	/**
115
	 * Returns the aggregated count of products from the product for the given key.
116
	 *
117
	 * @param \Aimeos\MW\Criteria\Iface $filter Critera object which contains the filter conditions
118
	 * @param string $key Search key to aggregate for, e.g. "product.attribute.id"
119
	 * @return array Associative list of key values as key and the product count for this key as value
120
	 * @since 2015.08
121
	 */
122
	public function aggregate( \Aimeos\MW\Criteria\Iface $filter, $key )
123
	{
124
		return $this->controller->aggregate( $filter, $key );
1 ignored issue
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Aimeos\Controller\Frontend\Iface as the method aggregate() does only exist in the following implementations of said interface: Aimeos\Controller\Frontend\Product\Decorator\Base, Aimeos\Controller\Frontend\Product\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...
125
	}
126
127
128
	/**
129
	 * Returns the default product filter.
130
	 *
131
	 * @param string|null $sort Sortation of the product list like "name", "code", "price" and "position", null for no sortation
132
	 * @param string $direction Sort direction of the product list ("+", "-")
133
	 * @param integer $start Position in the list of found products where to begin retrieving the items
134
	 * @param integer $size Number of products that should be returned
135
	 * @param string $listtype Type of the product list, e.g. default, promotion, etc.
136
	 * @return \Aimeos\MW\Criteria\Iface Criteria object containing the conditions for searching
137
	 * @since 2015.08
138
	 */
139
	public function createFilter( $sort = null, $direction = '+', $start = 0, $size = 100, $listtype = 'default' )
140
	{
141
		return $this->controller->createFilter( $sort, $direction, $start, $size, $listtype );
1 ignored issue
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Aimeos\Controller\Frontend\Iface as the method createFilter() does only exist in the following implementations of said interface: Aimeos\Controller\Fronte...ttribute\Decorator\Base, Aimeos\Controller\Frontend\Attribute\Standard, Aimeos\Controller\Frontend\Catalog\Decorator\Base, Aimeos\Controller\Frontend\Catalog\Standard, Aimeos\Controller\Frontend\Product\Decorator\Base, Aimeos\Controller\Frontend\Product\Standard, Aimeos\Controller\Frontend\Stock\Decorator\Base, Aimeos\Controller\Frontend\Stock\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...
142
	}
143
144
145
	/**
146
	 * Returns the product for the given product ID from the product
147
	 *
148
	 * @param string $productId Unique product ID
149
	 * @param string[] $domains Domain names of items that are associated with the products and that should be fetched too
150
	 * @return \Aimeos\MShop\Product\Item\Iface Product item including the referenced domains items
151
	 * @since 2017.03
152
	 */
153
	public function getItem( $productId, array $domains = array( 'attribute', 'media', 'price', 'product', 'product/property', 'text' ) )
154
	{
155
		return $this->controller->getItem( $productId, $domains );
1 ignored issue
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Aimeos\Controller\Frontend\Iface as the method getItem() does only exist in the following implementations of said interface: Aimeos\Controller\Fronte...ttribute\Decorator\Base, Aimeos\Controller\Frontend\Attribute\Standard, Aimeos\Controller\Frontend\Product\Decorator\Base, Aimeos\Controller\Frontend\Product\Standard, Aimeos\Controller\Frontend\Stock\Decorator\Base, Aimeos\Controller\Frontend\Stock\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...
156
	}
157
158
159
	/**
160
	 * Returns the product for the given product ID from the product
161
	 *
162
	 * @param string[] $productIds List of unique product ID
163
	 * @param string[] $domains Domain names of items that are associated with the products and that should be fetched too
164
	 * @return \Aimeos\MShop\Product\Item\Iface[] Associative list of product IDs as keys and product items as values
165
	 * @since 2017.03
166
	 */
167
	public function getItems( array $productIds, array $domains = array( 'media', 'price', 'text' ) )
168
	{
169
		return $this->controller->getItems( $productIds, $domains );
1 ignored issue
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Aimeos\Controller\Frontend\Iface as the method getItems() does only exist in the following implementations of said interface: Aimeos\Controller\Frontend\Product\Decorator\Base, Aimeos\Controller\Frontend\Product\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...
170
	}
171
172
173
	/**
174
	 * Returns the products from the product filtered by the given criteria object.
175
	 *
176
	 * @param \Aimeos\MW\Criteria\Iface $filter Critera object which contains the filter conditions
177
	 * @param string[] $domains Domain names of items that are associated with the products and that should be fetched too
178
	 * @param integer &$total Parameter where the total number of found products will be stored in
179
	 * @return array Ordered list of product items implementing \Aimeos\MShop\Product\Item\Iface
180
	 * @since 2015.08
181
	 */
182
	public function searchItems( \Aimeos\MW\Criteria\Iface $filter, array $domains = array( 'media', 'price', 'text' ), &$total = null )
183
	{
184
		return $this->controller->searchItems( $filter, $domains, $total );
1 ignored issue
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Aimeos\Controller\Frontend\Iface as the method searchItems() does only exist in the following implementations of said interface: Aimeos\Controller\Fronte...ttribute\Decorator\Base, Aimeos\Controller\Frontend\Attribute\Standard, Aimeos\Controller\Frontend\Product\Decorator\Base, Aimeos\Controller\Frontend\Product\Standard, Aimeos\Controller\Frontend\Stock\Decorator\Base, Aimeos\Controller\Frontend\Stock\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...
185
	}
186
187
188
	/**
189
	 * Returns the frontend controller
190
	 *
191
	 * @return \Aimeos\Controller\Frontend\Product\Iface Frontend controller object
192
	 */
193
	protected function getController()
194
	{
195
		return $this->controller;
196
	}
197
}
198