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

aimeos / aimeos-core / 18a2821b-9fed-4e27-8151-60c5375acb47

16 Aug 2024 11:47AM UTC coverage: 91.965% (-0.002%) from 91.967%
18a2821b-9fed-4e27-8151-60c5375acb47

push

circleci

aimeos
Removed unnecessary assignments in fromArray()

278 of 279 new or added lines in 40 files covered. (99.64%)

30 existing lines in 30 files now uncovered.

10244 of 11139 relevant lines covered (91.97%)

61.77 hits per line

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

94.12
/src/MShop/Plugin/Item/Standard.php
1
<?php
2

3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2011
6
 * @copyright Aimeos (aimeos.org), 2015-2024
7
 * @package MShop
8
 * @subpackage Plugin
9
 */
10

11

12
namespace Aimeos\MShop\Plugin\Item;
13

14

15
/**
16
 * Default implementation of plugin items.
17
 *
18
 * @package MShop
19
 * @subpackage Plugin
20
 */
21
class Standard
22
        extends \Aimeos\MShop\Common\Item\Base
23
        implements \Aimeos\MShop\Plugin\Item\Iface
24
{
25
        use \Aimeos\MShop\Common\Item\Config\Traits;
26

27

28
        /**
29
         * Returns the type of the plugin.
30
         *
31
         * @return string Plugin type
32
         */
33
        public function getType() : string
34
        {
35
                return $this->get( 'plugin.type', 'order' );
310✔
36
        }
37

38

39
        /**
40
         * Sets the new type of the plugin item.
41
         *
42
         * @param string $type New plugin type
43
         * @return \Aimeos\MShop\Plugin\Item\Iface Plugin item for chaining method calls
44
         */
45
        public function setType( string $type ) : \Aimeos\MShop\Common\Item\Iface
46
        {
47
                return $this->set( 'plugin.type', $this->checkCode( $type ) );
15✔
48
        }
49

50

51
        /**
52
         * Returns the provider of the plugin.
53
         *
54
         * @return string Plugin provider which is the short plugin class name
55
         */
56
        public function getProvider() : string
57
        {
58
                return $this->get( 'plugin.provider', '' );
309✔
59
        }
60

61

62
        /**
63
         * Sets the new provider of the plugin item which is the short
64
         * name of the plugin class name.
65
         *
66
         * @param string $provider Plugin provider, esp. short plugin class name
67
         * @return \Aimeos\MShop\Plugin\Item\Iface Plugin item for chaining method calls
68
         */
69
        public function setProvider( string $provider ) : \Aimeos\MShop\Plugin\Item\Iface
70
        {
71
                if( preg_match( '/^[A-Za-z0-9]+(,[A-Za-z0-9]+)*$/', $provider ) !== 1 ) {
17✔
72
                        throw new \Aimeos\MShop\Plugin\Exception( sprintf( 'Invalid provider name "%1$s"', $provider ) );
1✔
73
                }
74

75
                return $this->set( 'plugin.provider', $provider );
16✔
76
        }
77

78

79
        /**
80
         * Returns the name of the plugin item.
81
         *
82
         * @return string Label of the plugin item
83
         */
84
        public function getLabel() : string
85
        {
86
                return $this->get( 'plugin.label', '' );
5✔
87
        }
88

89

90
        /**
91
         * Sets the new label of the plugin item.
92
         *
93
         * @param string $label New label of the plugin item
94
         * @return \Aimeos\MShop\Plugin\Item\Iface Plugin item for chaining method calls
95
         */
96
        public function setLabel( string $label ) : \Aimeos\MShop\Plugin\Item\Iface
97
        {
98
                return $this->set( 'plugin.label', $label );
2✔
99
        }
100

101

102
        /**
103
         * Returns the configuration of the plugin item.
104
         *
105
         * @return array Custom configuration values
106
         */
107
        public function getConfig() : array
108
        {
109
                return $this->get( 'plugin.config', [] );
65✔
110
        }
111

112

113
        /**
114
         * Sets the new configuration for the plugin item.
115
         *
116
         * @param array $config Custom configuration values
117
         * @return \Aimeos\MShop\Plugin\Item\Iface Plugin item for chaining method calls
118
         */
119
        public function setConfig( array $config ) : \Aimeos\MShop\Common\Item\Iface
120
        {
121
                return $this->set( 'plugin.config', $config );
70✔
122
        }
123

124

125
        /**
126
         * Returns the position of the plugin item.
127
         *
128
         * @return int Position of the item
129
         */
130
        public function getPosition() : int
131
        {
132
                return $this->get( 'plugin.position', 0 );
4✔
133
        }
134

135

136
        /**
137
         * Sets the new position of the plugin item.
138
         *
139
         * @param int $position Position of the item
140
         * @return \Aimeos\MShop\Plugin\Item\Iface Plugin item for chaining method calls
141
         */
142
        public function setPosition( int $position ) : \Aimeos\MShop\Common\Item\Iface
143
        {
144
                return $this->set( 'plugin.position', $position );
2✔
145
        }
146

147

148
        /**
149
         * Returns the status of the plugin item.
150
         *
151
         * @return int Status of the item
152
         */
153
        public function getStatus() : int
154
        {
155
                return $this->get( 'plugin.status', 1 );
7✔
156
        }
157

158

159
        /**
160
         * Sets the new status of the plugin item.
161
         *
162
         * @param int $status Status of the item
163
         * @return \Aimeos\MShop\Plugin\Item\Iface Plugin item for chaining method calls
164
         */
165
        public function setStatus( int $status ) : \Aimeos\MShop\Common\Item\Iface
166
        {
167
                return $this->set( 'plugin.status', $status );
16✔
168
        }
169

170

171
        /**
172
         * Tests if the item is available based on status, time, language and currency
173
         *
174
         * @return bool True if available, false if not
175
         */
176
        public function isAvailable() : bool
177
        {
178
                return parent::isAvailable() && $this->getStatus() > 0;
2✔
179
        }
180

181

182
        /**
183
         * Sets the item values from the given array and removes that entries from the list
184
         *
185
         * @param array &$list Associative list of item keys and their values
186
         * @param bool True to set private properties too, false for public only
187
         * @return \Aimeos\MShop\Plugin\Item\Iface Plugin item for chaining method calls
188
         */
189
        public function fromArray( array &$list, bool $private = false ) : \Aimeos\MShop\Common\Item\Iface
190
        {
191
                $item = parent::fromArray( $list, $private );
1✔
192

193
                foreach( $list as $key => $value )
1✔
194
                {
195
                        switch( $key )
196
                        {
197
                                case 'plugin.type': $item->setType( $value ); break;
1✔
198
                                case 'plugin.label': $item->setLabel( $value ); break;
1✔
199
                                case 'plugin.provider': $item->setProvider( $value ); break;
1✔
200
                                case 'plugin.status': $item->setStatus( (int) $value ); break;
1✔
201
                                case 'plugin.config': $item->setConfig( (array) $value ); break;
1✔
NEW
202
                                case 'plugin.position': $item->setPosition( (int) $value ); break;
×
UNCOV
203
                                default: continue 2;
×
204
                        }
205

206
                        unset( $list[$key] );
1✔
207
                }
208

209
                return $item;
1✔
210
        }
211

212

213
        /**
214
         * Returns the item values as array.
215
         *
216
         * @param bool True to return private properties, false for public only
217
         * @return array Associative list of item properties and their values
218
         */
219
        public function toArray( bool $private = false ) : array
220
        {
221
                $list = parent::toArray( $private );
2✔
222

223
                $list['plugin.type'] = $this->getType();
2✔
224
                $list['plugin.label'] = $this->getLabel();
2✔
225
                $list['plugin.provider'] = $this->getProvider();
2✔
226
                $list['plugin.config'] = $this->getConfig();
2✔
227
                $list['plugin.status'] = $this->getStatus();
2✔
228
                $list['plugin.position'] = $this->getPosition();
2✔
229

230
                return $list;
2✔
231
        }
232

233
}
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