Conditions | 13 |
Paths | 84 |
Total Lines | 92 |
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 |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * {@inheritdoc} |
||
40 | */ |
||
41 | public function beforeFilter(\Cake\Event\Event $event) |
||
42 | { |
||
43 | $this->set('titleForLayout', __d('installer', 'title')); |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * Starting point |
||
48 | * |
||
49 | * @return \Cake\Http\Response|void |
||
50 | */ |
||
51 | public function index() |
||
52 | { |
||
53 | $this->log('Start installer.'); |
||
54 | InstallerState::reset(); |
||
55 | |||
56 | return $this->redirect('/install/dbconnection'); |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * Check if connection to DB is working |
||
61 | * |
||
62 | * @return \Cake\Http\Response|void |
||
63 | */ |
||
64 | public function dbconnection() |
||
65 | { |
||
66 | try { |
||
67 | $connection = ConnectionManager::get('default'); |
||
68 | if ($connection->connect()) { |
||
69 | $this->log('Database connection found.'); |
||
70 | |||
71 | return $this->installerRedirect('salt'); |
||
72 | } |
||
73 | } catch (\Throwable $connectionError) { |
||
74 | // connection manager will throw error if no connection |
||
75 | } |
||
76 | |||
77 | $this->log('No database connection.'); |
||
78 | $this->set('database', false); |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * Check if security salt is set |
||
83 | * |
||
84 | * @return \Cake\Http\Response|void |
||
85 | */ |
||
86 | public function salt() |
||
87 | { |
||
88 | if (!InstallerState::check('salt')) { |
||
89 | return $this->redirect('/'); |
||
90 | } |
||
91 | |||
92 | $secured = (Security::getSalt() !== '__SALT__') |
||
93 | && (Configure::read('Security.cookieSalt') !== '__SALT__'); |
||
94 | |||
95 | if ($secured) { |
||
96 | $this->log('Security salt is set.'); |
||
97 | |||
98 | return $this->installerRedirect('connected'); |
||
99 | } |
||
100 | |||
101 | $this->log('Security salt is not set.'); |
||
102 | $this->set('secured', $secured); |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * Check if there's an existing installation |
||
107 | * |
||
108 | * User uses new software version but hit the Installer accidentally. |
||
109 | * |
||
110 | * @return \Cake\Http\Response|void |
||
111 | */ |
||
112 | public function connected() |
||
113 | { |
||
114 | if (!InstallerState::check('connected')) { |
||
115 | return $this->redirect('/'); |
||
116 | } |
||
117 | |||
118 | try { |
||
119 | (new DbVersion($this->loadModel('Settings')))->get(); |
||
|
|||
120 | $this->log('Installer found Settings-table.'); |
||
121 | |||
122 | return; |
||
123 | } catch (\Throwable $e) { |
||
124 | // Settings-table doesn't exist yet |
||
125 | } |
||
126 | |||
127 | $this->log('Installer didn\'t find Settings-table.'); |
||
128 | |||
248 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.