| Conditions | 2 |
| Paths | 1 |
| Total Lines | 108 |
| Code Lines | 64 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 28 | public function __construct(Config $config) { |
||
| 29 | $this["config"] = $config; |
||
| 30 | |||
| 31 | $this["ruleset"] = function($c) { |
||
| 32 | $rule_file_path = $c["config"]->project_rules(); |
||
| 33 | if (!file_exists($rule_file_path)) { |
||
| 34 | throw new \RuntimeException("Unknown rule-file '$rule_file_path'"); |
||
| 35 | } |
||
| 36 | $ruleset = $c["rule_loader"]->load_rules_from($rule_file_path); |
||
| 37 | return $ruleset; |
||
| 38 | }; |
||
| 39 | |||
| 40 | $this["rule_loader"] = function($c) { |
||
| 41 | return new RuleLoader($c["rule_parser"]); |
||
| 42 | }; |
||
| 43 | |||
| 44 | $this["rule_parser"] = function($c) { |
||
| 45 | return new RuleParser |
||
| 46 | ( $c["variables"] |
||
| 47 | , $c["schemas"] |
||
| 48 | , $c["properties"] |
||
| 49 | ); |
||
| 50 | }; |
||
| 51 | |||
| 52 | $this["engine"] = function($c) { |
||
| 53 | return new Engine |
||
| 54 | ( $c["log"] |
||
| 55 | , $c["config"] |
||
| 56 | , $c["database_factory"] |
||
| 57 | , $c["indexer_factory"] |
||
| 58 | , $c["analyzer_factory"] |
||
| 59 | , $c["analysis_listener"] |
||
| 60 | , $c["source_status"] |
||
| 61 | ); |
||
| 62 | }; |
||
| 63 | |||
| 64 | $this["log"] = function () { |
||
| 65 | return new CLILogger(); |
||
| 66 | }; |
||
| 67 | |||
| 68 | $this["database_factory"] = function() { |
||
| 69 | return new DBFactory(); |
||
| 70 | }; |
||
| 71 | |||
| 72 | $this["indexer_factory"] = function($c) { |
||
| 73 | return new \Lechimp\Dicto\Indexer\IndexerFactory |
||
| 74 | ( $c["log"] |
||
| 75 | , $c["php_parser"] |
||
| 76 | , array |
||
| 77 | ( new \Lechimp\Dicto\Rules\ContainText() |
||
| 78 | , new \Lechimp\Dicto\Rules\DependOn() |
||
| 79 | , new \Lechimp\Dicto\Rules\Invoke() |
||
| 80 | ) |
||
| 81 | ); |
||
| 82 | }; |
||
| 83 | |||
| 84 | $this["analyzer_factory"] = function($c) { |
||
| 85 | return new \Lechimp\Dicto\Analysis\AnalyzerFactory |
||
| 86 | ( $c["log"] |
||
| 87 | , $c["ruleset"] |
||
| 88 | ); |
||
| 89 | }; |
||
| 90 | |||
| 91 | $this["php_parser"] = function() { |
||
| 92 | $lexer = new \PhpParser\Lexer\Emulative |
||
| 93 | (["usedAttributes" => ["comments", "startLine", "endLine", "startFilePos"]]); |
||
| 94 | return (new ParserFactory)->create(ParserFactory::PREFER_PHP7, $lexer); |
||
| 95 | }; |
||
| 96 | |||
| 97 | $this["analysis_listener"] = function($c) { |
||
| 98 | return $this->build_analysis_listener($c); |
||
| 99 | }; |
||
| 100 | |||
| 101 | $this["stdout_analysis_listener"] = function() { |
||
| 102 | return new CLIReportGenerator(); |
||
| 103 | }; |
||
| 104 | |||
| 105 | $this["result_database"] = function($c) { |
||
| 106 | $path = $this->result_database_path($c["config"]); |
||
| 107 | return $c["database_factory"]->get_result_db($path); |
||
| 108 | }; |
||
| 109 | |||
| 110 | $this["report_generator"] = function($c) { |
||
| 111 | return new Report\Generator($c["report_queries"]); |
||
| 112 | }; |
||
| 113 | |||
| 114 | $this["report_queries"] = function($c) { |
||
| 115 | return new Report\Queries($c["result_database"]); |
||
| 116 | }; |
||
| 117 | |||
| 118 | $this["source_status"] = function($c) { |
||
| 119 | return new SourceStatusGit($c["config"]->project_root()); |
||
| 120 | }; |
||
| 121 | |||
| 122 | $this["schemas"] = function($c) { |
||
| 123 | return $this->load_schemas($c["config"]->rules_schemas()); |
||
| 124 | }; |
||
| 125 | |||
| 126 | $this["properties"] = function($c) { |
||
| 127 | return $this->load_properties($c["config"]->rules_properties()); |
||
| 128 | }; |
||
| 129 | |||
| 130 | $this["variables"] = function($c) { |
||
| 131 | return $this->load_variables($c["config"]->rules_variables()); |
||
| 132 | }; |
||
| 133 | |||
| 134 | return $this; |
||
|
|
|||
| 135 | } |
||
| 136 | |||
| 223 |