Conditions | 6 |
Paths | 32 |
Total Lines | 62 |
Code Lines | 42 |
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 |
||
92 | public function createLocalClient(array $options) |
||
93 | { |
||
94 | $options = ArrayUtils::defaults($this->defaultConfig, $options); |
||
95 | $dbConfig = ArrayUtils::get($options, 'database', []); |
||
96 | |||
97 | $config = ArrayUtils::omit($options, 'database'); |
||
98 | // match the actual directus status mapping config key |
||
99 | $config['statusMapping'] = $config['status']['mapping']; |
||
100 | unset($config['status']['mapping']); |
||
101 | |||
102 | if (!defined('STATUS_DELETED_NUM')) { |
||
103 | define('STATUS_DELETED_NUM', ArrayUtils::get($config, 'status.deleted_value', 0)); |
||
104 | } |
||
105 | |||
106 | if (!defined('STATUS_ACTIVE_NUM')) { |
||
107 | define('STATUS_ACTIVE_NUM', ArrayUtils::get($config, 'status.active_value', 1)); |
||
108 | } |
||
109 | |||
110 | if (!defined('STATUS_DRAFT_NUM')) { |
||
111 | define('STATUS_DRAFT_NUM', ArrayUtils::get($config, 'status.draft_value', 2)); |
||
112 | } |
||
113 | |||
114 | if (!defined('STATUS_COLUMN_NAME')) { |
||
115 | define('STATUS_COLUMN_NAME', ArrayUtils::get($config, 'status.column_name', 'active')); |
||
116 | } |
||
117 | |||
118 | if (!defined('DIRECTUS_ENV')) { |
||
119 | define('DIRECTUS_ENV', ArrayUtils::get($config, 'environment', 'development')); |
||
120 | } |
||
121 | |||
122 | $connection = new Connection($dbConfig); |
||
123 | $connection->connect(); |
||
124 | |||
125 | $acl = new Acl(); |
||
126 | $acl->setUserId(1); |
||
127 | $acl->setGroupId(1); |
||
128 | $acl->setGroupPrivileges([ |
||
129 | '*' => [ |
||
130 | 'id' => 1, |
||
131 | 'table_name' => '*', |
||
132 | 'group_id' => 1, |
||
133 | 'read_field_blacklist' => [], |
||
134 | 'write_field_blacklist' => [], |
||
135 | 'nav_listed' => 1, |
||
136 | 'status_id' => 0, |
||
137 | 'allow_view' => 2, |
||
138 | 'allow_add' => 1, |
||
139 | 'allow_edit' => 2, |
||
140 | 'allow_delete' => 2, |
||
141 | 'allow_alter' => 1 |
||
142 | ] |
||
143 | ]); |
||
144 | |||
145 | $schema = new \Directus\Database\Schemas\Sources\MySQLSchema($connection); |
||
146 | $schema = new \Directus\Database\SchemaManager($schema); |
||
147 | TableSchema::setSchemaManagerInstance($schema); |
||
148 | TableSchema::setAclInstance($acl); |
||
149 | TableSchema::setConnectionInstance($connection); |
||
150 | TableSchema::setConfig($config); |
||
151 | |||
152 | return new ClientLocal($connection); |
||
153 | } |
||
154 | |||
167 | } |