MCPcopy Create free account
hub / github.com/error311/FileRise / check

Method check

src/FileRise/Storage/SourceHealth.php:211–450  ·  view source on GitHub ↗
(array $source)

Source from the content-addressed store, hash-verified

209 }
210
211 public static function check(array $source): array
212 {
213 $checks = [];
214 $type = strtolower((string)($source['type'] ?? 'local'));
215 $readOnly = !empty($source['readOnly']);
216 $rootPath = self::sourceRoot($source);
217
218 if ($type === 'local') {
219 if (!is_dir($rootPath)) {
220 self::addCheck($checks, 'connect', 'Connect', 'fail', 'Local path not found');
221 self::addCheck($checks, 'read', 'Read/list', 'fail', 'Local path not found');
222 self::addCheck($checks, 'createFolder', 'Create folder', 'skipped', 'Skipped because source root is unavailable.');
223 self::addCheck($checks, 'write', 'Write file', 'skipped', 'Skipped because source root is unavailable.');
224 self::addCheck($checks, 'moveRename', 'Move/Rename', 'skipped', 'Skipped because source root is unavailable.');
225 self::addCheck($checks, 'delete', 'Delete', 'skipped', 'Skipped because source root is unavailable.');
226 return self::buildResult($source, $checks);
227 }
228 if (!is_readable($rootPath)) {
229 self::addCheck($checks, 'connect', 'Connect', 'fail', 'Local path is not readable');
230 self::addCheck($checks, 'read', 'Read/list', 'fail', 'Local path is not readable');
231 self::addCheck($checks, 'createFolder', 'Create folder', 'skipped', 'Skipped because source root is not readable.');
232 self::addCheck($checks, 'write', 'Write file', 'skipped', 'Skipped because source root is not readable.');
233 self::addCheck($checks, 'moveRename', 'Move/Rename', 'skipped', 'Skipped because source root is not readable.');
234 self::addCheck($checks, 'delete', 'Delete', 'skipped', 'Skipped because source root is not readable.');
235 return self::buildResult($source, $checks);
236 }
237 }
238
239 $adapter = null;
240 try {
241 $adapter = StorageFactory::createAdapterFromSourceConfig($source, false);
242 } catch (Throwable $e) {
243 $adapter = null;
244 }
245 if (!$adapter) {
246 self::addCheck($checks, 'connect', 'Connect', 'fail', 'Adapter unavailable');
247 self::addCheck($checks, 'read', 'Read/list', 'fail', 'Adapter unavailable');
248 self::addCheck($checks, 'createFolder', 'Create folder', 'skipped', 'Skipped because adapter is unavailable.');
249 self::addCheck($checks, 'write', 'Write file', 'skipped', 'Skipped because adapter is unavailable.');
250 self::addCheck($checks, 'moveRename', 'Move/Rename', 'skipped', 'Skipped because adapter is unavailable.');
251 self::addCheck($checks, 'delete', 'Delete', 'skipped', 'Skipped because adapter is unavailable.');
252 return self::buildResult($source, $checks);
253 }
254
255 $connectOk = false;
256 $connectMsg = '';
257 if (method_exists($adapter, 'testConnection')) {
258 try {
259 $connectOk = (bool)$adapter->testConnection();
260 } catch (Throwable $e) {
261 $connectOk = false;
262 $connectMsg = trim($e->getMessage());
263 }
264 if ($connectOk) {
265 $connectMsg = 'Connection established';
266 } elseif ($connectMsg === '') {
267 $connectMsg = self::adapterError($adapter);
268 }

Callers 2

testByIdMethod · 0.80

Calls 14

sourceRootMethod · 0.95
addCheckMethod · 0.95
buildResultMethod · 0.95
adapterErrorMethod · 0.95
randomTokenMethod · 0.95
joinPathMethod · 0.95
deletePathMethod · 0.95
testConnectionMethod · 0.80
listMethod · 0.45
statMethod · 0.45
mkdirMethod · 0.45

Tested by

no test coverage detected