Passed
Push — main ( f9f23c...f7616c )
by Aimeos
05:03
created

Standard   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 190
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 40
c 1
b 0
f 0
dl 0
loc 190
rs 10
wmc 18

12 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 3 1
A find() 0 3 1
A uses() 0 4 1
A slice() 0 4 1
A compare() 0 4 1
A parse() 0 7 2
A has() 0 9 3
A __construct() 0 7 1
A sort() 0 13 4
A search() 0 4 1
A function() 0 3 1
A __clone() 0 3 1
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2021
6
 * @package Controller
7
 * @subpackage Frontend
8
 */
9
10
11
namespace Aimeos\Controller\Frontend\Cms;
12
13
14
/**
15
 * Default implementation of the cms frontend controller
16
 *
17
 * @package Controller
18
 * @subpackage Frontend
19
 */
20
class Standard
21
	extends \Aimeos\Controller\Frontend\Base
22
	implements Iface, \Aimeos\Controller\Frontend\Common\Iface
23
{
24
	private $conditions = [];
25
	private $domains = [];
26
	private $filter;
27
	private $manager;
28
29
30
	/**
31
	 * Common initialization for controller classes
32
	 *
33
	 * @param \Aimeos\MShop\Context\Item\Iface $context Common MShop context object
34
	 */
35
	public function __construct( \Aimeos\MShop\Context\Item\Iface $context )
36
	{
37
		parent::__construct( $context );
38
39
		$this->manager = \Aimeos\MShop::create( $context, 'cms' );
40
		$this->filter = $this->manager->filter( true );
41
		$this->conditions[] = $this->filter->getConditions();
42
	}
43
44
45
	/**
46
	 * Clones objects in controller and resets values
47
	 */
48
	public function __clone()
49
	{
50
		$this->filter = clone $this->filter;
51
	}
52
53
54
	/**
55
	 * Adds generic condition for filtering
56
	 *
57
	 * @param string $operator Comparison operator, e.g. "==", "!=", "<", "<=", ">=", ">", "=~", "~="
58
	 * @param string $key Search key defined by the cms manager, e.g. "cms.status"
59
	 * @param array|string $value Value or list of values to compare to
60
	 * @return \Aimeos\Controller\Frontend\Cms\Iface Cms controller for fluent interface
61
	 * @since 2021.04
62
	 */
63
	public function compare( string $operator, string $key, $value ) : Iface
64
	{
65
		$this->conditions[] = $this->filter->compare( $operator, $key, $value );
66
		return $this;
67
	}
68
69
70
	/**
71
	 * Returns the cms for the given cms code
72
	 *
73
	 * @param string $code Unique cms code
74
	 * @return \Aimeos\MShop\Cms\Item\Iface Cms item including the referenced domains items
75
	 * @since 2021.04
76
	 */
77
	public function find( string $code ) : \Aimeos\MShop\Cms\Item\Iface
78
	{
79
		return $this->manager->find( $code, $this->domains, null, null, true );
0 ignored issues
show
Bug introduced by
The method find() does not exist on Aimeos\MShop\Common\Manager\Iface. It seems like you code against a sub-type of said class. However, the method does not exist in Aimeos\MShop\Common\Manager\Decorator\Iface or Aimeos\MShop\Service\Manager\Lists\Type\Iface or Aimeos\MShop\Price\Manager\Iface or Aimeos\MShop\Attribute\Manager\Type\Iface or Aimeos\MShop\Review\Manager\Iface or Aimeos\MShop\Price\Manager\Lists\Type\Iface or Aimeos\MShop\Media\Manager\Type\Iface or Aimeos\MShop\Order\Manager\Base\Coupon\Iface or Aimeos\MShop\Common\Manager\Property\Iface or Aimeos\MShop\Customer\Manager\Property\Iface or Aimeos\MShop\Order\Manager\Base\Service\Iface or Aimeos\MShop\Order\Manager\Base\Iface or Aimeos\MShop\Price\Manager\Lists\Iface or Aimeos\MShop\Cms\Manager\Lists\Type\Iface or Aimeos\MShop\Supplier\Manager\Lists\Type\Iface or Aimeos\MShop\Order\Manag...Service\Attribute\Iface or Aimeos\MShop\Service\Manager\Lists\Iface or Aimeos\MShop\Tag\Manager\Type\Iface or Aimeos\MShop\Text\Manager\Lists\Iface or Aimeos\MShop\Price\Manager\Type\Iface or Aimeos\MShop\Locale\Manager\Currency\Iface or Aimeos\MShop\Order\Manag...Product\Attribute\Iface or Aimeos\MShop\Media\Manager\Lists\Type\Iface or Aimeos\MShop\Catalog\Manager\Lists\Iface or Aimeos\MShop\Tag\Manager\Iface or Aimeos\MShop\Coupon\Manager\Iface or Aimeos\MShop\Common\Manager\Lists\Iface or Aimeos\MShop\Service\Manager\Type\Iface or Aimeos\MShop\Product\Manager\Lists\Iface or Aimeos\MShop\Order\Manager\Iface or Aimeos\MShop\Media\Manager\Iface or Aimeos\MShop\Customer\Manager\Lists\Type\Iface or Aimeos\MShop\Attribute\Manager\Lists\Iface or Aimeos\MShop\Media\Manager\Lists\Iface or Aimeos\MShop\Plugin\Manager\Iface or Aimeos\MShop\Order\Manager\Base\Address\Iface or Aimeos\MShop\Product\Manager\Type\Iface or Aimeos\MShop\Supplier\Manager\Lists\Iface or Aimeos\MShop\Text\Manager\Iface or Aimeos\MAdmin\Job\Manager\Iface or Aimeos\MShop\Product\Manager\Lists\Type\Iface or Aimeos\MShop\Text\Manager\Lists\Type\Iface or Aimeos\MShop\Text\Manager\Type\Iface or Aimeos\MShop\Order\Manager\Status\Iface or Aimeos\MShop\Common\Manager\Address\Iface or Aimeos\MShop\Plugin\Manager\Type\Iface or Aimeos\MShop\Stock\Manager\Iface or Aimeos\MShop\Attribute\Manager\Property\Iface or Aimeos\MShop\Subscription\Manager\Iface or Aimeos\MShop\Product\Manager\Property\Iface or Aimeos\MShop\Locale\Manager\Language\Iface or Aimeos\MShop\Media\Manager\Property\Iface or Aimeos\MShop\Attribute\Manager\Lists\Type\Iface or Aimeos\MAdmin\Log\Manager\Iface or Aimeos\MShop\Cms\Manager\Lists\Iface or Aimeos\MShop\Locale\Manager\Iface or Aimeos\MAdmin\Cache\Manager\Iface or Aimeos\MShop\Order\Manager\Base\Product\Iface or Aimeos\MShop\Price\Manager\Property\Iface or Aimeos\MShop\Customer\Manager\Lists\Iface or Aimeos\MShop\Catalog\Manager\Lists\Type\Iface or Aimeos\MShop\Supplier\Manager\Address\Iface or Aimeos\MShop\Customer\Manager\Address\Iface. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

79
		return $this->manager->/** @scrutinizer ignore-call */ find( $code, $this->domains, null, null, true );
Loading history...
80
	}
81
82
83
	/**
84
	 * Creates a search function string for the given name and parameters
85
	 *
86
	 * @param string $name Name of the search function without parenthesis, e.g. "cms:has"
87
	 * @param array $params List of parameters for the search function with numeric keys starting at 0
88
	 * @return string Search function string that can be used in compare()
89
	 */
90
	public function function( string $name, array $params ) : string
91
	{
92
		return $this->filter->make( $name, $params );
93
	}
94
95
96
	/**
97
	 * Returns the cms for the given cms ID
98
	 *
99
	 * @param string $id Unique cms ID
100
	 * @return \Aimeos\MShop\Cms\Item\Iface Cms item including the referenced domains items
101
	 * @since 2021.04
102
	 */
103
	public function get( string $id ) : \Aimeos\MShop\Cms\Item\Iface
104
	{
105
		return $this->manager->get( $id, $this->domains, true );
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->manager->g..., $this->domains, true) returns the type Aimeos\MShop\Common\Item\Iface which includes types incompatible with the type-hinted return Aimeos\MShop\Cms\Item\Iface.
Loading history...
106
	}
107
108
109
	/**
110
	 * Adds a filter to return only items containing a reference to the given ID
111
	 *
112
	 * @param string $domain Domain name of the referenced item, e.g. "product"
113
	 * @param string|null $type Type code of the reference, e.g. "default" or null for all types
114
	 * @param string|null $refId ID of the referenced item of the given domain or null for all references
115
	 * @return \Aimeos\Controller\Frontend\Cms\Iface Cms controller for fluent interface
116
	 * @since 2019.10
117
	 */
118
	public function has( string $domain, string $type = null, string $refId = null ) : Iface
119
	{
120
		$params = [$domain];
121
		!$type ?: $params[] = $type;
122
		!$refId ?: $params[] = $refId;
123
124
		$func = $this->filter->make( 'cms:has', $params );
125
		$this->conditions[] = $this->filter->compare( '!=', $func, null );
126
		return $this;
127
	}
128
129
130
	/**
131
	 * Parses the given array and adds the conditions to the list of conditions
132
	 *
133
	 * @param array $conditions List of conditions, e.g. ['=~' => ['cms.label' => 'test']]
134
	 * @return \Aimeos\Controller\Frontend\Cms\Iface Cms controller for fluent interface
135
	 * @since 2021.04
136
	 */
137
	public function parse( array $conditions ) : Iface
138
	{
139
		if( ( $cond = $this->filter->parse( $conditions ) ) !== null ) {
140
			$this->conditions[] = $cond;
141
		}
142
143
		return $this;
144
	}
145
146
147
	/**
148
	 * Returns the cmss filtered by the previously assigned conditions
149
	 *
150
	 * @param int &$total Parameter where the total number of found cmss will be stored in
151
	 * @return \Aimeos\Map Ordered list of cms items implementing \Aimeos\MShop\Cms\Item\Iface
152
	 * @since 2021.04
153
	 */
154
	public function search( int &$total = null ) : \Aimeos\Map
155
	{
156
		$this->filter->setConditions( $this->filter->and( $this->conditions ) );
157
		return $this->manager->search( $this->filter, $this->domains, $total );
158
	}
159
160
161
	/**
162
	 * Sets the start value and the number of returned cms items for slicing the list of found cms items
163
	 *
164
	 * @param int $start Start value of the first cms item in the list
165
	 * @param int $limit Number of returned cms items
166
	 * @return \Aimeos\Controller\Frontend\Cms\Iface Cms controller for fluent interface
167
	 * @since 2021.04
168
	 */
169
	public function slice( int $start, int $limit ) : Iface
170
	{
171
		$this->filter->slice( $start, $limit );
172
		return $this;
173
	}
174
175
176
	/**
177
	 * Sets the sorting of the result list
178
	 *
179
	 * @param string|null $key Sorting key of the result list like "cms.label", null for no sorting
180
	 * @return \Aimeos\Controller\Frontend\Cms\Iface Cms controller for fluent interface
181
	 * @since 2021.04
182
	 */
183
	public function sort( string $key = null ) : Iface
184
	{
185
		$sort = [];
186
		$list = ( $key ? explode( ',', $key ) : [] );
187
188
		foreach( $list as $sortkey )
189
		{
190
			$direction = ( $sortkey[0] === '-' ? '-' : '+' );
191
			$sort[] = $this->filter->sort( $direction, ltrim( $sortkey, '+-' ) );
192
		}
193
194
		$this->filter->setSortations( $sort );
195
		return $this;
196
	}
197
198
199
	/**
200
	 * Sets the referenced domains that will be fetched too when retrieving items
201
	 *
202
	 * @param array $domains Domain names of the referenced items that should be fetched too
203
	 * @return \Aimeos\Controller\Frontend\Cms\Iface Cms controller for fluent interface
204
	 * @since 2021.04
205
	 */
206
	public function uses( array $domains ) : Iface
207
	{
208
		$this->domains = $domains;
209
		return $this;
210
	}
211
}
212