Conditions | 3 |
Paths | 3 |
Total Lines | 62 |
Code Lines | 41 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 3 | Features | 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 |
||
74 | public function make() |
||
75 | { |
||
76 | // prepare configurations to save |
||
77 | /** @var array $cfg */ |
||
78 | $cfg = App::$Properties->getAll('default'); |
||
79 | $this->before(); |
||
80 | $cfg['database'] = $this->db; |
||
81 | $cfg['adminEmail'] = $this->email; |
||
82 | $cfg['singleLanguage'] = $this->singleLanguage; |
||
83 | $cfg['multiLanguage'] = (bool)$this->multiLanguage; |
||
84 | $cfg['passwordSalt'] = '$2a$07$' . Str::randomLatinNumeric(mt_rand(21, 30)) . '$'; |
||
85 | $cfg['debug']['cookie']['key'] = 'fdebug_' . Str::randomLatinNumeric(mt_rand(4, 16)); |
||
86 | $cfg['debug']['cookie']['value'] = Str::randomLatinNumeric(mt_rand(32, 128)); |
||
87 | |||
88 | // import database tables |
||
89 | $connectName = 'install'; |
||
90 | include(root . '/Private/Database/install.php'); |
||
91 | |||
92 | // insert admin user |
||
93 | $user = new User(); |
||
94 | $user->setConnection('install'); |
||
95 | $user->login = $this->user['login']; |
||
96 | $user->email = $this->user['email']; |
||
97 | $user->role_id = 4; |
||
98 | $user->password = App::$Security->password_hash($this->user['password'], $cfg['passwordSalt']); |
||
99 | $user->save(); |
||
100 | |||
101 | $profile = new Profile(); |
||
102 | $profile->setConnection('install'); |
||
103 | $profile->user_id = $user->id; |
||
104 | $profile->save(); |
||
105 | |||
106 | // write config data |
||
107 | App::$Properties->writeConfig('default', $cfg); |
||
108 | // make routing configs based on preset property |
||
109 | $routing = []; |
||
110 | switch ($this->mainpage) { |
||
111 | case 'news': |
||
112 | $routing = [ |
||
113 | 'Alias' => [ |
||
114 | 'Front' => [ |
||
115 | '/' => '/content/list/news', |
||
116 | '/about' => '/content/read/page/about-page' |
||
117 | ] |
||
118 | ] |
||
119 | ]; |
||
120 | break; |
||
121 | case 'about': |
||
122 | $routing = [ |
||
123 | 'Alias' => [ |
||
124 | 'Front' => [ |
||
125 | '/' => '/content/read/page/about-page' |
||
126 | ] |
||
127 | ] |
||
128 | ]; |
||
129 | break; |
||
130 | } |
||
131 | // write routing configurations |
||
132 | App::$Properties->writeConfig('routing', $routing); |
||
133 | // write installer lock |
||
134 | File::write('/Private/Install/install.lock', 'Installation is locked!'); |
||
135 | } |
||
136 | |||
155 | } |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.