Completed
Push — master ( b6a2ec...b3bd8f )
by Alexander
01:55
created

Container::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 70
Code Lines 40

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 1.2035

Importance

Changes 0
Metric Value
dl 0
loc 70
ccs 14
cts 34
cp 0.4118
rs 9.1724
c 0
b 0
f 0
cc 1
eloc 40
nc 1
nop 1
crap 1.2035

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
 * This file is part of the Code-Insight library.
4
 * For the full copyright and license information, please view
5
 * the LICENSE file that was distributed with this source code.
6
 *
7
 * @copyright Alexander Obuhovich <[email protected]>
8
 * @link      https://github.com/console-helpers/code-insight
9
 */
10
11
namespace ConsoleHelpers\CodeInsight;
12
13
14
use ConsoleHelpers\CodeInsight\BackwardsCompatibility\BreakFilter;
15
use ConsoleHelpers\CodeInsight\BackwardsCompatibility\Checker\CheckerFactory;
16
use ConsoleHelpers\CodeInsight\BackwardsCompatibility\Checker\ClassChecker;
17
use ConsoleHelpers\CodeInsight\BackwardsCompatibility\Checker\ConstantChecker;
18
use ConsoleHelpers\CodeInsight\BackwardsCompatibility\Checker\FunctionChecker;
19
use ConsoleHelpers\CodeInsight\BackwardsCompatibility\Checker\InPortalClassChecker;
20
use ConsoleHelpers\CodeInsight\BackwardsCompatibility\Reporter\HtmlReporter;
21
use ConsoleHelpers\CodeInsight\BackwardsCompatibility\Reporter\JsonReporter;
22
use ConsoleHelpers\CodeInsight\BackwardsCompatibility\Reporter\ReporterFactory;
23
use ConsoleHelpers\CodeInsight\BackwardsCompatibility\Reporter\TextReporter;
24
use ConsoleHelpers\CodeInsight\Cache\CacheFactory;
25
use ConsoleHelpers\CodeInsight\KnowledgeBase\DatabaseManager;
26
use ConsoleHelpers\CodeInsight\KnowledgeBase\KnowledgeBaseFactory;
27
use ConsoleHelpers\ConsoleKit\Config\ConfigEditor;
28
use ConsoleHelpers\DatabaseMigration\MigrationManager;
29
use ConsoleHelpers\DatabaseMigration\PhpMigrationRunner;
30
use ConsoleHelpers\DatabaseMigration\SqlMigrationRunner;
31
32
class Container extends \ConsoleHelpers\ConsoleKit\Container
33
{
34
35
	/**
36
	 * {@inheritdoc}
37
	 */
38 34
	public function __construct(array $values = array())
39
	{
40 34
		parent::__construct($values);
41
42 34
		$this['app_name'] = 'Code-Insight';
43 34
		$this['app_version'] = '@git-version@';
44
45 34
		$this['working_directory_sub_folder'] = '.code-insight';
46
47 34
		$this['config_defaults'] = array(
48 34
			'cache.provider' => '',
49
		);
50
51
		$this['project_root_folder'] = function () {
52 34
			return dirname(dirname(__DIR__));
53
		};
54
55
		$this['migration_manager'] = function ($c) {
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $c. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
56 34
			$migrations_directory = $c['project_root_folder'] . '/migrations';
57 34
			$migration_manager = new MigrationManager($migrations_directory, $c);
58 34
			$migration_manager->registerMigrationRunner(new SqlMigrationRunner());
59 34
			$migration_manager->registerMigrationRunner(new PhpMigrationRunner());
60
61 34
			return $migration_manager;
62
		};
63
64
		$this['db_manager'] = function ($c) {
65
			return new DatabaseManager($c['migration_manager'], $c['working_directory']);
66
		};
67
68
		$this['knowledge_base_factory'] = function ($c) {
69
			return new KnowledgeBaseFactory($c['db_manager']);
70
		};
71
72
		$this['bc_checker_factory'] = function ($c) {
73
			$cache = $c['cache'];
74
75
			$factory = new CheckerFactory();
76
			$factory->add(new ClassChecker($cache));
77
			$factory->add(new FunctionChecker($cache));
78
			$factory->add(new ConstantChecker($cache));
79
80
			$factory->add(new InPortalClassChecker($cache));
81
82
			return $factory;
83
		};
84
85
		$this['bc_reporter_factory'] = function ($c) {
86
			$factory = new ReporterFactory();
87
			$factory->add(new TextReporter());
88
			$factory->add(new HtmlReporter());
89
			$factory->add(new JsonReporter());
90
91
			return $factory;
92
		};
93
94
		$this['bc_break_filter'] = function ($c) {
95
			return new BreakFilter();
96
		};
97
98
		$this['cache'] = function ($c) {
99
			/** @var ConfigEditor $config_editor */
100
			$config_editor = $c['config_editor'];
101
			$cache_provider = $config_editor->get('cache.provider');
102
103
			$cache_factory = new CacheFactory('');
104
105
			return $cache_factory->create('chain', array('array', $cache_provider));
106
		};
107 34
	}
108
109
}
110