Completed
Push — master ( b85bec...862a1a )
by Alexander
05:15
created

Container::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 66
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 66
ccs 13
cts 13
cp 1
rs 9.3191
c 0
b 0
f 0
cc 1
eloc 38
nc 1
nop 1
crap 1

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\Checker\CheckerFactory;
15
use ConsoleHelpers\CodeInsight\BackwardsCompatibility\Checker\ClassChecker;
16
use ConsoleHelpers\CodeInsight\BackwardsCompatibility\Checker\ConstantChecker;
17
use ConsoleHelpers\CodeInsight\BackwardsCompatibility\Checker\FunctionChecker;
18
use ConsoleHelpers\CodeInsight\BackwardsCompatibility\Checker\InPortalClassChecker;
19
use ConsoleHelpers\CodeInsight\BackwardsCompatibility\Reporter\HtmlReporter;
20
use ConsoleHelpers\CodeInsight\BackwardsCompatibility\Reporter\JsonReporter;
21
use ConsoleHelpers\CodeInsight\BackwardsCompatibility\Reporter\ReporterFactory;
22
use ConsoleHelpers\CodeInsight\BackwardsCompatibility\Reporter\TextReporter;
23
use ConsoleHelpers\CodeInsight\Cache\CacheFactory;
24
use ConsoleHelpers\CodeInsight\KnowledgeBase\DatabaseManager;
25
use ConsoleHelpers\CodeInsight\KnowledgeBase\KnowledgeBaseFactory;
26
use ConsoleHelpers\ConsoleKit\Config\ConfigEditor;
27
use ConsoleHelpers\DatabaseMigration\MigrationManager;
28
use ConsoleHelpers\DatabaseMigration\PhpMigrationRunner;
29
use ConsoleHelpers\DatabaseMigration\SqlMigrationRunner;
30
31
class Container extends \ConsoleHelpers\ConsoleKit\Container
32
{
33
34
	/**
35
	 * {@inheritdoc}
36
	 */
37 34
	public function __construct(array $values = array())
38
	{
39 34
		parent::__construct($values);
40
41 34
		$this['app_name'] = 'Code-Insight';
42 34
		$this['app_version'] = '@git-version@';
43
44 34
		$this['working_directory_sub_folder'] = '.code-insight';
45
46 34
		$this['config_defaults'] = array(
47
			'cache.provider' => '',
48
		);
49
50
		$this['project_root_folder'] = function () {
51 34
			return dirname(dirname(__DIR__));
52
		};
53
54
		$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...
55 34
			$migrations_directory = $c['project_root_folder'] . '/migrations';
56 34
			$migration_manager = new MigrationManager($migrations_directory, $c);
57 34
			$migration_manager->registerMigrationRunner(new SqlMigrationRunner());
58 34
			$migration_manager->registerMigrationRunner(new PhpMigrationRunner());
59
60 34
			return $migration_manager;
61
		};
62
63
		$this['db_manager'] = function ($c) {
64
			return new DatabaseManager($c['migration_manager'], $c['working_directory']);
65
		};
66
67
		$this['knowledge_base_factory'] = function ($c) {
68
			return new KnowledgeBaseFactory($c['db_manager']);
69
		};
70
71
		$this['bc_checker_factory'] = function ($c) {
72
			$cache = $c['cache'];
73
74
			$factory = new CheckerFactory();
75
			$factory->add(new ClassChecker($cache));
76
			$factory->add(new FunctionChecker($cache));
77
			$factory->add(new ConstantChecker($cache));
78
79
			$factory->add(new InPortalClassChecker($cache));
80
81
			return $factory;
82
		};
83
84
		$this['bc_reporter_factory'] = function ($c) {
85
			$factory = new ReporterFactory();
86
			$factory->add(new TextReporter());
87
			$factory->add(new HtmlReporter());
88
			$factory->add(new JsonReporter());
89
90
			return $factory;
91
		};
92
93
		$this['cache'] = function ($c) {
94
			/** @var ConfigEditor $config_editor */
95
			$config_editor = $c['config_editor'];
96
			$cache_provider = $config_editor->get('cache.provider');
97
98
			$cache_factory = new CacheFactory('');
99
100
			return $cache_factory->create('chain', array('array', $cache_provider));
101
		};
102 34
	}
103
104
}
105