FuelServiceProvider::register()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 65
Code Lines 34

Duplication

Lines 21
Ratio 32.31 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 21
loc 65
rs 9.3571
cc 1
eloc 34
nc 1
nop 0

How to fix   Long Method   

Long Method

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:

1
<?php
2
/**
3
 * @package    Fuel\Common
4
 * @version    2.0
5
 * @author     Fuel Development Team
6
 * @license    MIT License
7
 * @copyright  2010 - 2015 Fuel Development Team
8
 * @link       http://fuelphp.com
9
 */
10
11
namespace Fuel\Common\Providers;
12
13
use League\Container\ServiceProvider;
14
use Fuel\Common;
15
16
/**
17
 * Fuel ServiceProvider class for Common
18
 *
19
 * @package Fuel\Common
20
 *
21
 * @since 2.0
22
 */
23
class FuelServiceProvider extends ServiceProvider
24
{
25
	/**
26
	 * @var array
27
	 */
28
	protected $provides = [
29
		'arr',
30
		'datacontainer',
31
		'cookiejar',
32
		'format',
33
		'date',
34
		'num',
35
		'str',
36
		'inflector',
37
		'debug'
38
	];
39
40
	/**
41
	 * {@inheritdoc}
42
	 */
43
	public function register()
44
	{
45
		$this->container->add('arr', 'Fuel\Common\Arr');
46
47
		$this->container->add('datacontainer', function (array $data = [], $readOnly = false)
48
		{
49
			return new Common\DataContainer($data, $readOnly);
50
		});
51
52
		// \Fuel\Common\CookieJar
53
		$this->container->add('cookiejar', function (array $config = [], array $data = [])
54
		{
55
			return new Common\CookieJar($config, $data);
56
		});
57
58 View Code Duplication
		$this->container->add('format', function ($data = null, $fromType = null, array $config = [])
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
59
		{
60
			$configInstance = $this->container->get('configInstance');
61
			$input = $this->container->get('inputInstance');
62
63
			$config = \Arr::merge($configInstance->load('format', true), $config);
64
65
			$inflector = $this->container->get('inflector');
66
67
			return new Common\Format($data, $fromType, $config, $input, $inflector);
68
		});
69
70
		$this->container->add('pagination', function ($view)
71
		{
72
			$input = $this->container->get('inputInstance');
73
			$viewManager = $this->container->get('viewManagerInstance');
74
75
			return new Common\Pagination($viewManager, $input, $view);
76
		});
77
78
		$this->container->add('date', function ($time = "now", $timezone = null, array $config = [])
79
		{
80
			$configInstance = $this->container->get('configInstance');
81
			$config = \Arr::merge($configInstance->load('date', true), $config);
82
83
			return new Common\Date($time, $timezone, $config);
84
		});
85
86 View Code Duplication
		$this->container->add('num', function (array $config = [], array $lang = [])
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
87
		{
88
			$configInstance = $this->container->get('configInstance');
89
			$langInstance = $this->container->get('langInstance');
90
91
			$config = \Arr::merge($configInstance->load('num', true), $config);
92
			$lang = \Arr::merge($langInstance->load('byteunits', true), $lang);
93
94
			return new Common\Num($config, $lang);
95
		});
96
97
		$this->container->singleton('str', 'Fuel\Common\Str');
98
99
		$this->container->singleton('inflector', 'Fuel\Common\Inflector')
100
			->withArgument(null)
101
			->withArgument('security')
102
			->withArgument('str');
103
104
		$this->container->singleton('debug', 'Fuel\Common\Debug')
105
			->withArgument(null)
106
			->withArgument('inflector');
107
	}
108
}
109