Address code standards issues

This commit is contained in:
fabrixxm 2018-11-21 15:10:47 +01:00 committed by Hypolite Petovan
parent 12dd7b552f
commit 9317a1c054
6 changed files with 53 additions and 44 deletions

View file

@ -24,7 +24,7 @@ use Friendica\Util\Strings;
class Filesystem implements IStorage
{
// Default base folder
const DEFAULT_BASE_FOLDER="storage";
const DEFAULT_BASE_FOLDER = "storage";
private static function getBasePath()
{
@ -39,28 +39,26 @@ class Filesystem implements IStorage
private static function pathForRef($ref)
{
$base = self::getBasePath();
$fold1 = substr($ref,0,2);
$fold2 = substr($ref,2,2);
$file = substr($ref,4);
$fold1 = substr($ref, 0, 2);
$fold2 = substr($ref, 2, 2);
$file = substr($ref, 4);
return "{$base}/{$fold1}/{$fold2}/{$file}";
}
/*
}
*/
public static function get($ref)
{
$file = self::pathForRef($ref);
if (!is_file($file)) return "";
if (!is_file($file)) {
return "";
}
return file_get_contents($file);
}
public static function put($data, $ref = null)
public static function put($data, $ref = "")
{
if (is_null($ref)) {
if ($ref === "") {
$ref = Strings::getRandomHex();
}
@ -87,7 +85,11 @@ class Filesystem implements IStorage
public static function delete($ref)
{
$file = self::pathForRef($ref);
// return true if file doesn't exists. we want to delete it: success with zero work!
if (!is_file($file)) {
return true;
}
return unlink($file);
}
}
}

View file

@ -19,12 +19,12 @@ interface IStorage
public static function get($ref);
/**
* @brief Put data in backend as $ref. If $ref is null a new reference is created.
* @brief Put data in backend as $ref. If $ref is not defiend a new reference is created.
* @param string $data Data to save
* @param string $ref Data referece. Optional.
* @return string Saved data referece
*/
public static function put($data, $ref = null);
public static function put($data, $ref = "");
/**
* @brief Remove data from backend
@ -32,4 +32,4 @@ interface IStorage
* @return boolean True on success
*/
public static function delete($ref);
}
}

View file

@ -15,18 +15,22 @@ namespace Friendica\Model\Storage;
class SystemResource implements IStorage
{
// Valid folders to look for resources
const VALID_FOLDERS = [ "images" ];
const VALID_FOLDERS = ["images"];
public static function get($filename)
{
$folder = dirname($filename);
if (!in_array($folder, self::VALID_FOLDERS)) return "";
if (!file_exists($filename)) return "";
if (!in_array($folder, self::VALID_FOLDERS)) {
return "";
}
if (!file_exists($filename)) {
return "";
}
return file_get_contents($filename);
}
public static function put($data, $filename=null)
public static function put($data, $filename="")
{
throw new \BadMethodCallException();
}