• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

aimeos / aimeos-core / 4f8b7e8d-5595-43b2-ba5c-df9921830178

17 May 2026 07:32AM UTC coverage: 92.581%. Remained the same
4f8b7e8d-5595-43b2-ba5c-df9921830178

push

circleci

aimeos
Fixed PHPStan issues

896 of 980 new or added lines in 165 files covered. (91.43%)

35 existing lines in 29 files now uncovered.

9734 of 10514 relevant lines covered (92.58%)

80.53 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.86
/src/MShop/Customer/Manager/Base.php
1
<?php
2

3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2026
6
 * @package MShop
7
 * @subpackage Customer
8
 */
9

10

11
namespace Aimeos\MShop\Customer\Manager;
12

13

14
/**
15
 * Base class with common methods for all customer implementations.
16
 *
17
 * @package MShop
18
 * @subpackage Customer
19
 */
20
abstract class Base
21
        extends \Aimeos\MShop\Common\Manager\Base
22
{
23
        /**
24
         * Counts the number items that are available for the values of the given key.
25
         *
26
         * @param \Aimeos\Base\Criteria\Iface $search Search criteria
27
         * @param array|string $key Search key or list of key to aggregate items for
28
         * @param string|null $value Search key for aggregating the value column
29
         * @param string|null $type Type of the aggregation, empty string for count or "sum" or "avg" (average)
30
         * @return \Aimeos\Map List of the search keys as key and the number of counted items as value
31
         */
32
        public function aggregate( \Aimeos\Base\Criteria\Iface $search, $key, ?string $value = null, ?string $type = null ) : \Aimeos\Map
33
        {
34
                /** mshop/customer/manager/aggregate/mysql
35
                 * Counts the number of records grouped by the values in the key column and matched by the given criteria
36
                 *
37
                 * @see mshop/customer/manager/aggregate/ansi
38
                 */
39

40
                /** mshop/customer/manager/aggregate/ansi
41
                 * Counts the number of records grouped by the values in the key column and matched by the given criteria
42
                 *
43
                 * Groups all records by the values in the key column and counts their
44
                 * occurence. The matched records can be limited by the given criteria
45
                 * from the customer database. The records must be from one of the sites
46
                 * that are configured via the context item. If the current site is part
47
                 * of a tree of sites, the statement can count all records from the
48
                 * current site and the complete sub-tree of sites.
49
                 *
50
                 * As the records can normally be limited by criteria from sub-managers,
51
                 * their tables must be joined in the SQL context. This is done by
52
                 * using the "internaldeps" property from the definition of the ID
53
                 * column of the sub-managers. These internal dependencies specify
54
                 * the JOIN between the tables and the used columns for joining. The
55
                 * ":joins" placeholder is then replaced by the JOIN strings from
56
                 * the sub-managers.
57
                 *
58
                 * To limit the records matched, conditions can be added to the given
59
                 * criteria object. It can contain comparisons like column names that
60
                 * must match specific values which can be combined by AND, OR or NOT
61
                 * operators. The resulting string of SQL conditions replaces the
62
                 * ":cond" placeholder before the statement is sent to the database
63
                 * server.
64
                 *
65
                 * This statement doesn't return any records. Instead, it returns pairs
66
                 * of the different values found in the key column together with the
67
                 * number of records that have been found for that key values.
68
                 *
69
                 * The SQL statement should conform to the ANSI standard to be
70
                 * compatible with most relational database systems. This also
71
                 * includes using double quotes for table and column names.
72
                 *
73
                 * @type string SQL statement for aggregating customer items
74
                 * @since 2021.04
75
                 * @see mshop/customer/manager/insert/ansi
76
                 * @see mshop/customer/manager/update/ansi
77
                 * @see mshop/customer/manager/newid/ansi
78
                 * @see mshop/customer/manager/delete/ansi
79
                 * @see mshop/customer/manager/search/ansi
80
                 * @see mshop/customer/manager/count/ansi
81
                 */
82

83
                $cfgkey = 'mshop/customer/manager/aggregate';
2✔
84
                return $this->aggregateBase( $search, $key, $cfgkey, ['customer'], $value, $type );
2✔
85
        }
86

87

88
        /**
89
         * Creates a filter object.
90
         *
91
         * @param bool|null $default Add default criteria or NULL for relaxed default criteria
92
         * @param bool $site TRUE for adding site criteria to limit items by the site of related items
93
         * @return \Aimeos\Base\Criteria\Iface Returns the filter object
94
         */
95
        public function filter( ?bool $default = false, bool $site = false ) : \Aimeos\Base\Criteria\Iface
96
        {
97
                return $this->filterBase( 'customer', $default );
39✔
98
        }
99

100

101
        /**
102
         * Returns the item specified by its code and domain/type if necessary
103
         *
104
         * @param string $code Code of the item
105
         * @param string[] $ref List of domains to fetch list items and referenced items for
106
         * @param string|null $domain Domain of the item if necessary to identify the item uniquely
107
         * @param string|null $type Type code of the item if necessary to identify the item uniquely
108
         * @param bool|null $default Add default criteria or NULL for relaxed default criteria
109
         * @return \Aimeos\MShop\Customer\Item\Iface Item object
110
         */
111
        public function find( string $code, array $ref = [], ?string $domain = null, ?string $type = null,
112
                ?bool $default = false ) : \Aimeos\MShop\Common\Item\Iface
113
        {
114
                return $this->findBase( ['customer.code' => $code], $ref, $default ); // @phpstan-ignore return.type
21✔
115
        }
116

117

118
        /**
119
         * Returns the customer item object specificed by its ID.
120
         *
121
         * @param string $id Unique customer ID referencing an existing customer
122
         * @param string[] $ref List of domains to fetch list items and referenced items for
123
         * @param bool|null $default Add default criteria or NULL for relaxed default criteria
124
         * @return \Aimeos\MShop\Customer\Item\Iface Returns the customer item of the given id
125
         * @throws \Aimeos\MShop\Exception If item couldn't be found
126
         */
127
        public function get( string $id, array $ref = [], ?bool $default = false ) : \Aimeos\MShop\Common\Item\Iface
128
        {
129
                return $this->getItemBase( 'customer.id', $id, $ref, $default ); // @phpstan-ignore return.type
5✔
130
        }
131

132

133
        /**
134
         * Adds the customer to the groups listed in the customer item
135
         *
136
         * @param \Aimeos\MShop\Customer\Item\Iface $item Customer item
137
         * @return \Aimeos\MShop\Customer\Item\Iface $item Modified customer item
138
         */
139
        protected function addGroups( \Aimeos\MShop\Customer\Item\Iface $item ): \Aimeos\MShop\Customer\Item\Iface
140
        {
141
                $pos = 0;
3✔
142
                $groupIds = [];
3✔
143

144
                $manager = $this->object()->getSubManager( 'lists' );
3✔
145
                $listItems = $item->getListItems( 'group', 'default', null, false );
3✔
146

147
                foreach( $item->getGroups() as $refId )
3✔
148
                {
149
                        // @phpstan-ignore argument.type
150
                        if( ( $litem = $item->getListItem( 'group', 'default', $refId, false ) ) !== null ) {
1✔
151
                                unset( $listItems[$litem->getId()], $listItems['__group_default_' . $refId] );
×
152
                        } else {
153
                                $litem = $manager->create()->setType( 'default' );
1✔
154
                        }
155

156
                        // @phpstan-ignore argument.type
157
                        $item->addListItem( 'group', $litem->setRefId( $refId )->setPosition( $pos++ ) );
1✔
158
                }
159

160
                return $item->deleteListItems( $listItems );
3✔
161
        }
162

163

164
        /**
165
         * Creates a new customer item.
166
         *
167
         * @param array $values List of attributes for customer item
168
         * @param \Aimeos\MShop\Common\Item\Lists\Iface[] $listItems List of list items
169
         * @param \Aimeos\MShop\Common\Item\Iface[] $refItems List of referenced items
170
         * @param \Aimeos\MShop\Common\Item\Address\Iface[] $addrItems List of address items
171
         * @param \Aimeos\MShop\Common\Item\Property\Iface[] $propItems List of property items
172
         * @return \Aimeos\MShop\Customer\Item\Iface New customer item
173
         */
174
        protected function createItemBase( array $values = [], array $listItems = [], array $refItems = [],
175
                array $addrItems = [], array $propItems = [] ) : \Aimeos\MShop\Common\Item\Iface
176
        {
177
                $values['.listitems'] = $listItems;
×
178
                $values['.propitems'] = $propItems;
×
179
                $values['.addritems'] = $addrItems;
×
180

NEW
181
                return $this->create( $values ); // @phpstan-ignore return.type
×
182
        }
183

184

185
        /**
186
         * Deletes items.
187
         *
188
         * @param \Aimeos\MShop\Common\Item\Iface|\Aimeos\Map|array|string $items List of item objects or IDs of the items
189
         * @param string $cfgpath Configuration path to the SQL statement
190
         * @param bool $siteid If siteid should be used in the statement
191
         * @param string $name Name of the ID column
192
         * @return static Manager object for chaining method calls
193
         */
194
        protected function deleteItemsBase( $items, string $cfgpath, bool $siteid = true,
195
                string $name = 'id' ) : static
196
        {
197
                if( map( $items )->isEmpty() ) {
3✔
198
                        return $this;
×
199
                }
200

201
                $search = $this->object()->filter();
3✔
202
                $search->setConditions( $search->compare( '==', $name, $items ) );
3✔
203

204
                $types = array( $name => \Aimeos\Base\DB\Statement\Base::PARAM_STR );
3✔
205
                $translations = array( $name => '"' . $name . '"' );
3✔
206

207
                $cond = $search->getConditionSource( $types, $translations );
3✔
208
                $sql = str_replace( ':cond', (string) $cond, (string) $this->getSqlConfig( $cfgpath ) );
3✔
209

210
                $context = $this->context();
3✔
211
                $conn = $context->db( $this->getResourceName() );
3✔
212

213
                $stmt = $conn->create( (string) $sql );
3✔
214

215
                if( $siteid )
3✔
216
                {
217
                        $stmt->bind( 1, $context->locale()->getSiteId() . '%' );
3✔
218
                        $stmt->bind( 2, $context->user()?->getSiteId() );
3✔
219
                }
220

221
                $stmt->execute()->finish();
3✔
222

223
                return $this;
3✔
224
        }
225
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc