| Conditions | 13 |
| Paths | 1 |
| Total Lines | 111 |
| Code Lines | 69 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 12 | ||
| Bugs | 1 | Features | 2 |
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 |
||
| 262 | public function getServiceConfig() |
||
| 263 | { |
||
| 264 | return array( |
||
| 265 | |||
| 266 | 'aliases' => array( |
||
| 267 | 'playgroundcore_doctrine_em' => 'doctrine.entitymanager.orm_default', |
||
| 268 | 'google-analytics' => 'PlaygroundCore\Analytics\Tracker', |
||
| 269 | 'facebook-opengraph' => 'PlaygroundCore\Opengraph\Tracker', |
||
| 270 | 'twitter-card' => 'PlaygroundCore\TwitterCard\Config', |
||
| 271 | 'twilio' => 'playgroundcore_twilio', |
||
| 272 | 'ffmpeg' => 'playgroundcore_phpvideotoolkit' |
||
| 273 | ), |
||
| 274 | |||
| 275 | 'shared' => array( |
||
| 276 | 'playgroundcore_message' => false, |
||
| 277 | // don't want this service to be a singleton. I have to reset the ffmpeg parameters for each call. |
||
| 278 | 'playgroundcore_ffmpeg_service' => false |
||
| 279 | ), |
||
| 280 | |||
| 281 | 'invokables' => array( |
||
| 282 | 'Zend\Session\SessionManager' => 'Zend\Session\SessionManager', |
||
| 283 | 'playgroundcore_message' => 'PlaygroundCore\Mail\Service\Message', |
||
| 284 | 'playgroundcore_cron_service' => 'PlaygroundCore\Service\Cron', |
||
| 285 | 'playgroundcore_shortenurl_service' => 'PlaygroundCore\Service\ShortenUrl', |
||
| 286 | 'playgroundcore_website_service' => 'PlaygroundCore\Service\Website', |
||
| 287 | 'playgroundcore_locale_service' => 'PlaygroundCore\Service\Locale', |
||
| 288 | 'playgroundcore_formgen_service' => 'PlaygroundCore\Service\Formgen', |
||
| 289 | 'playgroundcore_image_service' => 'PlaygroundCore\Service\Image', |
||
| 290 | 'playgroundcore_ffmpeg_service' => 'PlaygroundCore\Service\Ffmpeg', |
||
| 291 | ), |
||
| 292 | 'factories' => array( |
||
| 293 | 'playgroundcore_module_options' => function (\Zend\ServiceManager\ServiceManager $sm) { |
||
| 294 | $config = $sm->get('Configuration'); |
||
| 295 | |||
| 296 | return new Options\ModuleOptions(isset($config['playgroundcore']) ? $config['playgroundcore'] : array()); |
||
| 297 | }, |
||
| 298 | |||
| 299 | 'playgroundcore_formgen_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
||
| 300 | return new Mapper\Formgen($sm->get('playgroundcore_doctrine_em'), $sm->get('playgroundcore_module_options')); |
||
| 301 | }, |
||
| 302 | |||
| 303 | 'playgroundcore_website_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
||
| 304 | |||
| 305 | return new Mapper\Website($sm->get('playgroundcore_doctrine_em'), $sm->get('playgroundcore_module_options')); |
||
| 306 | }, |
||
| 307 | |||
| 308 | 'playgroundcore_locale_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
||
| 309 | return new Mapper\Locale($sm->get('playgroundcore_doctrine_em'), $sm->get('playgroundcore_module_options')); |
||
| 310 | }, |
||
| 311 | |||
| 312 | 'playgroundcore_twilio' => 'PlaygroundCore\Service\Factory\TwilioServiceFactory', |
||
| 313 | 'playgroundcore_phpvideotoolkit' => 'PlaygroundCore\Service\Factory\PhpvideotoolkitServiceFactory', |
||
| 314 | 'playgroundcore_transport' => 'PlaygroundCore\Mail\Transport\Service\TransportFactory', |
||
| 315 | 'PlaygroundCore\Analytics\Tracker' => function (\Zend\ServiceManager\ServiceManager $sm) { |
||
| 316 | $config = $sm->get('config'); |
||
| 317 | $config = isset($config['playgroundcore']) ? $config['playgroundcore']['googleAnalytics'] : array('id' => 'UA-XXXXXXXX-X'); |
||
| 318 | |||
| 319 | $tracker = new Analytics\Tracker($config['id']); |
||
| 320 | |||
| 321 | if (isset($config['custom_vars'])) { |
||
| 322 | foreach ($config['custom_vars'] as $customVar) { |
||
| 323 | $customVarId = $customVar['id']; |
||
| 324 | $customVarName = $customVar['name']; |
||
| 325 | $customVarValue = $customVar['value']; |
||
| 326 | $customVarOptScope = $customVar['optScope']; |
||
| 327 | $customVar = new Analytics\CustomVar($customVarId, $customVarName, $customVarValue, $customVarOptScope); |
||
| 328 | $tracker->addCustomVar($customVar); |
||
| 329 | } |
||
| 330 | } |
||
| 331 | |||
| 332 | if (isset($config['domain_name'])) { |
||
| 333 | $tracker->setDomainName($config['domain_name']); |
||
| 334 | } |
||
| 335 | |||
| 336 | if (isset($config['allow_linker'])) { |
||
| 337 | $tracker->setAllowLinker($config['allow_linker']); |
||
| 338 | } |
||
| 339 | |||
| 340 | if (isset($config['allow_hash'])) { |
||
| 341 | $tracker->setAllowHash($config['allow_hash']); |
||
| 342 | } |
||
| 343 | |||
| 344 | return $tracker; |
||
| 345 | }, |
||
| 346 | 'PlaygroundCore\Opengraph\Tracker' => function (\Zend\ServiceManager\ServiceManager $sm) { |
||
| 347 | $config = $sm->get('config'); |
||
| 348 | $config = isset($config['playgroundcore']['facebookOpengraph']) ? $config['playgroundcore']['facebookOpengraph'] : array('appId' => ''); |
||
| 349 | |||
| 350 | $tracker = new Opengraph\Tracker($config['appId']); |
||
| 351 | |||
| 352 | if (isset($config['enable'])) { |
||
| 353 | $tracker->setEnableOpengraph($config['enable']); |
||
| 354 | } |
||
| 355 | |||
| 356 | if (isset($config['tags'])) { |
||
| 357 | foreach ($config['tags'] as $type => $value) { |
||
| 358 | $tag = new Opengraph\Tag($type, $value); |
||
| 359 | $tracker->addTag($tag); |
||
| 360 | } |
||
| 361 | } |
||
| 362 | |||
| 363 | return $tracker; |
||
| 364 | }, |
||
| 365 | 'PlaygroundCore\TwitterCard\Config' => function (\Zend\ServiceManager\ServiceManager $sm) { |
||
| 366 | $config = $sm->get('config'); |
||
| 367 | $config = isset($config['playgroundcore']['twitterCard']) ? $config['playgroundcore']['twitterCard'] : array(); |
||
| 368 | return new TwitterCard\Config($config); |
||
| 369 | }, |
||
| 370 | ), |
||
| 371 | ); |
||
| 372 | } |
||
| 373 | } |
||
| 374 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: