Skip to content

Commit

Permalink
cleanup: cleanup to match coding standards
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewhilton committed Jul 29, 2024
1 parent e90dc51 commit f024f8e
Show file tree
Hide file tree
Showing 33 changed files with 216 additions and 216 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function get_candidates_sql_params() {
return [
'consistancythreshold' => $consistancythreshold,
'location' => OBJECT_LOCATION_DUPLICATED,
'sizethreshold' => $this->config->sizethreshold
'sizethreshold' => $this->config->sizethreshold,
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function get_candidates_sql() {
*/
public function get_candidates_sql_params() {
return [
'location' => OBJECT_LOCATION_ORPHANED
'location' => OBJECT_LOCATION_ORPHANED,
];
}
}
2 changes: 1 addition & 1 deletion classes/local/object_manipulator/manipulator_builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class manipulator_builder {
pusher::class,
recoverer::class,
checker::class,
orphaner::class
orphaner::class,
];

/** @var string $manipulatorclass */
Expand Down
6 changes: 3 additions & 3 deletions classes/local/report/location_report_builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function build_report($reportid) {
OBJECT_LOCATION_DUPLICATED,
OBJECT_LOCATION_EXTERNAL,
OBJECT_LOCATION_ORPHANED,
OBJECT_LOCATION_ERROR
OBJECT_LOCATION_ERROR,
];

$totalcount = 0;
Expand All @@ -71,7 +71,7 @@ public function build_report($reportid) {

if ($location !== OBJECT_LOCATION_ORPHANED) {
// Process the query normally.
$result = $DB->get_record_sql($sql, array($location));
$result = $DB->get_record_sql($sql, [$location]);
} else if ($location === OBJECT_LOCATION_ORPHANED) {
// Start the query from objectfs, for ORPHANED objects, they are not located in the files table.
$sql = 'SELECT COALESCE(count(sub.contenthash) ,0) AS objectcount
Expand All @@ -80,7 +80,7 @@ public function build_report($reportid) {
LEFT JOIN {files} f on f.contenthash = o.contenthash
GROUP BY o.contenthash, f.filesize, o.location
HAVING o.location = ?' . $localsql .') AS sub';
$result = $DB->get_record_sql($sql, array($location));
$result = $DB->get_record_sql($sql, [$location]);
$result->objectsum = 0;
}

Expand Down
4 changes: 2 additions & 2 deletions classes/local/report/object_location_history_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ public function __construct() {
public function query_db($pagesize, $useinitialsbar = true) {
global $DB;
$fields = 'CONCAT(reportid, datakey) AS uid, datakey AS location, objectcount AS count, objectsum AS size';
$conditions = array('reporttype' => 'location');
$conditions = ['reporttype' => 'location'];
$rawrecords = $DB->get_records('tool_objectfs_report_data', $conditions, 'reportid', $fields);
$reports = objectfs_report::get_report_ids();

// Used to fallback to when the expected record is not there.
// NOTE: This avoids the need to null coalesce on a non-existing count/size.
$emptyrecord = (object)[
'count' => 0,
'size' => 0
'size' => 0,
];
foreach ($reports as $id => $timecreated) {
// Initialises the records to be used, and fallback to an empty one if not found.
Expand Down
4 changes: 2 additions & 2 deletions classes/local/report/object_status_history_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function query_db($pagesize, $useinitialsbar = true) {
default:
$sort = 'heading ASC';
}
$params = array('reporttype' => $this->reporttype, 'reportid' => $this->reportid);
$params = ['reporttype' => $this->reporttype, 'reportid' => $this->reportid];
$fields = 'datakey AS heading, objectcount AS count, objectsum AS size';
$rows = $DB->get_records('tool_objectfs_report_data', $params, $sort, $fields);
$this->rawdata = $rows;
Expand Down Expand Up @@ -196,7 +196,7 @@ public function add_barchart($value, $max, $type, $precision = 0) {
if ($max > 0) {
$share = round(100 * $value / $max, $precision);
}
$htmlparams = array('class' => 'ofs-bar', 'style' => 'width:'.$share.'%');
$htmlparams = ['class' => 'ofs-bar', 'style' => 'width:'.$share.'%'];

switch ($type) {
case 'count':
Expand Down
4 changes: 2 additions & 2 deletions classes/local/report/objectfs_report.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public static function generate_status_report() {
public static function cleanup_reports() {
global $DB;
$reportdate = time() - YEARSECS;
$params = array('reportdate' => $reportdate);
$params = ['reportdate' => $reportdate];
$reports = $DB->get_records_select('tool_objectfs_reports', 'reportdate < :reportdate', $params, 'id', 'id');
$reportids = array_keys($reports);
$DB->delete_records_list('tool_objectfs_reports', 'id', $reportids);
Expand All @@ -177,7 +177,7 @@ public static function get_report_types() {
*/
public static function get_report_ids() {
global $DB;
$reports = array();
$reports = [];
$records = $DB->get_records('tool_objectfs_reports', null, 'id DESC', 'id, reportdate');
foreach ($records as $record) {
$reports[$record->id] = $record->reportdate;
Expand Down
12 changes: 6 additions & 6 deletions classes/local/store/azure/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ public function get_relative_path_from_fullpath($fullpath) {
* @return resource
*/
public function get_seekable_stream_context() {
$context = stream_context_create(array(
'blob' => array(
'seekable' => true
)
));
$context = stream_context_create([
'blob' => [
'seekable' => true,
],
]);
return $context;
}

Expand Down Expand Up @@ -259,7 +259,7 @@ public function test_connection() {
public function test_permissions($testdelete) {
$permissions = new \stdClass();
$permissions->success = true;
$permissions->messages = array();
$permissions->messages = [];

try {
$result = $this->client->createBlockBlob($this->container, 'permissions_check_file', 'permissions_check_file');
Expand Down
12 changes: 6 additions & 6 deletions classes/local/store/digitalocean/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ public function set_client($config) {
return;
}

$this->client = \Aws\S3\S3Client::factory(array(
'credentials' => array('key' => $config->do_key, 'secret' => $config->do_secret),
$this->client = \Aws\S3\S3Client::factory([
'credentials' => ['key' => $config->do_key, 'secret' => $config->do_secret],
'region' => $config->do_region,
'endpoint' => 'https://' . $config->do_region . '.digitaloceanspaces.com',
'version' => AWS_API_VERSION
));
'version' => AWS_API_VERSION,
]);
}

/**
Expand All @@ -93,13 +93,13 @@ public function set_client($config) {
*/
public function define_client_section($settings, $config) {

$regionoptions = array(
$regionoptions = [
'sfo2' => 'sfo2 (San Fransisco)',
'nyc3' => 'nyc3 (New York City)',
'ams3' => 'ams3 (Amsterdam)',
'sgp1' => 'spg1 (Singapore)',
'fra1' => 'fra1 (Frankfurt)',
);
];

$settings->add(new \admin_setting_heading('tool_objectfs/do',
new \lang_string('settings:do:header', 'tool_objectfs'), ''));
Expand Down
2 changes: 1 addition & 1 deletion classes/local/store/object_client.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function verify_object($contenthash, $localpath);
*
* @return mixed
*/
public function generate_presigned_url($contenthash, $headers = array());
public function generate_presigned_url($contenthash, $headers = []);

/**
* support_presigned_urls
Expand Down
2 changes: 1 addition & 1 deletion classes/local/store/object_client_base.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function support_presigned_urls() {
*
* @throws \coding_exception
*/
public function generate_presigned_url($contenthash, $headers = array()) {
public function generate_presigned_url($contenthash, $headers = []) {
throw new \coding_exception("Pre-signed URLs not supported");
}

Expand Down
6 changes: 3 additions & 3 deletions classes/local/store/object_file_system.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ public function delete_empty_dirs($rootpath = '') {
$pathinfo['filename'],
$pathinfo['basename'],
$pathinfo['filename'],
$pathinfo['basename']
$pathinfo['basename'],
]);

if (!$exists) {
Expand Down Expand Up @@ -844,7 +844,7 @@ protected function copy_from_external_to_local($contenthash) {
* @return bool
* @throws \dml_exception
*/
public function redirect_to_presigned_url($contenthash, $headers = array()) {
public function redirect_to_presigned_url($contenthash, $headers = []) {
global $FULLME;
try {
$signedurl = $this->externalclient->generate_presigned_url($contenthash, $headers);
Expand Down Expand Up @@ -926,7 +926,7 @@ public function presigned_url_should_redirect_file($file) {
* @return bool
* @throws \dml_exception
*/
public function presigned_url_should_redirect($contenthash, $headers = array()) {
public function presigned_url_should_redirect($contenthash, $headers = []) {
// Redirect regardless.
if ($this->externalclient->presignedminfilesize == 0 &&
manager::all_extensions_whitelisted()) {
Expand Down
60 changes: 30 additions & 30 deletions classes/local/store/s3/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function __construct($config) {
* @return array
*/
public function __sleep() {
return array('bucket');
return ['bucket'];
}

/**
Expand Down Expand Up @@ -150,17 +150,17 @@ public function set_client($config) {
return;
}

$options = array(
$options = [
'region' => $config->s3_region,
'version' => AWS_API_VERSION
);
'version' => AWS_API_VERSION,
];

if (empty($config->s3_usesdkcreds)) {
$options['credentials'] = array('key' => $config->s3_key, 'secret' => $config->s3_secret);
$options['credentials'] = ['key' => $config->s3_key, 'secret' => $config->s3_secret];
}

if ($config->useproxy) {
$options['http'] = array('proxy' => $this->get_proxy_string());
$options['http'] = ['proxy' => $this->get_proxy_string()];
}

// Support base_url config for aws api compatible endpoints.
Expand Down Expand Up @@ -196,9 +196,9 @@ private function get_md5_from_hash($contenthash) {

try {
$key = $this->get_filepath_from_hash($contenthash);
$result = $this->client->headObject(array(
$result = $this->client->headObject([
'Bucket' => $this->bucket,
'Key' => $this->bucketkeyprefix . $key));
'Key' => $this->bucketkeyprefix . $key]);
} catch (\Aws\S3\Exception\S3Exception $e) {
return false;
}
Expand Down Expand Up @@ -265,11 +265,11 @@ public function rename_file($currentpath, $destinationpath) {
* @return mixed
*/
public function get_seekable_stream_context() {
$context = stream_context_create(array(
's3' => array(
'seekable' => true
)
));
$context = stream_context_create([
's3' => [
'seekable' => true,
],
]);
return $context;
}

Expand Down Expand Up @@ -303,7 +303,7 @@ public function test_connection() {
$connection->success = false;
$connection->details = get_string('settings:notconfigured', 'tool_objectfs');
} else {
$this->client->headBucket(array('Bucket' => $this->bucket));
$this->client->headBucket(['Bucket' => $this->bucket]);
}
} catch (\Aws\S3\Exception\S3Exception $e) {
$connection->success = false;
Expand Down Expand Up @@ -331,29 +331,29 @@ public function test_connection() {
public function test_permissions($testdelete) {
$permissions = new \stdClass();
$permissions->success = true;
$permissions->messages = array();
$permissions->messages = [];

if ($this->is_functional()) {
$permissions->success = false;
$permissions->messages = array();
$permissions->messages = [];
return $permissions;
}

try {
$result = $this->client->putObject(array(
$result = $this->client->putObject([
'Bucket' => $this->bucket,
'Key' => $this->bucketkeyprefix . 'permissions_check_file',
'Body' => 'test content'));
'Body' => 'test content']);
} catch (\Aws\S3\Exception\S3Exception $e) {
$details = $this->get_exception_details($e);
$permissions->messages[get_string('settings:writefailure', 'tool_objectfs') . $details] = 'notifyproblem';
$permissions->success = false;
}

try {
$result = $this->client->getObject(array(
$result = $this->client->getObject([
'Bucket' => $this->bucket,
'Key' => $this->bucketkeyprefix . 'permissions_check_file'));
'Key' => $this->bucketkeyprefix . 'permissions_check_file']);
} catch (\Aws\S3\Exception\S3Exception $e) {
$errorcode = $e->getAwsErrorCode();
// Write could have failed.
Expand All @@ -368,7 +368,7 @@ public function test_permissions($testdelete) {
try {
$result = $this->client->deleteObject([
'Bucket' => $this->bucket,
'Key' => $this->bucketkeyprefix . 'permissions_check_file'
'Key' => $this->bucketkeyprefix . 'permissions_check_file',
]);
$permissions->messages[get_string('settings:deletesuccess', 'tool_objectfs')] = 'warning';
$permissions->success = false;
Expand Down Expand Up @@ -536,7 +536,7 @@ public function support_presigned_urls() {
* @return signed_url
* @throws \Exception
*/
public function generate_presigned_url($contenthash, $headers = array()) {
public function generate_presigned_url($contenthash, $headers = []) {
if ('cf' === $this->signingmethod) {
return $this->generate_presigned_url_cloudfront($contenthash, $headers);
}
Expand Down Expand Up @@ -825,18 +825,18 @@ public function curl_range_request_to_presigned_url($contenthash, $ranges, $head
} catch (\Exception $e) {
throw new \coding_exception('Failed to generate pre-signed url: ' . $e->getMessage());
}
$headers = array(
$headers = [
'Range: bytes=' . $ranges->rangefrom . '-' . $ranges->rangeto,
);
];
$curl = new \curl();
$curl->setopt(array('CURLOPT_HTTP_VERSION' => CURL_HTTP_VERSION_1_1));
$curl->setopt(array('CURLOPT_RETURNTRANSFER' => true));
$curl->setopt(array('CURLOPT_SSL_VERIFYPEER' => false));
$curl->setopt(array('CURLOPT_CONNECTTIMEOUT' => 15));
$curl->setopt(array('CURLOPT_TIMEOUT' => 15));
$curl->setopt(['CURLOPT_HTTP_VERSION' => CURL_HTTP_VERSION_1_1]);
$curl->setopt(['CURLOPT_RETURNTRANSFER' => true]);
$curl->setopt(['CURLOPT_SSL_VERIFYPEER' => false]);
$curl->setopt(['CURLOPT_CONNECTTIMEOUT' => 15]);
$curl->setopt(['CURLOPT_TIMEOUT' => 15]);
$curl->setHeader($headers);
$content = $curl->get($url);
return array('responseheaders' => $curl->getResponse(), 'content' => $content, 'url' => $url);
return ['responseheaders' => $curl->getResponse(), 'content' => $content, 'url' => $url];
}

/**
Expand Down
6 changes: 3 additions & 3 deletions classes/local/store/swift/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private function get_endpoint() {
'password' => $this->config->openstack_password,
'domain' => ['id' => 'default'],
],
'scope' => ['project' => ['id' => $this->config->openstack_projectid]]
'scope' => ['project' => ['id' => $this->config->openstack_projectid]],
];

if (!isset($this->config->openstack_authtoken['expires_at'])
Expand Down Expand Up @@ -179,7 +179,7 @@ public function get_seekable_stream_context() {
'endpoint' => $this->config->openstack_authurl,
'region' => $this->config->openstack_region,
'cachedtoken' => $this->config->openstack_authtoken,
]
],
]);
return $context;
}
Expand Down Expand Up @@ -288,7 +288,7 @@ public function test_connection() {
public function test_permissions($testdelete) {
$permissions = new \stdClass();
$permissions->success = true;
$permissions->messages = array();
$permissions->messages = [];

$container = $this->get_container();

Expand Down
Loading

0 comments on commit f024f8e

Please sign in to comment.