• 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

84.0
/src/MShop/Service/Manager/Base.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-2026
7
 * @package MShop
8
 * @subpackage Service
9
 */
10

11

12
namespace Aimeos\MShop\Service\Manager;
13

14

15
/**
16
 * Abstract class for service managers.
17
 *
18
 * @package MShop
19
 * @subpackage Service
20
 */
21
abstract class Base
22
        extends \Aimeos\MShop\Common\Manager\Base
23
{
24
        /**
25
         * Returns the service provider which is responsible for the service item.
26
         *
27
         * @param \Aimeos\MShop\Service\Item\Iface $item Delivery or payment service item object
28
         * @param string $type Service type code
29
         * @return \Aimeos\MShop\Service\Provider\Iface Service provider object
30
         * @throws \LogicException If provider couldn't be found
31
         */
32
        public function getProvider( \Aimeos\MShop\Service\Item\Iface $item, string $type ) : \Aimeos\MShop\Service\Provider\Iface
33
        {
34
                $type = ucwords( $type );
13✔
35
                $context = $this->context();
13✔
36
                $names = explode( ',', $item->getProvider() );
13✔
37

38
                if( ctype_alnum( $type ) === false ) {
13✔
39
                        throw new \LogicException( sprintf( 'Invalid characters in type name "%1$s"', $type ), 400 );
×
40
                }
41

42
                if( ( $provider = array_shift( $names ) ) === null ) {
13✔
43
                        throw new \LogicException( sprintf( 'Provider in "%1$s" not available', $item->getProvider() ), 400 );
×
44
                }
45

46
                if( ctype_alnum( $provider ) === false ) {
13✔
47
                        throw new \LogicException( sprintf( 'Invalid characters in provider name "%1$s"', $provider ), 400 );
1✔
48
                }
49

50
                $classname = '\Aimeos\MShop\Service\Provider\\' . $type . '\\' . $provider;
13✔
51
                $interface = \Aimeos\MShop\Service\Provider\Factory\Iface::class;
13✔
52

53
                // @phpstan-ignore argument.type
54
                $provider = \Aimeos\Utils::create( $classname, [$context, $item], $interface );
13✔
55

56
                /** mshop/service/provider/delivery/decorators
57
                 * Adds a list of decorators to all delivery provider objects automatcally
58
                 *
59
                 * Decorators extend the functionality of a class by adding new aspects
60
                 * (e.g. log what is currently done), executing the methods of the underlying
61
                 * class only in certain conditions (e.g. only for logged in users) or
62
                 * modify what is returned to the caller.
63
                 *
64
                 * This option allows you to wrap decorators
65
                 * ("\Aimeos\MShop\Service\Provider\Decorator\*") around the delivery provider.
66
                 *
67
                 *  mshop/service/provider/delivery/decorators = array( 'decorator1' )
68
                 *
69
                 * This would add the decorator named "decorator1" defined by
70
                 * "\Aimeos\MShop\Service\Provider\Decorator\Decorator1" to all delivery provider
71
                 * objects.
72
                 *
73
                 * @type array List of decorator names
74
                 * @since 2014.03
75
                 * @see mshop/service/provider/payment/decorators
76
                 */
77

78
                /** mshop/service/provider/payment/decorators
79
                 * Adds a list of decorators to all payment provider objects automatcally
80
                 *
81
                 * Decorators extend the functionality of a class by adding new aspects
82
                 * (e.g. log what is currently done), executing the methods of the underlying
83
                 * class only in certain conditions (e.g. only for logged in users) or
84
                 * modify what is returned to the caller.
85
                 *
86
                 * This option allows you to wrap decorators
87
                 * ("\Aimeos\MShop\Service\Provider\Decorator\*") around the payment provider.
88
                 *
89
                 *  mshop/service/provider/payment/decorators = array( 'decorator1' )
90
                 *
91
                 * This would add the decorator named "decorator1" defined by
92
                 * "\Aimeos\MShop\Service\Provider\Decorator\Decorator1" to all payment provider
93
                 * objects.
94
                 *
95
                 * @type array List of decorator names
96
                 * @since 2014.03
97
                 * @see mshop/service/provider/delivery/decorators
98
                 */
99
                $decorators = $context->config()->get( 'mshop/service/provider/' . $item->getType() . '/decorators', [] );
13✔
100

101
                // @phpstan-ignore argument.type
102
                $provider = $this->addServiceDecorators( $item, $provider, $names );
13✔
103
                // @phpstan-ignore argument.type
104
                return $this->addServiceDecorators( $item, $provider, (array) $decorators );
13✔
105
        }
106

107

108
        /**
109
         * Wraps the named service decorators around the service provider.
110
         *
111
         * @param \Aimeos\MShop\Service\Item\Iface $serviceItem Service item object
112
         * @param \Aimeos\MShop\Service\Provider\Iface $provider Service provider object
113
         * @param array $names List of decorator names that should be wrapped around the provider object
114
         * @return \Aimeos\MShop\Service\Provider\Iface
115
         */
116
        protected function addServiceDecorators( \Aimeos\MShop\Service\Item\Iface $serviceItem,
117
                \Aimeos\MShop\Service\Provider\Iface $provider, array $names ) : \Aimeos\MShop\Service\Provider\Iface
118
        {
119
                $context = $this->context();
13✔
120
                $classprefix = '\Aimeos\MShop\Service\Provider\Decorator\\';
13✔
121

122
                foreach( $names as $name )
13✔
123
                {
124
                        if( ctype_alnum( $name ) === false )
1✔
125
                        {
126
                                $msg = $context->translate( 'mshop', 'Invalid characters in class name "%1$s"' );
×
NEW
127
                                throw new \Aimeos\MShop\Service\Exception( sprintf( $msg, (string) $name ), 400 );
×
128
                        }
129

130
                        $classname = $classprefix . $name;
1✔
131
                        $interface = \Aimeos\MShop\Service\Provider\Decorator\Iface::class;
1✔
132

133
                        $provider = \Aimeos\Utils::create( $classname, [$provider, $context, $serviceItem], $interface );
1✔
134
                }
135

136
                // @phpstan-ignore return.type
137
                return $provider;
13✔
138
        }
139
}
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