| Conditions | 1 |
| Paths | 1 |
| Total Lines | 52 |
| Code Lines | 28 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 86 | private static function createContext( $site ) |
||
| 87 | { |
||
| 88 | $ctx = new \Aimeos\MShop\Context(); |
||
| 89 | $aimeos = self::getAimeos(); |
||
| 90 | |||
| 91 | |||
| 92 | $paths = $aimeos->getConfigPaths(); |
||
| 93 | $paths[] = __DIR__ . DIRECTORY_SEPARATOR . 'config'; |
||
| 94 | $file = __DIR__ . DIRECTORY_SEPARATOR . 'confdoc.ser'; |
||
| 95 | |||
| 96 | $conf = new \Aimeos\Base\Config\PHPArray( ['client' => ['jsonapi' => ['debug' => true]]], $paths ); |
||
| 97 | $conf = new \Aimeos\Base\Config\Decorator\Memory( $conf ); |
||
| 98 | $conf = new \Aimeos\Base\Config\Decorator\Documentor( $conf, $file ); |
||
| 99 | $ctx->setConfig( $conf ); |
||
| 100 | |||
| 101 | |||
| 102 | $dbm = new \Aimeos\Base\DB\Manager\Standard( $conf->get( 'resource', [] ), 'DBAL' ); |
||
| 103 | $ctx->setDatabaseManager( $dbm ); |
||
| 104 | |||
| 105 | |||
| 106 | $mq = new \Aimeos\Base\MQueue\Manager\Standard( $conf->get( 'resource', [] ) ); |
||
| 107 | $ctx->setMessageQueueManager( $mq ); |
||
| 108 | |||
| 109 | |||
| 110 | $logger = new \Aimeos\Base\Logger\File( $site . '.log', \Aimeos\Base\Logger\Iface::DEBUG ); |
||
| 111 | $ctx->setLogger( $logger ); |
||
| 112 | |||
| 113 | |||
| 114 | $cache = new \Aimeos\Base\Cache\None(); |
||
| 115 | $ctx->setCache( $cache ); |
||
| 116 | |||
| 117 | |||
| 118 | $i18n = new \Aimeos\Base\Translation\None( 'en' ); |
||
| 119 | $ctx->setI18n( array( 'en' => $i18n ) ); |
||
| 120 | |||
| 121 | |||
| 122 | $passwd = new \Aimeos\Base\Password\Standard(); |
||
| 123 | $ctx->setPassword( $passwd ); |
||
| 124 | |||
| 125 | |||
| 126 | $session = new \Aimeos\Base\Session\None(); |
||
| 127 | $ctx->setSession( $session ); |
||
| 128 | |||
| 129 | |||
| 130 | $localeManager = \Aimeos\MShop::create( $ctx, 'locale' ); |
||
| 131 | $locale = $localeManager->bootstrap( $site, '', '', false ); |
||
| 132 | $ctx->setLocale( $locale ); |
||
| 133 | |||
| 134 | |||
| 135 | $ctx->setEditor( 'ai-client-jsonapi' ); |
||
| 136 | |||
| 137 | return $ctx; |
||
| 138 | } |
||
| 140 |